limitless.controller('Zupit.Limitless.Backend.LoginController', ['$scope', '$rootScope', 'Zupit.Core.AppService', 'Zupit.Identity.AuthService', 'Zupit.Core.HttpClient', '$state', '$stateParams', '$translate', '$location', function ($scope, $rootScope, app, auth, $http, $state, $stateParams, $translate, $location) { $scope.message = $stateParams.message; $scope.email = ''; $scope.password = ''; $scope.rememberMe = false; $scope.forgotpassword = {}; $scope.forgotpassword.email = ""; $scope.errorMessage = null; $scope.resetpassword = {}; $scope.resetpassword.userEmail = $stateParams.useremail; $scope.resetpassword.resetPasswordCode = $location.search().code; $translate('EMAIL').then(function (headline) { $scope._EMAIL = headline; }, function (translationId) { $scope._EMAIL = translationId; }); if ($stateParams.email != undefined) { $scope.email = $stateParams.email; } if ($stateParams.code != undefined) { //used for forgot and reset password $scope.code = $stateParams.code; } if ($stateParams.userid != undefined) { $scope.userid = $stateParams.userid; } function checkIfAlreadyLoggedIn(user) { if (user !== null && user !== undefined && user.isAuthenticated) { $state.go($stateParams.name, $stateParams.params); return; } } checkIfAlreadyLoggedIn(app.user); $scope.goToForgotPassword = function () { state.go("ForgotPassword"); }; $scope.login = function (event) { event.preventDefault(); app.Loading.show('#loginbox'); auth.login($scope.email, $scope.password, $scope.rememberMe).then(function () { app.Loading.hide('#loginbox'); $state.go($stateParams.name, $stateParams.params); }, function () { app.Loading.hide('#loginbox'); }); }; $scope.sendforgotpassword = function () { //event.preventDefault(); $scope.errorMessage = null; app.Loading.show('#loginbox'); auth.forgotpassword($scope.forgotpassword).then(function () { app.Loading.hide('#loginbox'); //TODO visualizzare messaggio che una mail è stata spedita con il link per tornare alla login $state.go('Login'); }, function (err) { $scope.errorMessage = error.data.message; app.Loading.hide('#loginbox'); //TODO visualizzare messaggio che la mail non esiste nel sistema o l'utente è stato bloccato }); }; $scope.sendresetpassword = function (event) { //event.preventDefault(); $scope.errorMessage = null; app.Loading.show('#loginbox'); auth.resetpassword($scope.resetpassword).then(function () { app.Loading.hide('#loginbox'); //TODO visualizzare messaggio che la password è stata modificata correttamente con il link per tornare alla login $state.go('Login'); }, function (error) { $scope.errorMessage = error.data.message; app.Loading.hide('#loginbox'); //TODO visualizzare messaggio che la mail non esiste nel sistema o l'utente è stato bloccato }); }; }]);