Roberto Sánchez
2014-01-16 8f97df85eefe4d648f2002b8d68818ef6020c2df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(function() {
   'use strict';
   var app = angular.module('securis');
   
   app.controller('LoginCtrl', ['$scope', '$http', '$window', '$location', 'toaster', '$L',
                             function($scope, $http, $window, $location, toaster, $L) {
       $('#username').focus();
       
       $scope.submit = function() {
           console.log('Sending user: ' + $scope.username + ' pass: ' + $scope.password);
           $http({    method: 'POST', 
                   url: '/user/login',
                   headers: {
                       "Content-Type": "application/x-www-form-urlencoded"
                   }, 
                   data: $.param({
                       username: $scope.username,
                       password: $scope.password
                   })
           }).
             success(function(data, status, headers, config) {
                 toaster.pop('success', $L.get('Login successful'), $L.get('User {0} has logged in SeCuris', $scope.username), 1500);
                 $location.path('/licenses');
             }).
             error(function(data, status, headers, config) {
               console.error(data + " status: "+ status);
               if (status === 403 /* forbidden */) {
                   toaster.pop('error', $L.get('Login error'), $L.get('Invalid credentials'), 3000);
               } else {
                   toaster.pop('error', $L.get('Unexpected Login error'), $L.get('Unexpected error HTTP ({0}) accessing to server. Contact with the administrator.', status), 5000);
               }
                $('#username').focus();
             });
             return false;
           }
   }]);    
   
})();