You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.5 KiB

  1. 'use strict';
  2. angular.module('app.login', ['ngRoute'])
  3. .config(['$routeProvider', function($routeProvider) {
  4. $routeProvider.when('/login', {
  5. templateUrl: 'views/login/login.html',
  6. controller: 'LoginCtrl'
  7. });
  8. }])
  9. .controller('LoginCtrl', function($scope, $http, $routeParams, toastr) {
  10. $scope.user = {};
  11. $scope.login = function() {
  12. console.log('Doing login', $scope.user);
  13. console.log(urlapi + "login");
  14. $http({
  15. url: urlapi + 'login',
  16. method: "POST",
  17. headers: {
  18. "Content-Type": undefined
  19. },
  20. data: $scope.user
  21. })
  22. .then(function(data) {
  23. console.log("data: ");
  24. console.log(data.data);
  25. if (data.data.token) {
  26. localStorage.setItem("blid_token", data.data.token);
  27. localStorage.setItem("blid_user", JSON.stringify(data.data));
  28. window.location.reload();
  29. } else {
  30. console.log("login failed");
  31. toastr.error('Login failed');
  32. }
  33. },
  34. function(data) {
  35. console.log(data);
  36. });
  37. };
  38. });