Files
old-ribica/front-ui/app/actions/userActions.js
Edin Dazdarevic 4befef5bf4 login progress
2015-03-02 07:49:36 +01:00

65 lines
1.6 KiB
JavaScript

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;