Created
March 27, 2013 02:16
-
-
Save giosakti/5251023 to your computer and use it in GitHub Desktop.
This file contains 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
app.service "Session", (sessionStore, UserSession) -> | |
# Initialize variables (happens every page load) | |
@signedIn = !!window.sessionStorage.getItem(sessionStore) | |
@signedOut = not @signedIn | |
if @signedIn | |
@currentUser = JSON.parse(window.sessionStorage.getItem(sessionStore)).user | |
@userSession = new UserSession( | |
login: "" | |
password: "" | |
remember_me: false | |
auth_token: @currentUser.authentication_token | |
) | |
else | |
@currentUser = null | |
@userSession = new UserSession( | |
login: "" | |
password: "" | |
remember_me: false | |
auth_token: "" | |
) | |
# Function for storing session data, then update variables accordingly | |
@putSessionData = (sessionData) -> | |
window.sessionStorage.setItem(sessionStore, JSON.stringify(sessionData)) | |
@signedIn = true | |
@signedOut = not @signedIn | |
@currentUser = sessionData.user | |
@userSession = new UserSession( | |
login: "" | |
password: "" | |
remember_me: false | |
auth_token: sessionData.user.authentication_token | |
) | |
# Function for clearing session data, then update variables accordingly | |
@removeSessionData = () -> | |
window.sessionStorage.removeItem(sessionStore) | |
@signedIn = false | |
@signedOut = not @signedIn | |
@currentUser = null | |
@userSession = new UserSession( | |
login: "" | |
password: "" | |
remember_me: false | |
auth_token: "" | |
) | |
return this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment