| .. | .. |
|---|
| 1 | 1 | (function() { |
|---|
| 2 | 2 | 'use strict'; |
|---|
| 3 | 3 | |
|---|
| 4 | | - var app = angular.module('app', ['ngRoute']); |
|---|
| 4 | + var app = angular.module('securis'); |
|---|
| 5 | 5 | |
|---|
| 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(); |
|---|
| 8 | 10 | |
|---|
| 9 | | - $scope.$loginerror = false; |
|---|
| 10 | | - $('#loginError').removeClass('hide'); |
|---|
| 11 | | - |
|---|
| 12 | | - $scope.hideAlert = function() { |
|---|
| 13 | | - $scope.$loginerror = false; |
|---|
| 14 | | - $('#user').focus(); |
|---|
| 15 | | - } |
|---|
| 16 | 11 | $scope.submit = function() { |
|---|
| 17 | 12 | console.log('Sending user: ' + $scope.username + ' pass: ' + $scope.password); |
|---|
| 18 | | - $scope.hideAlert(); |
|---|
| 19 | 13 | $http({ method: 'POST', |
|---|
| 20 | 14 | url: '/user/login', |
|---|
| 21 | 15 | headers: { |
|---|
| .. | .. |
|---|
| 27 | 21 | }) |
|---|
| 28 | 22 | }). |
|---|
| 29 | 23 | 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'); |
|---|
| 31 | 26 | }). |
|---|
| 32 | 27 | error(function(data, status, headers, config) { |
|---|
| 33 | 28 | console.error(data + " status: "+ status); |
|---|
| 34 | | - $scope.$loginerror = true; |
|---|
| 35 | 29 | if (status === 403 /* forbidden */) { |
|---|
| 36 | | - $scope.$errormsg = 'Invalid credentials' |
|---|
| 30 | + toaster.pop('error', $L.get('Login error'), $L.get('Invalid credentials'), 3000); |
|---|
| 37 | 31 | } 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); |
|---|
| 39 | 33 | } |
|---|
| 40 | | - $('#user').focus(); |
|---|
| 34 | + $('#username').focus(); |
|---|
| 41 | 35 | }); |
|---|
| 42 | 36 | return false; |
|---|
| 43 | 37 | } |
|---|