2016-05-01 19:46:50 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.sign.in')
|
|
|
|
.directive('signIn', signIn);
|
|
|
|
|
2016-05-24 12:22:06 +02:00
|
|
|
SignInController.$inject = ['SignInService', 'LogOutService', 'currentUser', 'I18nService', '$window', '$scope'];
|
|
|
|
function SignInController(SignInService, LogOutService, currentUser, I18nService, $window, $scope) {
|
2016-05-01 19:46:50 +02:00
|
|
|
var vm = this;
|
2016-05-14 07:34:54 +02:00
|
|
|
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
|
|
|
|
vm.reset = reset;
|
2016-05-01 19:46:50 +02:00
|
|
|
vm.doSignIn = doSignIn;
|
2016-05-12 12:30:01 +02:00
|
|
|
vm.doSignUp = doSignUp;
|
|
|
|
vm.doForgotPassword = doForgotPassword;
|
2016-05-14 07:34:54 +02:00
|
|
|
|
2016-05-24 12:22:06 +02:00
|
|
|
vm.doContinue = doContinue;
|
|
|
|
vm.doLogOut = doLogOut;
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function reset() {
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSignIn(user) {
|
|
|
|
if(user && angular.isDefined(user.principal) && angular.isDefined(user.password)) {
|
|
|
|
SignInService(user.principal, user.password)
|
2016-05-01 19:46:50 +02:00
|
|
|
.success(signedInSuccess)
|
|
|
|
.error(signedInFailed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function signedInSuccess(data, status) {
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = "/dashboard";
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function signedInFailed(data, status) {
|
2016-05-14 07:34:54 +02:00
|
|
|
if(status === 401) {
|
|
|
|
vm.hasError = true;
|
|
|
|
vm.errorMessage = 'username_or_password_is_incorrect';
|
|
|
|
}
|
|
|
|
console.log('Failed sign in:' + data + ', status:' + status);
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 12:30:01 +02:00
|
|
|
function doSignUp() {
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = '/sign_up';
|
2016-05-12 12:30:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function doForgotPassword() {
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = '/forgot_password';
|
2016-05-12 12:30:01 +02:00
|
|
|
}
|
2016-05-24 12:22:06 +02:00
|
|
|
|
|
|
|
function doContinue() {
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = '/dashboard';
|
2016-05-24 12:22:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function doLogOut() {
|
|
|
|
LogOutService()
|
|
|
|
.success(logOutSuccess)
|
|
|
|
.error(logOutFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function logOutSuccess(data, status) {
|
|
|
|
currentUser.unset();
|
|
|
|
I18nService().unset();
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href= '/';
|
2016-05-24 12:22:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function logOutFailed(data, status) {
|
|
|
|
console.log('Failed to log out:' + data);
|
|
|
|
}
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function signIn() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/sign_in',
|
2016-05-10 12:43:52 +02:00
|
|
|
'scope': true,
|
2016-05-01 19:46:50 +02:00
|
|
|
'controller': SignInController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
2016-05-23 12:29:17 +02:00
|
|
|
};
|
|
|
|
|
2016-05-01 19:46:50 +02:00
|
|
|
return directive;
|
2016-05-14 07:34:54 +02:00
|
|
|
|
2016-05-01 19:46:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|