Last active
August 29, 2015 14:06
-
-
Save rgoldfinger/afc3943016fa8f672cec 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
constants = require('../constants/constants') | |
AppDispatcher = require('../dispatchers/appDispatcher') | |
ApiHelper = require('../helpers/ApiHelper') | |
LoginActionsCreators = { | |
# user actions | |
loginUser: (username, password) -> | |
# this is called when submitting the login form | |
# this just assembles the payload and sends it to the API | |
data = { | |
username: username | |
password: password | |
} | |
ApiHelper('POST', '/auth', data, LoginActionsCreators.receiveUserLogin) | |
signupUser: (username, password) -> | |
data = { | |
username: username | |
password: password | |
} | |
ApiHelper('POST', '/signup', data, LoginActionsCreators.receiveUserLogin) | |
logoutUser: -> | |
AppDispatcher.handleServerAction({ | |
actionType: constants.LOGOUT_USER | |
}) | |
# server actions | |
receiveUserLogin: (error, data) -> | |
if (error) | |
# handle error | |
else | |
AppDispatcher.handleServerAction({ | |
actionType: constants.RECEIVE_LOGIN_USER | |
user: data.user | |
token: data.token | |
exp: data.exp | |
}) | |
}; | |
module.exports = LoginActionsCreators; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment