after successful registration user should be logged in

This commit is contained in:
Edin Dazdarevic
2015-03-03 22:19:41 +01:00
parent 9ebb4769af
commit 38de717da9
5 changed files with 26 additions and 18 deletions

View File

@@ -36,7 +36,8 @@ post '/user' do
user.from_json(json, false) user.from_json(json, false)
if user.save if user.save
{:status => "ok"}.to_json response.set_cookie('ribica_auth', :path=> '/', :httponly => true, :value=>user.id, :expires=>Time.now+100.year)
user.to_json(except: 'password_digest')
else else
status 400 status 400
user.errors.to_json user.errors.to_json

View File

@@ -12,18 +12,22 @@ var UserActions = {
user: user user: user
}); });
user.save(null, { superagent
success: function() { .post(globals.ApiUrl + '/user')
UserActions.registrationSuccess(); .send(user)
}, .withCredentials()
error: function(model, response, options) { .end(function(response){
UserActions.registrationFailure(response); if(response.ok) {
UserActions.registrationSuccess(response.body);
} else {
UserActions.registrationFailure(response.body);
} }
}); });
}, },
registrationSuccess: function() { registrationSuccess: function(user) {
AppDispatcher.handleAction({ AppDispatcher.handleAction({
actionType: UserConstants.REGISTRATION_SUCCESS actionType: UserConstants.REGISTRATION_SUCCESS,
user: user
}); });
}, },
registrationFailure: function(error) { registrationFailure: function(error) {

View File

@@ -144,7 +144,6 @@ var Register = React.createClass({
//} //}
//}.bind(this), 1000); //}.bind(this), 1000);
} else { } else {
return ['Neispravna email adresa.']; return ['Neispravna email adresa.'];
} }

View File

@@ -10,8 +10,8 @@ var LoginStatus = React.createClass({
return UserStore.getLoginState(); return UserStore.getLoginState();
}, },
componentDidMount: function() { componentDidMount: function() {
UserActions.checkLogin();
UserStore.addChangeListener(this.onUserStateChange); UserStore.addChangeListener(this.onUserStateChange);
UserActions.checkLogin();
}, },
componentWillReceiveProps: function() { componentWillReceiveProps: function() {
this.update(); this.update();
@@ -23,7 +23,9 @@ var LoginStatus = React.createClass({
this.update(); this.update();
}, },
update: function() { update: function() {
if(this.isMounted()) {
this.setState(UserStore.getLoginState()); this.setState(UserStore.getLoginState());
}
}, },
logout: function(e){ logout: function(e){
e.preventDefault(); e.preventDefault();

View File

@@ -6,11 +6,13 @@ var NavigationActions = require('../actions/navigationActions');
var _registrationState = {}; var _registrationState = {};
var _loginState = {}; var _loginState = {};
var handleRegistrationSuccess = function() { var handleRegistrationSuccess = function(user) {
_registrationState = { _registrationState = {
performed: true, performed: true,
success: true success: true
}; };
handleLoginSuccess(user);
}; };
var handleRegistrationFailure = function(error) { var handleRegistrationFailure = function(error) {
@@ -51,7 +53,7 @@ var handleCheckLoginArrived = function(user, error) {
}; };
var handleLogoutDone = function() { var handleLogoutDone = function() {
_registrationState = {};
_loginState = { _loginState = {
loggedIn: false loggedIn: false
} }
@@ -94,7 +96,7 @@ AppDispatcher.register(function(payload) {
case UserConstants.REGISTRATION_SUCCESS: case UserConstants.REGISTRATION_SUCCESS:
handleRegistrationSuccess(); handleRegistrationSuccess(action.user);
break; break;
case UserConstants.REGISTRATION_FAILURE: case UserConstants.REGISTRATION_FAILURE:
handleRegistrationFailure(action.error); handleRegistrationFailure(action.error);