re-imagined toderp, first commit.

This commit is contained in:
Max Lynch
2013-10-03 18:02:59 -05:00
parent a7fbaac5db
commit 0ecb2b58a8
6 changed files with 268 additions and 1 deletions

View File

@ -0,0 +1,46 @@
angular.module('ionic.todo.services', ['ionic.todo', 'firebase'])
// The AuthService handles user authentication with Firebase.
.factory('AuthService', function(angularFireAuth, $rootScope, FIREBASE_URL) {
// Initialize the angularFireAuth service.
var ref = new Firebase(FIREBASE_URL);
angularFireAuth.initialize(ref, {
scope: $rootScope,
callback: function(user, err) {
console.log('AUTH CHANGED', err, user);
},
name: 'user'
});
return {
// Try to log in with the given email and pass
login: function(email, password) {
if(!email || !password) {
return;
}
console.log('Logging in', email, password);
return angularFireAuth.login('password', {
email: email,
password: password
});
},
// Try to sign up with the given email and pass
signup: function(email, password) {
if(!email || !password) {
return;
}
console.log('Signing up', name, email, password);
angularFireAuth.createUser(email, password, function(err, user) {
if(err && err.code == "EMAIL_TAKEN") {
alert('That email is already taken');
}
});
}
};
})