Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
62 changes: 42 additions & 20 deletions src/app/login/login.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};

}]);
41 changes: 30 additions & 11 deletions src/app/login/login.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
<div class="middle-box text-center loginscreen animated fadeInDown">
<div ng-controller="LoginController">
<div>
<h1 class="logo-name"><img src="assets/images/appirio-logo.png"/></h1>
<div class="middle-box text-center loginscreen animated fadeInDown">
<div ng-controller="LoginController" style="margin-top: 70px">
<div class="login-box">
<div class="logo-header">
<img src="assets/images/appirio-logo.png"/>
</div>
<form role="form" class="form-horizontal">
<h3>Admin app login</h3>
<div ng-include src="'components/alert/alert-simple.html'"></div>
<div class="form-group">
<div class="col-lg-12">
<input type="text" placeholder="username" class="form-control"
ng-model="formLogin.username" ng-disabled="formLogin.loggingIn">
</div>
</div>
<div class="form-group">
<div class="col-lg-12">
<input type="password" placeholder="password" class="form-control"
ng-model="formLogin.password" ng-disabled="formLogin.loggingIn">
</div>
</div>
<div class="form-group">
<div class="col-lg-12">
<button class="btn btn-sm btn-primary" ng-click="login()" ng-disabled="formLogin.loggingIn || !formLogin.valid()">
<span ng-show="!formLogin.loggingIn">Login</span>
<span ng-show="formLogin.loggingIn">Logging in...</span>
</button>
</div>
</div>
</form>
</div>
<div class="text-ceneter" ng-include src="'components/alert/alert.html'"></div>
<form ng-submit="submit()" class="m-t" role="form" method="post">
<button type="submit" class="btn btn-primary block full-width m-b">
<span ng-show="!isLoggingIn()">Login</span>
<span ng-show="isLoggingIn()">Logging in...</span>
</button>
</form>
</div>
</div>
41 changes: 20 additions & 21 deletions src/app/users/users.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
);
Expand All @@ -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 + '\'?')) {
Expand All @@ -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);
}
);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -201,17 +200,17 @@ 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);
}
);
}
};

$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;
}

Expand All @@ -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);
}
);
Expand All @@ -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,
Expand All @@ -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?')) {
Expand All @@ -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);
}
);
Expand Down
28 changes: 14 additions & 14 deletions src/app/users/users.service.js
Original file line number Diff line number Diff line change
@@ -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 ({
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down
Loading