openEventsPlatformApp/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("events_app_token", response.data.token);
23 localStorage.setItem("events_app_userdata", JSON.stringify(response.data.user));
24 window.location.href="#/app/main";
25 window.location.reload();
26 }else{
27 console.log("login failed");
28 $ionicLoading.show({ template: 'Login failed, user or password error.', noBackdrop: true, duration: 2000 });
29 }
30
31
32 },
33 function(response) { // optional
34 // failed
35 console.log(response);
36 });
37
38 };
39});