Browse Source

signup and login system implemented in the app

pull/1/head
nau 8 years ago
parent
commit
049492ca1a
6 changed files with 134 additions and 22 deletions
  1. +73
    -11
      app/www/js/controllers.js
  2. +1
    -1
      app/www/templates/login.html
  3. +7
    -1
      app/www/templates/menu.html
  4. +42
    -0
      app/www/templates/signup.html
  5. +10
    -8
      app/www/templates/travel.html
  6. +1
    -1
      app/www/templates/travels.html

+ 73
- 11
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);
};
})

+ 1
- 1
app/www/templates/login.html

@ -2,7 +2,7 @@
<ion-header-bar>
<h1 class="title">Login</h1>
<div class="buttons">
<button class="button button-clear" ng-click="closeLogin()">Close</button>
<button class="button button-dark" ng-click="closeLogin()">Close</button>
</div>
</ion-header-bar>
<ion-content>

+ 7
- 1
app/www/templates/menu.html

@ -18,7 +18,10 @@
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close ng-click="login()">
<ion-item menu-close ng-click="signup()" ng-show="!storageusername">
Signup
</ion-item>
<ion-item menu-close ng-click="login()" ng-show="!storageusername">
Login
</ion-item>
<ion-item menu-close href="#/app/travels">
@ -33,6 +36,9 @@
<img class='o-imgMenu' src="img/settings.png" />
Settings
</ion-item>
<ion-item menu-close ng-click="logout()" ng-show="storageusername">
Logout
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>

+ 42
- 0
app/www/templates/signup.html

@ -0,0 +1,42 @@
<ion-modal-view>
<ion-header-bar>
<h1 class="title">Signup</h1>
<div class="buttons">
<button class="button button-dark" ng-click="closeLogin()">Close</button>
</div>
</ion-header-bar>
<ion-content>
<form ng-submit="doSignup()">
<div class="list">
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" ng-model="signupData.username">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" ng-model="signupData.password">
</label>
<label class="item item-input">
<span class="input-label">Mail</span>
<input type="email" ng-model="signupData.mail">
</label>
<label class="item item-input">
<span class="input-label">Phone</span>
<input type="number" ng-model="signupData.phone">
</label>
<label class="item item-input">
<span class="input-label">Telegram</span>
<input type="text" ng-model="signupData.telegram">
</label>
<label class="item item-input">
<span class="input-label">Avatar</span>
<input type="text" ng-model="signupData.avatar">
</label>
<label class="item">
<button class="button button-block button-positive" type="submit">Sign up</button>
</label>
</div>
</form>
</ion-content>
</ion-modal-view>

+ 10
- 8
app/www/templates/travel.html

@ -32,14 +32,16 @@
<img class='o-imgMenu' src="img/telegram.png" /> {{travel.telegram}}
</p>
<p class='text-right' ng-show="storageusername!==travel.owner">
<a ng-show="travel.modality=='offering'" href="#" class="button button-calm o-pull-right">Ask to join</a>
<a ng-show="travel.modality=='asking'" href="#" class="button button-calm o-pull-right">Offer car</a>
<a ng-show="travel.modality=='package'" href="#" class="button button-calm o-pull-right">Offer car</a>
</p>
<p ng-show="storageusername==travel.owner" class="text-right">
<a href="#" class="button button-assertive o-pull-right">Delete</a>
</p>
<div ng-show="storageusername">
<p class='text-right' ng-show="storageusername!==travel.owner">
<a ng-show="travel.modality=='offering'" href="#" class="button button-calm o-pull-right">Ask to join</a>
<a ng-show="travel.modality=='asking'" href="#" class="button button-calm o-pull-right">Offer car</a>
<a ng-show="travel.modality=='package'" href="#" class="button button-calm o-pull-right">Offer car</a>
</p>
<p ng-show="storageusername==travel.owner" class="text-right">
<a href="#" class="button button-assertive o-pull-right">Delete</a>
</p>
</div>
</div>
</ion-content>
</ion-view>

+ 1
- 1
app/www/templates/travels.html

@ -5,7 +5,7 @@
on-refresh="doRefresh()">
</ion-refresher>
<div class="list">
<div class="o-float-right">
<div class="o-float-right" ng-show="storageusername">
<a ng-click="showNewAskingPackage()" class="button icon ion-email"></a>
<a ng-click="showNewAskingTravel()" class="button icon ion-help"></a>
<a ng-click="showNewOfferingTravel()" class="button icon ion-plus"></a>

Loading…
Cancel
Save