diff options
Diffstat (limited to 'app/login/controllers/login-controller.js')
-rw-r--r-- | app/login/controllers/login-controller.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/app/login/controllers/login-controller.js b/app/login/controllers/login-controller.js new file mode 100644 index 0000000..b1a0d45 --- /dev/null +++ b/app/login/controllers/login-controller.js @@ -0,0 +1,52 @@ +/** + * Controller for the login page + * + * @module app/login/controllers/index + * @exports LoginController + * @name LoginController + * @version 0.1.0 + */ + +window.angular && (function (angular) { + 'use strict'; + + angular + .module('app.login') + .controller('LoginController', [ + '$scope', + '$window', + 'APIUtils', + 'dataService', + 'userModel', + function($scope, $window, APIUtils, dataService, userModel){ + $scope.dataService = dataService; + + $scope.tryLogin = function(username, password, event){ + if(event.keyCode === 13){ + $scope.login(username, password); + } + }; + $scope.login = function(username, password){ + $scope.error = false; + + if(!username || username == "" || + !password || password == ""){ + return false; + }else{ + userModel.login(username, password, function(status, unreachable){ + if(status){ + $scope.$emit('user-logged-in',{}); + $window.location.hash = '#/system-overview'; + }else{ + if(!unreachable){ + $scope.error = true; + } + }; + }); + } + } + } + ] + ); + +})(angular); |