2014-08-12 15:06:54 +02:00
|
|
|
define([
|
|
|
|
|
'angular',
|
2015-01-05 07:58:15 +01:00
|
|
|
'config',
|
2014-08-12 15:06:54 +02:00
|
|
|
],
|
2015-01-05 07:58:15 +01:00
|
|
|
function (angular, config) {
|
2014-08-12 15:06:54 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var module = angular.module('grafana.controllers');
|
|
|
|
|
|
2015-01-29 15:46:36 +01:00
|
|
|
module.controller('LoginCtrl', function($scope, backendSrv) {
|
2015-01-22 11:51:44 +01:00
|
|
|
$scope.formModel = {
|
2015-01-21 09:51:31 +01:00
|
|
|
user: '',
|
2015-01-22 11:51:44 +01:00
|
|
|
email: '',
|
|
|
|
|
password: '',
|
2015-01-21 09:51:31 +01:00
|
|
|
};
|
|
|
|
|
|
2014-09-17 15:25:19 +02:00
|
|
|
$scope.grafana.sidemenu = false;
|
2015-01-28 10:25:53 +01:00
|
|
|
|
|
|
|
|
$scope.googleAuthEnabled = config.googleAuthEnabled;
|
|
|
|
|
$scope.githubAuthEnabled = config.githubAuthEnabled;
|
2015-01-29 15:46:36 +01:00
|
|
|
$scope.disableUserSignUp = config.disableUserSignUp;
|
2015-01-28 10:25:53 +01:00
|
|
|
|
2015-01-22 10:14:24 +01:00
|
|
|
$scope.loginMode = true;
|
2015-01-22 11:51:44 +01:00
|
|
|
$scope.submitBtnClass = 'btn-inverse';
|
|
|
|
|
$scope.submitBtnText = 'Log in';
|
|
|
|
|
$scope.strengthClass = '';
|
|
|
|
|
|
|
|
|
|
$scope.init = function() {
|
|
|
|
|
$scope.$watch("loginMode", $scope.loginModeChanged);
|
|
|
|
|
$scope.passwordChanged();
|
|
|
|
|
};
|
2014-08-12 15:06:54 +02:00
|
|
|
|
2015-01-05 10:46:16 +01:00
|
|
|
// build info view model
|
|
|
|
|
$scope.buildInfo = {
|
|
|
|
|
version: config.buildInfo.version,
|
|
|
|
|
commit: config.buildInfo.commit,
|
|
|
|
|
buildstamp: new Date(config.buildInfo.buildstamp * 1000)
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-21 09:51:31 +01:00
|
|
|
$scope.submit = function() {
|
2015-01-22 10:14:24 +01:00
|
|
|
if ($scope.loginMode) {
|
2015-01-21 09:51:31 +01:00
|
|
|
$scope.login();
|
|
|
|
|
} else {
|
|
|
|
|
$scope.signUp();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-22 11:51:44 +01:00
|
|
|
$scope.loginModeChanged = function(newValue) {
|
|
|
|
|
$scope.submitBtnText = newValue ? 'Log in' : 'Sign up';
|
2015-01-22 10:14:24 +01:00
|
|
|
};
|
|
|
|
|
|
2015-01-22 11:51:44 +01:00
|
|
|
$scope.passwordChanged = function(newValue) {
|
|
|
|
|
if (!newValue) {
|
|
|
|
|
$scope.strengthText = "";
|
|
|
|
|
$scope.strengthClass = "hidden";
|
|
|
|
|
return;
|
2015-01-22 10:14:24 +01:00
|
|
|
}
|
2015-01-22 11:51:44 +01:00
|
|
|
if (newValue.length < 4) {
|
|
|
|
|
$scope.strengthText = "strength: weak sauce.";
|
|
|
|
|
$scope.strengthClass = "password-strength-bad";
|
|
|
|
|
return;
|
2014-08-16 21:54:05 +02:00
|
|
|
}
|
2015-01-22 11:51:44 +01:00
|
|
|
if (newValue.length <= 6) {
|
|
|
|
|
$scope.strengthText = "strength: you can do better.";
|
|
|
|
|
$scope.strengthClass = "password-strength-ok";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.strengthText = "strength: strong like a bull.";
|
|
|
|
|
$scope.strengthClass = "password-strength-good";
|
2014-08-16 21:54:05 +02:00
|
|
|
};
|
|
|
|
|
|
2015-01-21 09:51:31 +01:00
|
|
|
$scope.signUp = function() {
|
|
|
|
|
if (!$scope.loginForm.$valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 12:57:44 +01:00
|
|
|
backendSrv.post('/api/user/signup', $scope.formModel).then(function() {
|
2015-01-21 09:51:31 +01:00
|
|
|
window.location.href = config.appSubUrl + '/';
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-12 15:06:54 +02:00
|
|
|
$scope.login = function() {
|
|
|
|
|
delete $scope.loginError;
|
2014-08-16 21:54:05 +02:00
|
|
|
|
2014-08-12 15:06:54 +02:00
|
|
|
if (!$scope.loginForm.$valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 11:59:20 +01:00
|
|
|
backendSrv.post('/login', $scope.formModel).then(function(result) {
|
|
|
|
|
if (result.redirectUrl) {
|
|
|
|
|
window.location.href = result.redirectUrl;
|
|
|
|
|
} else {
|
|
|
|
|
window.location.href = config.appSubUrl + '/';
|
|
|
|
|
}
|
2014-08-12 15:06:54 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-16 21:54:05 +02:00
|
|
|
$scope.init();
|
|
|
|
|
|
2014-08-12 15:06:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|