AngularJS Service for getting/storing user data and managing logins/sessions.
Requires
- module:authService
- module:domainService
- module:gameDataService
- module:gameTrackingService
- module:instructorService
- module:URLParamsService
- module:utilityService
Members
Methods
(static) checkSessionLimitReached() → {boolean}
- Source:
Returns:
- Type:
-
boolean
to let game know that the user has reached their session limit.
(static) isLoggedIn() → {boolean}
Check authentication using the module:authService
.
- Source:
Returns:
- Type:
-
boolean
Whether or not the user is authenticated.
(static) getUser() → {Promise}
Get the user via the API.
- Source:
- See:
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the HTTP response data.
- Rejected with the full HTTP response object or an error.
(static) getUserData() → {Object}
Get the current user data from localStorage.
- Source:
Returns:
- Type:
-
Object
(static) setUser(newUser)
Set the current user data in localStorage.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
newUser |
Object
|
(static) updateUser(data) → {Promise}
Update a user via the API.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
data |
Object
|
Request message data |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the HTTP response data.
- Rejected with the full HTTP response object or an error.
(static) logout()
Clear authentication and stored local user data.
- Source:
(static) startSession(dataopt) → {Promise}
Start a session via the API.
- Source:
- See:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Object
|
<optional> |
Request message data. |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the HTTP response data.
- Rejected with the full HTTP response object or an error.
(static) login(data) → {Promise}
Login as a user.
Calls module:userService~authDataApply
on success.
- Source:
- See:
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object
|
Request message data.
|
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the current user Object.
- Rejected with the full HTTP response object or an error.
(static) register(data) → {Promise}
Login as a user.
Calls module:userService~authDataApply
on success.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
data |
Object
|
Request message data. |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the current user Object.
- Rejected with the full HTTP response object or an error.
(static) checkAuthorizedUser(data) → {Promise}
Check authorization via the API.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
data |
Object
|
Request message data. |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the response data's
authorization
property. - Rejected with the full HTTP response object or an error.
(static) clearScores(data) → {Promise}
Clear player scores via the API.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
data |
Object
|
Request message data. |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the ull HTTP response object.
- Rejected with the full HTTP response object or an error.
(private, inner) authDataApply(data, response) → {Promise}
Internal method used to handle a successful API response of login and registration requests. It attempts to do the following:
- Set authentication data in
module:authService
- Get the currently logged in user object (via
module:userService.getUser
) - Set the currently stored user object (via
module:userService.SetUser
) - Start a session (via
module:userService.startSession
)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
data |
Object
|
Request message data. |
response |
Object
|
HTTP response object. |
Returns:
- Type:
-
Promise
Promise object, either:
- Resolved with the current user Object.
- Rejected with the full HTTP response object or an error.