|
|
@ -1,13 +1,13 @@ |
|
|
|
|
|
|
|
//var urlapi="http://localhost:3000/api/";
|
|
|
|
var urlapi="http://192.168.1.40:3000/api/"; |
|
|
|
localStorage.setItem("c_username", "user2"); |
|
|
|
localStorage.setItem("c_token", ""); |
|
|
|
//localStorage.setItem("c_username", "user2");
|
|
|
|
//localStorage.setItem("c_token", "");
|
|
|
|
|
|
|
|
|
|
|
|
angular.module('starter.controllers', []) |
|
|
|
|
|
|
|
.controller('AppCtrl', function($scope, $ionicModal, $timeout) { |
|
|
|
.controller('AppCtrl', function($scope, $ionicModal, $timeout, $http, $window) { |
|
|
|
// With the new view caching in Ionic, Controllers are only called
|
|
|
|
// when they are recreated or on app start, instead of every page change.
|
|
|
|
// To listen for when this page is active (for example, to refresh data),
|
|
|
@ -17,33 +17,95 @@ angular.module('starter.controllers', []) |
|
|
|
|
|
|
|
// Form data for the login modal
|
|
|
|
$scope.loginData = {}; |
|
|
|
$scope.signupData= {}; |
|
|
|
|
|
|
|
$scope.storageusername=localStorage.getItem("c_username"); |
|
|
|
// Create the login modal that we will use later
|
|
|
|
$ionicModal.fromTemplateUrl('templates/login.html', { |
|
|
|
scope: $scope |
|
|
|
}).then(function(modal) { |
|
|
|
$scope.modal = modal; |
|
|
|
$scope.modalLogin = modal; |
|
|
|
}); |
|
|
|
$ionicModal.fromTemplateUrl('templates/signup.html', { |
|
|
|
scope: $scope |
|
|
|
}).then(function(modal) { |
|
|
|
$scope.modalSignup = modal; |
|
|
|
}); |
|
|
|
|
|
|
|
// Triggered in the login modal to close it
|
|
|
|
$scope.closeLogin = function() { |
|
|
|
$scope.modal.hide(); |
|
|
|
$scope.modalLogin.hide(); |
|
|
|
}; |
|
|
|
$scope.closeSignup = function() { |
|
|
|
$scope.modalSignup.hide(); |
|
|
|
}; |
|
|
|
|
|
|
|
// Open the login modal
|
|
|
|
$scope.login = function() { |
|
|
|
$scope.modal.show(); |
|
|
|
$scope.modalLogin.show(); |
|
|
|
}; |
|
|
|
$scope.signup = function() { |
|
|
|
$scope.modalSignup.show(); |
|
|
|
}; |
|
|
|
|
|
|
|
// Perform the login action when the user submits the login form
|
|
|
|
$scope.doLogin = function() { |
|
|
|
console.log('Doing login', $scope.loginData); |
|
|
|
|
|
|
|
// Simulate a login delay. Remove this and replace with your login
|
|
|
|
// code if using a login system
|
|
|
|
$timeout(function() { |
|
|
|
$scope.closeLogin(); |
|
|
|
}, 1000); |
|
|
|
$http({ |
|
|
|
url: urlapi + 'auth', |
|
|
|
method: "POST", |
|
|
|
data: $scope.loginData |
|
|
|
}) |
|
|
|
.then(function(response) { |
|
|
|
// success
|
|
|
|
console.log("response: "); |
|
|
|
console.log(response.data); |
|
|
|
if(response.data.success==true) |
|
|
|
{ |
|
|
|
console.log("login successful"); |
|
|
|
localStorage.setItem("c_username", $scope.loginData.username); |
|
|
|
localStorage.setItem("c_token", response.data.token); |
|
|
|
}else{ |
|
|
|
console.log("login failed"); |
|
|
|
} |
|
|
|
$timeout(function() { |
|
|
|
$scope.closeLogin(); |
|
|
|
$window.location.reload(true); |
|
|
|
}, 1000); |
|
|
|
|
|
|
|
}, |
|
|
|
function(response) { // optional
|
|
|
|
// failed
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
$scope.doSignup = function() { |
|
|
|
console.log('Doing signup', $scope.signupData); |
|
|
|
|
|
|
|
$http({ |
|
|
|
url: urlapi + 'users', |
|
|
|
method: "POST", |
|
|
|
data: $scope.signupData |
|
|
|
}) |
|
|
|
.then(function(response) { |
|
|
|
// success
|
|
|
|
console.log("response: "); |
|
|
|
console.log(response.data); |
|
|
|
$timeout(function() { |
|
|
|
$scope.closeSignup(); |
|
|
|
}, 1000); |
|
|
|
|
|
|
|
}, |
|
|
|
function(response) { // optional
|
|
|
|
// failed
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
$scope.logout = function(){ |
|
|
|
localStorage.removeItem("c_username"); |
|
|
|
localStorage.removeItem("c_token"); |
|
|
|
$window.location.reload(true); |
|
|
|
}; |
|
|
|
}) |
|
|
|
|
|
|
|