Skip to content

Commit 71b97df

Browse files
committed
feat(client:auth.service): create sync methods
1 parent bf78a58 commit 71b97df

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

templates/app/client/components/auth(auth)/auth.service.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
112112
});
113113
},
114114

115+
/**
116+
* Gets all available info on a user
117+
*
118+
* @return {Object}
119+
*/
120+
getCurrentUserSync() {
121+
return currentUser;
122+
},
123+
115124
/**
116125
* Check if a user is logged in
117126
* (synchronous|asynchronous)
@@ -132,6 +141,15 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
132141
});
133142
},
134143

144+
/**
145+
* Check if a user is logged in
146+
*
147+
* @return {Bool}
148+
*/
149+
isLoggedInSync() {
150+
return currentUser.hasOwnProperty('role');
151+
},
152+
135153
/**
136154
* Check if a user has a specified role or higher
137155
* (synchronous|asynchronous)
@@ -158,6 +176,20 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
158176
});
159177
},
160178

179+
/**
180+
* Check if a user has a specified role or higher
181+
*
182+
* @param {String} role - the role to check against
183+
* @return {Bool}
184+
*/
185+
hasRoleSync(role) {
186+
var hasRole = function(r, h) {
187+
return userRoles.indexOf(r) >= userRoles.indexOf(h);
188+
};
189+
190+
return hasRole(currentUser.role, role);
191+
},
192+
161193
/**
162194
* Check if a user is an admin
163195
* (synchronous|asynchronous)
@@ -170,6 +202,15 @@ export function AuthService($location, $http, $cookies, $q, appConfig, Util, Use
170202
.apply(Auth, [].concat.apply(['admin'], arguments));
171203
},
172204

205+
/**
206+
* Check if a user is an admin
207+
*
208+
* @return {Bool}
209+
*/
210+
isAdminSync() {
211+
return Auth.hasRoleSync('admin');
212+
},
213+
173214
/**
174215
* Get auth token
175216
*

0 commit comments

Comments
 (0)