FIX: redirect to original URL after social signup

This commit is contained in:
Vinoth Kannan 2018-09-05 00:46:54 +05:30
parent 4382fb5fac
commit d8b543bb67
4 changed files with 23 additions and 0 deletions

View File

@ -205,6 +205,11 @@ export default Ember.Controller.extend(
"accountChallenge"
);
const userFields = this.get("userFields");
const destinationUrl = this.get("authOptions.destination_url");
if (!Ember.isEmpty(destinationUrl)) {
$.cookie("destination_url", destinationUrl, { path: '/' });
}
// Add the userfields to the data
if (!Ember.isEmpty(userFields)) {
@ -255,10 +260,12 @@ export default Ember.Controller.extend(
this.get("rejectedPasswords").pushObject(attrs.accountPassword);
}
this.set("formSubmitted", false);
$.cookie("destination_url", null);
}
},
() => {
this.set("formSubmitted", false);
$.cookie("destination_url", null);
return this.flash(I18n.t("create_account.failed"), "error");
}
);

View File

@ -675,6 +675,8 @@ class UsersController < ApplicationController
if current_user.present?
if SiteSetting.enable_sso_provider && payload = cookies.delete(:sso_payload)
return redirect_to(session_sso_provider_url + "?" + payload)
elsif destination_url = cookies.delete(:destination_url)
return redirect_to(destination_url)
else
return redirect_to(path('/'))
end

View File

@ -69,6 +69,8 @@ class Auth::Result
email_valid: !!email_valid,
omit_username: !!omit_username }
result[:destination_url] = destination_url if destination_url.present?
if SiteSetting.enable_names?
result[:name] = User.suggest_name(name || username || email)
end

View File

@ -2571,6 +2571,18 @@ describe UsersController do
expect(response).to redirect_to("/")
end
context 'when cookies contains a destination URL' do
it 'should redirect to the URL' do
sign_in(Fabricate(:user))
destination_url = 'http://thisisasite.com/somepath'
cookies[:destination_url] = destination_url
get "/u/account-created"
expect(response).to redirect_to(destination_url)
end
end
context "when the user account is created" do
include ApplicationHelper