Roberto Sánchez
2014-01-16 8f97df85eefe4d648f2002b8d68818ef6020c2df
securis/src/main/resources/static/js/login.js
....@@ -1,21 +1,15 @@
11 (function() {
22 'use strict';
33
4
- var app = angular.module('app', ['ngRoute']);
4
+ var app = angular.module('securis');
55
6
- app.controller('LoginCtrl', ['$scope', '$http', '$window',
7
- function($scope, $http, $window) {
6
+ app.controller('LoginCtrl', ['$scope', '$http', '$window', '$location', 'toaster', '$L',
7
+ function($scope, $http, $window, $location, toaster, $L) {
8
+
9
+ $('#username').focus();
810
9
- $scope.$loginerror = false;
10
- $('#loginError').removeClass('hide');
11
-
12
- $scope.hideAlert = function() {
13
- $scope.$loginerror = false;
14
- $('#user').focus();
15
- }
1611 $scope.submit = function() {
1712 console.log('Sending user: ' + $scope.username + ' pass: ' + $scope.password);
18
- $scope.hideAlert();
1913 $http({ method: 'POST',
2014 url: '/user/login',
2115 headers: {
....@@ -27,17 +21,17 @@
2721 })
2822 }).
2923 success(function(data, status, headers, config) {
30
- $window.location.href = "/main.html";
24
+ toaster.pop('success', $L.get('Login successful'), $L.get('User {0} has logged in SeCuris', $scope.username), 1500);
25
+ $location.path('/licenses');
3126 }).
3227 error(function(data, status, headers, config) {
3328 console.error(data + " status: "+ status);
34
- $scope.$loginerror = true;
3529 if (status === 403 /* forbidden */) {
36
- $scope.$errormsg = 'Invalid credentials'
30
+ toaster.pop('error', $L.get('Login error'), $L.get('Invalid credentials'), 3000);
3731 } else {
38
- $scope.$errormsg = 'Unexpected error HTTP ' + status + ' accessing to server. Contact with the administrator.'
32
+ toaster.pop('error', $L.get('Unexpected Login error'), $L.get('Unexpected error HTTP ({0}) accessing to server. Contact with the administrator.', status), 5000);
3933 }
40
- $('#user').focus();
34
+ $('#username').focus();
4135 });
4236 return false;
4337 }