var AppDispatcher = require('../dispatcher/appDispatcher'); var UserConstants = require('../constants/userConstants'); // Define action methods var UserActions = { registerUser: function(user) { AppDispatcher.handleAction({ actionType: UserConstants.REGISTER_USER, user: user }); user.save(null, { success: function() { UserActions.registrationSuccess(); }, error: function(model, response, options) { UserActions.registrationFailure(response); } }); }, registrationSuccess: function() { AppDispatcher.handleAction({ actionType: UserConstants.REGISTRATION_SUCCESS }); }, registrationFailure: function(error) { AppDispatcher.handleAction({ actionType: UserConstants.REGISTRATION_FAILURE, error: error }); }, userLogin: function(loginDetails) { AppDispatcher.handleAction({ actionType: UserConstants.USER_LOGIN, loginDetails: loginDetails }); loginDetails.save(null, { success: function(){ alert('ok') UserActions.loginSuccess(); }, error: function(model, response, options){ alert('error!'); UserActions.loginFailure(response); } }); }, loginSuccess: function() { AppDispatcher.handleAction({ actionType: UserConstants.LOGIN_SUCCESS }); }, loginFailure: function(error) { AppDispatcher.handleAction({ actionType: UserConstants.LOGIN_FAILURE, error: error }); } }; module.exports = UserActions;