Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular
- .module('app')
- // Auth Factory
- .factory("Auth", ["$firebaseAuth", "FIREBASE_URI",
- function($firebaseAuth, FIREBASE_URI) {
- var ref = new Firebase(FIREBASE_URI);
- return $firebaseAuth(ref);
- }
- ])
- function authenticationCtrl($scope, $state, authService) {
- var authenticationCtrl = this;
- // LOGIN
- var login = function (userObject) {
- authService.loginWithPassword(userObject, function () {
- $state.go('[...]');
- },
- function (errorText) {
- // ERROR
- console.error("Error logging in user:", errorText)
- });
- };
- // LOGOUT
- var logout = function () {
- // Clear locally logged in user
- $scope.authData = null;
- authService.logout();
- };
- // PUBLIC
- return {
- login: login,
- logout: logout
- };
- };
- angular
- .module('app')
- .controller('authenticationCtrl', authenticationCtrl)
- function authService($state, FIREBASE_URI, Auth) {
- var model = this,
- ref = new Firebase(FIREBASE_URI);
- // LOGIN
- model.loginWithPassword = function(credentials, callBack, errorCallBack) {
- Auth.$authWithPassword(credentials)
- .then(function(authData) {
- model.cachedUser = authData;
- callBack();
- }).catch(function(error) {
- console.error("Authentication failed:", error);
- });
- };
- // LOGOUT
- model.logout = function() {
- Auth.$unauth();
- model.cachedUser = null;
- $state.go('common.login');
- };
- };
- angular
- .module('app')
- .service('authService', authService)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement