after successful registration user should be logged in
This commit is contained in:
@@ -36,7 +36,8 @@ post '/user' do
|
||||
user.from_json(json, false)
|
||||
|
||||
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
|
||||
status 400
|
||||
user.errors.to_json
|
||||
|
||||
@@ -12,24 +12,28 @@ var UserActions = {
|
||||
user: user
|
||||
});
|
||||
|
||||
user.save(null, {
|
||||
success: function() {
|
||||
UserActions.registrationSuccess();
|
||||
},
|
||||
error: function(model, response, options) {
|
||||
UserActions.registrationFailure(response);
|
||||
}
|
||||
});
|
||||
superagent
|
||||
.post(globals.ApiUrl + '/user')
|
||||
.send(user)
|
||||
.withCredentials()
|
||||
.end(function(response){
|
||||
if(response.ok) {
|
||||
UserActions.registrationSuccess(response.body);
|
||||
} else {
|
||||
UserActions.registrationFailure(response.body);
|
||||
}
|
||||
});
|
||||
},
|
||||
registrationSuccess: function() {
|
||||
registrationSuccess: function(user) {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: UserConstants.REGISTRATION_SUCCESS
|
||||
actionType: UserConstants.REGISTRATION_SUCCESS,
|
||||
user: user
|
||||
});
|
||||
},
|
||||
registrationFailure: function(error) {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: UserConstants.REGISTRATION_FAILURE,
|
||||
error: error
|
||||
error: error
|
||||
});
|
||||
},
|
||||
userLogout:function() {
|
||||
|
||||
@@ -144,7 +144,6 @@ var Register = React.createClass({
|
||||
//}
|
||||
|
||||
//}.bind(this), 1000);
|
||||
|
||||
} else {
|
||||
return ['Neispravna email adresa.'];
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ var LoginStatus = React.createClass({
|
||||
return UserStore.getLoginState();
|
||||
},
|
||||
componentDidMount: function() {
|
||||
UserActions.checkLogin();
|
||||
UserStore.addChangeListener(this.onUserStateChange);
|
||||
UserActions.checkLogin();
|
||||
},
|
||||
componentWillReceiveProps: function() {
|
||||
this.update();
|
||||
@@ -23,7 +23,9 @@ var LoginStatus = React.createClass({
|
||||
this.update();
|
||||
},
|
||||
update: function() {
|
||||
this.setState(UserStore.getLoginState());
|
||||
if(this.isMounted()) {
|
||||
this.setState(UserStore.getLoginState());
|
||||
}
|
||||
},
|
||||
logout: function(e){
|
||||
e.preventDefault();
|
||||
|
||||
@@ -6,11 +6,13 @@ var NavigationActions = require('../actions/navigationActions');
|
||||
var _registrationState = {};
|
||||
var _loginState = {};
|
||||
|
||||
var handleRegistrationSuccess = function() {
|
||||
var handleRegistrationSuccess = function(user) {
|
||||
_registrationState = {
|
||||
performed: true,
|
||||
success: true
|
||||
};
|
||||
|
||||
handleLoginSuccess(user);
|
||||
};
|
||||
|
||||
var handleRegistrationFailure = function(error) {
|
||||
@@ -51,7 +53,7 @@ var handleCheckLoginArrived = function(user, error) {
|
||||
};
|
||||
|
||||
var handleLogoutDone = function() {
|
||||
|
||||
_registrationState = {};
|
||||
_loginState = {
|
||||
loggedIn: false
|
||||
}
|
||||
@@ -94,7 +96,7 @@ AppDispatcher.register(function(payload) {
|
||||
|
||||
|
||||
case UserConstants.REGISTRATION_SUCCESS:
|
||||
handleRegistrationSuccess();
|
||||
handleRegistrationSuccess(action.user);
|
||||
break;
|
||||
case UserConstants.REGISTRATION_FAILURE:
|
||||
handleRegistrationFailure(action.error);
|
||||
|
||||
Reference in New Issue
Block a user