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