From 3a7c48dea82d32a0eb4e2bba9ed871bc2628e98f Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Wed, 14 Sep 2016 17:23:49 -0400 Subject: [PATCH] fix(client:auth): fix hasOwnProperty instances, fix User usage fixes #2212 --- .../client/components/auth(auth)/auth.service.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index ac17e15ce..e38a12632 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -57,7 +57,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use */ logout() { $cookies.remove('token'); - currentUser = new User(); + currentUser = new _User(); }, /** @@ -103,7 +103,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * @return {Promise} */ getCurrentUser(callback?: Function) { - var value = currentUser.hasOwnProperty('$promise') + var value = _.get(currentUser, '$promise') ? currentUser.$promise : currentUser; @@ -135,7 +135,8 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use isLoggedIn(callback?: Function) { return Auth.getCurrentUser(undefined) .then(user => { - var is = user.hasOwnProperty('role'); + let is = _.get(user, 'role'); + safeCb(callback)(is); return is; }); @@ -147,7 +148,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * @return {Bool} */ isLoggedInSync() { - return currentUser.hasOwnProperty('role'); + return !!_.get(currentUser, 'role'); }, /** @@ -160,9 +161,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use hasRole(role, callback?: Function) { return Auth.getCurrentUser(undefined) .then(user => { - var has = user.hasOwnProperty('role') - ? hasRole(user.role, role) - : false; + let has = hasRole(_.get(user, 'role'), role); safeCb(callback)(has); return has; @@ -176,7 +175,7 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use * @return {Bool} */ hasRoleSync(role) { - return hasRole(currentUser.role, role); + return hasRole(_.get(currentUser, 'role'), role); }, /**