Advertisement
Guest User

Untitled

a guest
Mar 28th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('newApp2App').controller('loginCtrl', function ($scope, authService, $translate, camerasService, userService, $state, startStateService, notificationService) {
  2.  
  3.     $scope.loginData = {
  4.         userName: "",
  5.         password: ""
  6.     };
  7.     var lastLoginTry = new Date(0);
  8.  
  9.     $scope.message = "";
  10.  
  11.     $scope.login = function () {
  12.         var currentData = new Date();
  13.         var difference = (currentData - lastLoginTry) / 1000;
  14.        
  15.         if (difference > 10) {
  16.             lastLoginTry = currentData;
  17.             authService.login($scope.loginData).then(
  18.                 function (response) {
  19.                     notificationService.clearNotifications();
  20.                     startStateService.getStartStateName().then(
  21.                         function (stateName)
  22.                         {
  23.                             $state.go(stateName);
  24.                         });
  25.                     if($scope.$close)
  26.                     {
  27.                         $scope.$close();
  28.                     }
  29.                  },
  30.                  function (err)
  31.                  {
  32.                      $scope.message = $translate.instant(err.error_description);
  33.                      $scope.loginData.password = "";
  34.                  }
  35.             );
  36.         }
  37.         else {
  38.             var seconds = Math.round(10 - difference) + 1;
  39.             $scope.message = $translate.instant('TOOOFTENLOGIN') + seconds + $translate.instant('TOOOFTENLOGINSECOND');
  40.                 //$scope.loginData.password = "";
  41.             }
  42.     };
  43.     $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
  44.         if($scope.$close)
  45.         {
  46.             $scope.$close();
  47.         }
  48.     })
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement