diff --git a/bower.json b/bower.json index fc339f7..bd7c6d9 100755 --- a/bower.json +++ b/bower.json @@ -24,7 +24,6 @@ "angular-jwt": "~0.0.9", "angular-footable": "~1.0.3", "appirio-tech-ng-auth": "3.x.x", - "appirio-tech-ng-login-reg": "0.x.x", "appirio-tech-ng-api-services": "0.x.x" }, "overrides": { diff --git a/src/app/login/login.controller.js b/src/app/login/login.controller.js index 49ef027..a84e502 100644 --- a/src/app/login/login.controller.js +++ b/src/app/login/login.controller.js @@ -2,45 +2,67 @@ angular.module('supportAdminApp') .controller('LoginController', [ - '$scope', '$rootScope', '$location', '$state', 'AuthService', 'TokenService', 'UserService', - function ($scope, $rootScope, $location, $state, $authService, $tokenService, $userService) { + '$log', '$scope', '$rootScope', '$location', '$state', 'AuthService', 'TokenService', 'UserService', 'Alert', + function ($log, $scope, $rootScope, $location, $state, $authService, $tokenService, $userService, $alert) { $scope.loggingIn = false; - $scope.isLoggingIn = function() { - return $scope.loggingIn; + $scope.formLogin = { + username: null, + password: null, + loggingIn: false, + valid: function() { + return !!(this.username && this.username.length > 0 && + this.password && this.password.length > 0); + } }; - $scope.submit = function() { + $scope.login = function() { + $alert.clear(); + var loginSuccess = function() { var token = $tokenService.decodeToken(); - console.log(token); + $log.debug(token); if($.inArray('administrator', token && token.roles) < 0) { - $scope.$broadcast('AlertIssued', {type:'danger', message:'Permission denied.'}); - $scope.loggingIn = false; + $alert.error('Permission denied.', $scope); + $scope.formLogin.loggingIn = false; return; } - $userService.findById(token.userId).then(function(currentUser) { - console.log('Login Success'); - $rootScope.currentUser = currentUser; - $state.go('index.main') - }); + $userService.findById(token.userId).then( + function(currentUser) { + $rootScope.currentUser = currentUser; + $state.go('index.main'); + }, + function(err) { + $log.error('Failed to get user data.'); + $log.error(err); + $state.go('index.main'); + } + ); }; - var loginFailure = function() { - console.log('Login Failed') - $scope.loggingIn = false; + var loginFailure = function(err) { + $log.error('Login Failed') + $log.error(err) + var reason = err && err.data && err.data.error, + msg = err && err.data && err.data.error_description || err.statusText; + if(reason === "invalid_user_password") { + msg = "Wrong username or password."; + } + $alert.error(msg, $scope); + $scope.formLogin.loggingIn = false; }; var options = { - username:$scope.username, - password:$scope.password, + username: $scope.formLogin.username, + password: $scope.formLogin.password, success: loginSuccess, error: loginFailure }; - $scope.loggingIn = true; + $scope.formLogin.loggingIn = true; $authService.login(options); - }; + }; + }]); diff --git a/src/app/login/login.html b/src/app/login/login.html index 9823170..9f3e74b 100755 --- a/src/app/login/login.html +++ b/src/app/login/login.html @@ -1,14 +1,33 @@ -
-
-
-

+
+
+ -
-
- -
diff --git a/src/app/users/users.controller.js b/src/app/users/users.controller.js index 9368938..b4a7da8 100644 --- a/src/app/users/users.controller.js +++ b/src/app/users/users.controller.js @@ -3,8 +3,8 @@ var module = angular.module('supportAdminApp'); module.controller('users.UserSearchController', [ - '$scope', '$rootScope', '$timeout', '$state', '$modal', 'AuthService','UserService', - function ($scope, $rootScope, $timeout, $state, $modal, $authService, $userService) { + '$log', '$scope', '$rootScope', '$timeout', '$state', '$modal', 'AuthService','UserService', 'Alert', + function ($log, $scope, $rootScope, $timeout, $state, $modal, $authService, $userService, $alert) { // footable angular.element(document).ready(function () { @@ -36,7 +36,7 @@ module.controller('users.UserSearchController', [ $scope.search = function() { - $scope.$broadcast('alert.ClearAll', {}); + $alert.clear(); var handle = $scope.formSearch.handle, email = $scope.formSearch.email, @@ -75,7 +75,7 @@ module.controller('users.UserSearchController', [ }, 100); }, function(error) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); + $alert.error(error.error, $scope); $scope.formSearch.setLoading(false); } ); @@ -100,11 +100,10 @@ module.controller('users.UserSearchController', [ }; $scope.activate = function(index) { - $scope.$broadcast('alert.ClearAll', {}); + $alert.clear(); var user = $scope.users[index]; if(!user.credential || !user.credential.activationCode) { - $scope.$broadcast('alert.AlertIssued', - {type:'danger', message:'The user \'' + user.handle + '\' is invalid. Unable to activate it.'}); + $alert.error('The user \'' + user.handle + '\' is invalid. Unable to activate it.', $scope); return; }; if(window.confirm('Are you sure you want to activate user \'' + user.handle + '\'?')) { @@ -116,7 +115,7 @@ module.controller('users.UserSearchController', [ $scope.formSearch.setLoading(false); }, function(error) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); + $alert.error(error.error, $scope); $scope.formSearch.setLoading(false); } ); @@ -163,8 +162,8 @@ module.controller('users.UserSearchController', [ ]); module.controller('users.UserEditDialogController', [ - '$scope', '$rootScope', '$timeout', '$state', '$modalInstance', 'AuthService', 'UserService', 'user', - function ($scope, $rootScope, $timeout, $state, $modalInstance, $authService, $userService, user) { + '$scope', '$rootScope', '$timeout', '$state', '$modalInstance', 'AuthService', 'UserService', 'Alert', 'user', + function ($scope, $rootScope, $timeout, $state, $modalInstance, $authService, $userService, $alert, user) { $scope.user = user; @@ -186,9 +185,9 @@ module.controller('users.UserEditDialogController', [ }; $scope.saveHandle = function() { - $scope.$broadcast('alert.ClearAll', {}); + $alert.clear(); if(user.handle === $scope.form.handle) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:'Handle is not changed.'}); + $alert.error('Handle is not changed.', $scope); return; } @@ -201,7 +200,7 @@ module.controller('users.UserEditDialogController', [ $modalInstance.close(); }, function(error) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); + $alert.error(error.error, $scope); $scope.form.setLoading(false); } ); @@ -209,9 +208,9 @@ module.controller('users.UserEditDialogController', [ }; $scope.saveEmail = function() { - $scope.$broadcast('alert.ClearAll', {}); + $alert.clear(); if(user.email.toLowerCase() === $scope.form.email.toLowerCase()) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:'Email is not changed.'}); + $alert.error('Email is not changed.', $scope); return; } @@ -224,7 +223,7 @@ module.controller('users.UserEditDialogController', [ $modalInstance.close(); }, function(error) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); + $alert.error(error.error, $scope); $scope.form.setLoading(false); } ); @@ -235,8 +234,8 @@ module.controller('users.UserEditDialogController', [ ]); module.controller('users.StatusUpdateDialogController', [ - '$scope', '$rootScope', '$timeout', '$state', '$modalInstance', 'AuthService', 'UserService', 'user', - function ($scope, $rootScope, $timeout, $state, $modalInstance, $authService, $userService, user) { + '$scope', '$rootScope', '$timeout', '$state', '$modalInstance', 'AuthService', 'UserService', 'Alert', 'user', + function ($scope, $rootScope, $timeout, $state, $modalInstance, $authService, $userService, $alert, user) { $scope.form = { status : user.status, @@ -252,9 +251,9 @@ module.controller('users.StatusUpdateDialogController', [ }; $scope.save = function() { - $scope.$broadcast('alert.ClearAll', {}); + $alert.clear(); if(user.status === $scope.form.status) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:'Status is not changed.'}); + $alert.error('Status is not changed.', $scope); return; } if(window.confirm('Are you sure you want to save changes?')) { @@ -267,7 +266,7 @@ module.controller('users.StatusUpdateDialogController', [ $modalInstance.close(); }, function(error) { - $scope.$broadcast('alert.AlertIssued', {type:'danger', message:error.error}); + $alert.error(error.error, $scope); $scope.form.setLoading(false); } ); diff --git a/src/app/users/users.service.js b/src/app/users/users.service.js index f036d14..98b3838 100644 --- a/src/app/users/users.service.js +++ b/src/app/users/users.service.js @@ -1,8 +1,8 @@ 'use strict'; angular.module('supportAdminApp') - .factory('UserService', ['$q','$http', 'API_URL', - function ($q, $http, API_URL) { + .factory('UserService', ['$log', '$q','$http', 'API_URL', + function ($log, $q, $http, API_URL) { // local dev //var API_URL = 'http://local.topcoder-dev.com:8080'; return ({ @@ -23,11 +23,11 @@ angular.module('supportAdminApp') return request.then( function(response) { - console.log(response); + $log.debug(response); return response.data.result.content; }, function(error) { - console.log(error); + $log.error(error); var err; if(error && error.data && error.data.result) { err = { @@ -71,11 +71,11 @@ angular.module('supportAdminApp') return request.then( function(response) { - console.log(response); + $log.debug(response); return response.data.result.content; }, function(error) { - console.log(error); + $log.error(error); var err; if(error && error.data && error.data.result) { err = { @@ -107,11 +107,11 @@ angular.module('supportAdminApp') return request.then( function(response) { - console.log(response); + $log.debug(response); return response.data.result.content; }, function(error) { - console.log(error); + $log.error(error); var err; if(error && error.data && error.data.result) { err = { @@ -143,11 +143,11 @@ angular.module('supportAdminApp') return request.then( function(response) { - console.log(response); + $log.debug(response); return response.data.result.content; }, function(error) { - console.log(error); + $log.error(error); var err; if(error && error.data && error.data.result) { err = { @@ -179,11 +179,11 @@ angular.module('supportAdminApp') return request.then( function(response) { - console.log(response); + $log.debug(response); return response.data.result.content; }, function(error) { - console.log(error); + $log.error(error); var err; if(error && error.data && error.data.result) { err = { @@ -217,11 +217,11 @@ angular.module('supportAdminApp') return request.then( function(response) { - console.log(response); + $log.debug(response); return response.data.result.content; }, function(error) { - console.log(error); + $log.error(error); var err; if(error && error.data && error.data.result) { err = { diff --git a/src/app/vendor.less b/src/app/vendor.less index b2745f7..160d12b 100755 --- a/src/app/vendor.less +++ b/src/app/vendor.less @@ -7,4 +7,33 @@ // SERVE:DIST //@icon-font-path: '/fonts/'; -//@fa-font-path: '/fonts'; \ No newline at end of file +//@fa-font-path: '/fonts'; + +.login-box { + width: 300px; + text-align: center; + background-color: #fff; + + .logo-header { + padding: 13px; + border: solid 2px #fff; + background-color: #3e3e3e + } + + h3 { + color: #4a4a4a; + font-weight: 200; + font-family: 'sofia-pro'; + text-transform: uppercase; + } + + form { + padding: 20px; + } + + button { + text-transform: uppercase; + } +} + + diff --git a/src/components/alert/alert-simple.html b/src/components/alert/alert-simple.html new file mode 100644 index 0000000..bf50a86 --- /dev/null +++ b/src/components/alert/alert-simple.html @@ -0,0 +1,5 @@ +
+

+ {{alert.message}} +

+
diff --git a/src/components/alert/alert.html b/src/components/alert/alert.html index 5accbcc..e888b0f 100644 --- a/src/components/alert/alert.html +++ b/src/components/alert/alert.html @@ -1,5 +1,5 @@
-