diff --git a/front-api/controllers/user.rb b/front-api/controllers/user.rb index b9ef02b..252cc50 100644 --- a/front-api/controllers/user.rb +++ b/front-api/controllers/user.rb @@ -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 diff --git a/front-ui/app/actions/userActions.js b/front-ui/app/actions/userActions.js index 594f67f..4224728 100644 --- a/front-ui/app/actions/userActions.js +++ b/front-ui/app/actions/userActions.js @@ -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() { diff --git a/front-ui/app/components/account/register.js b/front-ui/app/components/account/register.js index f321df5..efa3a43 100644 --- a/front-ui/app/components/account/register.js +++ b/front-ui/app/components/account/register.js @@ -144,7 +144,6 @@ var Register = React.createClass({ //} //}.bind(this), 1000); - } else { return ['Neispravna email adresa.']; } diff --git a/front-ui/app/components/shared/loginStatus.js b/front-ui/app/components/shared/loginStatus.js index b98d668..c19bde6 100644 --- a/front-ui/app/components/shared/loginStatus.js +++ b/front-ui/app/components/shared/loginStatus.js @@ -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(); diff --git a/front-ui/app/stores/userStore.js b/front-ui/app/stores/userStore.js index 918ff3e..cb1a0cd 100644 --- a/front-ui/app/stores/userStore.js +++ b/front-ui/app/stores/userStore.js @@ -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);