diff --git a/app/www/js/controllers.js b/app/www/js/controllers.js
index a10e19b..f1bc3c8 100644
--- a/app/www/js/controllers.js
+++ b/app/www/js/controllers.js
@@ -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);
};
})
diff --git a/app/www/templates/login.html b/app/www/templates/login.html
index 793bd7f..1123cc7 100644
--- a/app/www/templates/login.html
+++ b/app/www/templates/login.html
@@ -2,7 +2,7 @@
Login
Signup
+
+
- Ask to join - Offer car - Offer car -
-- Delete -
++ Ask to join + Offer car + Offer car +
++ Delete +
+