(function() { 'use strict'; var app = angular.module('app', ['ngRoute']); app.controller('LoginCtrl', ['$scope', '$http', '$window', function($scope, $http, $window) { $scope.$loginerror = false; $('#loginError').removeClass('hide'); $scope.hideAlert = function() { $scope.$loginerror = false; $('#user').focus(); } $scope.submit = function() { console.log('Sending user: ' + $scope.username + ' pass: ' + $scope.password); $scope.hideAlert(); $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) { $window.location.href = "/main.html"; }). error(function(data, status, headers, config) { console.error(data + " status: "+ status); $scope.$loginerror = true; if (status === 403 /* forbidden */) { $scope.$errormsg = 'Invalid credentials' } else { $scope.$errormsg = 'Unexpected error HTTP ' + status + ' accessing to server. Contact with the administrator.' } $('#user').focus(); }); return false; } }]); })();