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.

38 lines
1.2 KiB

7 years ago
7 years ago
  1. angular.module('app.login', ['pascalprecht.translate'])
  2. .controller('LoginCtrl', function($scope, $ionicModal, $timeout, $http, $window, $ionicLoading) {
  3. // Form data for the login modal
  4. $scope.loginData = {};
  5. // Perform the login action when the user submits the login form
  6. $scope.doLogin = function() {
  7. console.log('Doing login', $scope.loginData);
  8. $http({
  9. url: urlapi + 'login',
  10. method: "POST",
  11. data: $scope.loginData
  12. })
  13. .then(function(response) {
  14. // success
  15. console.log("response: ");
  16. console.log(response.data);
  17. if (response.data.success == true)
  18. {
  19. localStorage.setItem("cim_app_token", response.data.token);
  20. localStorage.setItem("cim_app_userdata", JSON.stringify(response.data.user));
  21. window.location.reload();
  22. }else{
  23. console.log("login failed");
  24. $ionicLoading.show({ template: 'Login failed, user or password error.', noBackdrop: true, duration: 2000 });
  25. }
  26. },
  27. function(response) { // optional
  28. // failed
  29. console.log(response);
  30. });
  31. };
  32. });