xuekang
2024-05-10 edf3b7fde038fcf3e6d86b8b4b88c2ff6f9014cf
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
var app = angular.module('sentinelDashboardApp');
 
app.controller('LoginCtl', ['$scope', '$state', '$window', 'AuthService',
  function ($scope, $state, $window, AuthService) {
    // If auth passed, jump to the index page directly
    if ($window.localStorage.getItem('session_sentinel_admin')) {
      $state.go('dashboard');
    }
 
    $scope.login = function () {
      if (!$scope.username) {
        alert('请输入用户名');
        return;
      }
 
      if (!$scope.password) {
        alert('请输入密码');
        return;
      }
 
      var param = {"username": $scope.username, "password": $scope.password};
 
      AuthService.login(param).success(function (data) {
        if (data.code == 0) {
          $window.localStorage.setItem('session_sentinel_admin', JSON.stringify(data.data));
          $state.go('dashboard');
        } else {
          alert(data.msg);
        }
      });
    };
  }]
);