Created
September 5, 2015 23:31
-
-
Save eugenehp/e45537b73d58db33cd80 to your computer and use it in GitHub Desktop.
loopback-angular-passport authentication
This file contains hidden or 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
'use strict'; | |
/** | |
* @ngdoc function | |
* @name appApp.controller:AccountCtrl | |
* @description | |
* # AccountCtrl | |
* Controller of the appApp | |
*/ | |
angular.module('appApp') | |
.controller('AccountCtrl', function ($scope, $rootScope, $cookies, User, LoopBackAuth, $stateParams, $location) { | |
this.awesomeThings = [ | |
'HTML5 Boilerplate', | |
'AngularJS', | |
'Karma' | |
]; | |
var cookies = $cookies.getAll(); | |
var currentUserId = cookies['userId']; | |
var accessTokenId = cookies['access_token']; | |
currentUserId = currentUserId.split('.')[0]; | |
currentUserId = currentUserId.split(':')[1]; | |
accessTokenId = accessTokenId.split('.')[0]; | |
accessTokenId = accessTokenId.split(':')[1]; | |
console.log('before',LoopBackAuth); | |
if( localStorage.getItem('$LoopBack$accessTokenId') == null ){ | |
LoopBackAuth.currentUserId = currentUserId; | |
LoopBackAuth.accessTokenId = accessTokenId; | |
LoopBackAuth.rememberMe = true; | |
LoopBackAuth.save(); | |
console.log('after',LoopBackAuth); | |
} | |
User | |
.getCurrent() | |
.$promise | |
.then(function(user){ | |
console.log(user); | |
$rootScope.currentUser = $scope.user = user; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment