FIX: redirect users after signing up with a social login when using SSO provider

This commit is contained in:
Régis Hanol 2018-05-13 16:03:11 +02:00
parent f4e9d47a27
commit be6404d651
2 changed files with 21 additions and 24 deletions

View File

@ -157,21 +157,18 @@ export default Ember.Controller.extend(ModalFunctionality, PasswordValidation, U
}, },
createAccount() { createAccount() {
const self = this, const attrs = this.getProperties('accountName', 'accountEmail', 'accountPassword', 'accountUsername', 'accountPasswordConfirm', 'accountChallenge');
attrs = this.getProperties('accountName', 'accountEmail', 'accountPassword', 'accountUsername', 'accountPasswordConfirm', 'accountChallenge'), const userFields = this.get('userFields');
userFields = this.get('userFields');
// Add the userfields to the data // Add the userfields to the data
if (!Ember.isEmpty(userFields)) { if (!Ember.isEmpty(userFields)) {
attrs.userFields = {}; attrs.userFields = {};
userFields.forEach(function(f) { userFields.forEach(f => attrs.userFields[f.get('field.id')] = f.get('value'));
attrs.userFields[f.get('field.id')] = f.get('value');
});
} }
this.set('formSubmitted', true); this.set('formSubmitted', true);
return Discourse.User.createAccount(attrs).then(function(result) { return Discourse.User.createAccount(attrs).then(result => {
self.set('isDeveloper', false); this.set('isDeveloper', false);
if (result.success) { if (result.success) {
// Trigger the browser's password manager using the hidden static login form: // Trigger the browser's password manager using the hidden static login form:
const $hidden_login_form = $('#hidden-login-form'); const $hidden_login_form = $('#hidden-login-form');
@ -180,24 +177,21 @@ export default Ember.Controller.extend(ModalFunctionality, PasswordValidation, U
$hidden_login_form.find('input[name=redirect]').val(userPath('account-created')); $hidden_login_form.find('input[name=redirect]').val(userPath('account-created'));
$hidden_login_form.submit(); $hidden_login_form.submit();
} else { } else {
self.flash(result.message || I18n.t('create_account.failed'), 'error'); this.flash(result.message || I18n.t('create_account.failed'), 'error');
if (result.is_developer) { if (result.is_developer) {
self.set('isDeveloper', true); this.set('isDeveloper', true);
} }
if (result.errors && result.errors.email && result.errors.email.length > 0 && result.values) { if (result.errors && result.errors.email && result.errors.email.length > 0 && result.values) {
self.get('rejectedEmails').pushObject(result.values.email); this.get('rejectedEmails').pushObject(result.values.email);
} }
if (result.errors && result.errors.password && result.errors.password.length > 0) { if (result.errors && result.errors.password && result.errors.password.length > 0) {
self.get('rejectedPasswords').pushObject(attrs.accountPassword); this.get('rejectedPasswords').pushObject(attrs.accountPassword);
} }
self.set('formSubmitted', false); this.set('formSubmitted', false);
} }
if (result.active && !Discourse.SiteSettings.must_approve_users) { }, () => {
return window.location.reload(); this.set('formSubmitted', false);
} return this.flash(I18n.t('create_account.failed'), 'error');
}, function() {
self.set('formSubmitted', false);
return self.flash(I18n.t('create_account.failed'), 'error');
}); });
} }
} }

View File

@ -663,14 +663,17 @@ class UsersController < ApplicationController
end end
def account_created def account_created
return redirect_to("/") if current_user.present? if current_user.present?
if SiteSetting.enable_sso_provider && payload = cookies.delete(:sso_payload)
return redirect_to(session_sso_provider_url + "?" + payload)
else
return redirect_to("/")
end
end
@custom_body_class = "static-account-created" @custom_body_class = "static-account-created"
@message = session['user_created_message'] || I18n.t('activation.missing_session') @message = session['user_created_message'] || I18n.t('activation.missing_session')
@account_created = { @account_created = { message: @message, show_controls: false }
message: @message,
show_controls: false
}
if session_user_id = session[SessionController::ACTIVATE_USER_KEY] if session_user_id = session[SessionController::ACTIVATE_USER_KEY]
if user = User.where(id: session_user_id.to_i).first if user = User.where(id: session_user_id.to_i).first