Created
August 15, 2013 02:59
-
-
Save andruu/6237828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('Auth', function (Firebase, $rootScope, $localStorage) { | |
var auth = new FirebaseSimpleLogin(Firebase.reference, function (error, user) { | |
if (error) { | |
$rootScope.$emit('firebase.error', error); | |
} else if (user) { | |
// We have user | |
$localStorage.current_user = user; | |
$localStorage.logged_in = true; | |
$rootScope.$emit('firebase.logged_in'); | |
} else { | |
// No user | |
$localStorage.logged_in = false; | |
} | |
}); | |
var login = function (email, password) { | |
auth.login('password', { | |
email: email, | |
password: password, | |
rememberMe: true | |
}); | |
}; | |
var logout = function () { | |
auth.logout(); | |
$localStorage.current_user = {}; | |
$localStorage.logged_in = false; | |
}; | |
var register = function (email, password) { | |
auth.createUser(email, password, function (error, user) { | |
if (error) { | |
$rootScope.$emit('firebase.error', error); | |
} else { | |
// We have user | |
$localStorage.current_user = user; | |
$localStorage.logged_in = true; | |
$rootScope.$emit('firebase.logged_in'); | |
} | |
}); | |
}; | |
return { | |
login: login, | |
logout: logout, | |
register: register | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment