Skip to content

Commit

Permalink
Merge pull request #50 from omarduarte/user-auth
Browse files Browse the repository at this point in the history
Adds signup and login functionality
  • Loading branch information
kranrao committed Feb 24, 2015
2 parents ef134ff + 901e9dd commit 11540c1
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ pids
*.pid
*.seed

#ionic related
client/hooks/after_platform_add/
client/hooks/after_plugin_add/
client/hooks/after_plugin_rm/
client/hooks/after_prepare/020_remove_sass_from_platforms.js
client/hooks/before_platform_add/

# Compiled Dirs (http://nodejs.org/api/addons.html)
client/platforms/
client/plugins/
Expand Down
21 changes: 19 additions & 2 deletions client/www/app/app.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'app.mementos',
'app.memento',
'app.memento.create'
'app.user.auth'
])

.run(function($ionicPlatform) {
Expand All @@ -24,6 +25,11 @@
}
});
})

.config(function($httpProvider) {
$httpProvider.defaults.withCredentials = true;
delete $httpProvider.defaults.headers.common["X-Requested-With"];
})

.config(function($stateProvider, $urlRouterProvider) {

Expand All @@ -33,7 +39,6 @@
templateUrl: 'app/moment/moment.create.html',
controller: 'MomentCreate as vm'
})

.state('mementos', {
url: '/mementos',
templateUrl: 'app/mementos-list/mementos.html',
Expand All @@ -51,9 +56,21 @@
templateUrl: 'app/memento-create/memento.create.html',
controller: 'MementoCreate as vm'
});

.state('signup', {
url: '/signup',
templateUrl: 'app/auth/user.signup.html',
controller: 'UserSignup as vm'
})

.state('signin', {
url: '/signin',
templateUrl: 'app/auth/user.signin.html',
controller: 'UserSignin as vm'
});

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/moment');
$urlRouterProvider.otherwise('/signup');
});

})();
Expand Down
7 changes: 7 additions & 0 deletions client/www/app/auth/user.auth.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function() {

'user strict';

angular.module('app.user.auth', []);

})();
27 changes: 27 additions & 0 deletions client/www/app/auth/user.signin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<ion-view view-title="Sign In">
<ion-content>

<div class="list">
<label class="item item-input">
<input type="text" ng-model="vm.credentials.email" placeholder="email">
</label>

<label class="item item-input">
<input type="password" ng-model="vm.credentials.password" placeholder="password">
</label>
</div>

<div class="padding">
<button class="button button-block button-positive" on-tap="vm.signin(vm.credentials)">
Sign In
</button>
</div>

<div class="card">
<div class="item item-text-wrap">
<a href="#/signup" class="button icon-right ion-chevron-right button-clear button-dark">Don't have an account? Signup</a>
</div>
</div>

</ion-content>
</ion-view>
24 changes: 24 additions & 0 deletions client/www/app/auth/user.signin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(function() {
angular
.module('app.user.auth')
.controller('UserSignin', UserSignin);

/* @ngInject */
function UserSignin(dataservice, $state) {
vm = this;
vm.credentials = {};
vm.signin = signin;

//////////////////////////////////////

function signin(credentials) {
return dataservice.signin(credentials)
.then(function(result) {
$state.go('moment');
})
.catch(function(err) {
console.error(err);
});
}
}
})();
31 changes: 31 additions & 0 deletions client/www/app/auth/user.signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<ion-view view-title="Sign Up">
<ion-content>

<div class="list">
<label class="item item-input">
<input type="text" ng-model="vm.credentials.email" placeholder="email">
</label>

<label class="item item-input">
<input type="password" ng-model="vm.credentials.password" placeholder="password">
</label>

<label class="item item-input">
<input ng-pattern="{{ vm.credentials.password }}" type="password" ng-model="vm.repeatPassword" placeholder="repeat password">
</label>
</div>

<div class="padding">
<button class="button button-block button-positive" on-tap="vm.signup(vm.credentials)">
Sign Up
</button>
</div>

<div class="card">
<div class="item item-text-wrap">
<a href="#/signin" class="button icon-right ion-chevron-right button-clear button-dark">Already a member? Signin </a>
</div>
</div>

</ion-content>
</ion-view>
27 changes: 27 additions & 0 deletions client/www/app/auth/user.signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(function() {
angular
.module('app.user.auth')
.controller('UserSignup', UserSignup);

/* @ngInject */
function UserSignup(dataservice, $state) {
vm = this;
vm.credentials = {};
vm.repeatPassword = '';
vm.signup = signup;

//////////////////////////////////////

function signup(credentials) {
console.log('here out!', credentials);
return dataservice.signup(credentials)
.then(function(result) {
console.log('here!')
$state.go('moment');
})
.catch(function(err) {
console.error(err);
});
}
}
})();
46 changes: 44 additions & 2 deletions client/www/app/core/dataservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/*FIXME: makesure ngInject is working during minification*/

/* @ngInject */
function dataservice($q) {
function dataservice($q, $http) {


// MOCKED DATA
Expand All @@ -32,7 +32,9 @@
saveMemento: saveMemento,
addMoment: addMoment,
/*NOTE: temp until server is connected*/
getMoment: getMoment
getMoment: getMoment,
signup: signup,
signin: signin
};

return service;
Expand All @@ -43,6 +45,46 @@
resolve(mementos);
});
}

function signup(userCredentials) {
var req = {
method: 'POST',
url: 'http://localhost:3000/auth/signup',
headers: {
'Content-Type': 'application/json',
},
data: userCredentials
};

return $http(req)
.success(function(result){
return result;
})
.error(function(error){
console.error(error);
throw error;
});
}

function signin(userCredentials) {
var req = {
method: 'POST',
url: 'http://localhost:3000/auth/login',
headers: {
'Content-Type': 'application/json',
},
data: userCredentials
};

return $http(req)
.success(function(result){
return result;
})
.error(function(error){
console.error(error);
throw error;
});
}

// NOTE: memento ID will be supplied from getMementos call in list view
function getMemento(ID) {
Expand Down
5 changes: 3 additions & 2 deletions client/www/app/moment/moment.module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(function() {

'use strict';

angular.module('app.moment', ['app.moment.items']);
})();

})();
3 changes: 3 additions & 0 deletions client/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="app/auth/user.auth.module.js"></script>
<script src="app/auth/user.signup.js"></script>
<script src="app/auth/user.signin.js"></script>
<script src="app/core/core.module.js"></script>
<script src="app/core/dataservice.js"></script>
<script src="app/core/CurrentMoment.js"></script>
Expand Down
25 changes: 25 additions & 0 deletions client/www/test/specs/user.auth.specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe('User Authorization Process', function() {
var signup;
var login;
var scope;
var controller;
var dataservice;

beforeEach(function() {
module('app', 'templates');

inject(function(_dataservice_, _$rootScope_, _$controller_) {
dataservice = _dataservice_;
scope = _$rootScope_.$new();
controller = _$controller_;
});

controller = controller('UserSignup', { $scope: scope });

});

it('has a credentials object', function() {
expect(controller.credentials).toBeDefined();
});

});

0 comments on commit 11540c1

Please sign in to comment.