Ben/fix authorization edge case (#748)
* Add top param to article tag api * Fix user validation persistence bug
This commit is contained in:
parent
eafefd7422
commit
cf075d4a9f
4 changed files with 15 additions and 3 deletions
|
|
@ -7,10 +7,12 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
def #{provider}
|
||||
cta_variant = request.env["omniauth.params"]['state'].to_s
|
||||
@user = AuthorizationService.new(request.env["omniauth.auth"], current_user, cta_variant).get_user
|
||||
if @user.persisted?
|
||||
if @user.persisted? && @user.valid?
|
||||
remember_me(@user)
|
||||
sign_in_and_redirect @user, event: :authentication
|
||||
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
|
||||
elsif @user.persisted? && @user.errors&.full_messages&.join.include?("username has already been taken")
|
||||
redirect_to "/settings?state=previous-registration"
|
||||
else
|
||||
session["devise.#{provider}_data"] = request.env["omniauth.auth"]
|
||||
redirect_to new_user_registration_url
|
||||
|
|
|
|||
|
|
@ -76,14 +76,14 @@ class AuthorizationService
|
|||
end
|
||||
|
||||
def update_user(user)
|
||||
user.remember_me!
|
||||
user.remember_me = true
|
||||
if auth.provider == "github" && auth.info.nickname != user.github_username
|
||||
user.github_username = auth.info.nickname
|
||||
end
|
||||
if auth.provider == "twitter" && auth.info.nickname != user.twitter_username
|
||||
user.twitter_username = auth.info.nickname
|
||||
end
|
||||
user.remember_me!
|
||||
user.remember_me = true
|
||||
add_social_identity_data(user)
|
||||
user.save
|
||||
user
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if params[:state] == "previous-registration" %>
|
||||
<div class="notice error-notice" id="notice">
|
||||
There is an existing account authorized with that social account. Contact <a href="mailto:yo@dev.to">yo@dev.to</a> if this is a mistake.
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="user-settings-page">
|
||||
<% if @tab == "organization" && @user.organization.present? %>
|
||||
|
|
|
|||
|
|
@ -33,6 +33,11 @@ RSpec.describe "UserSettings", type: :request do
|
|||
get "/settings/membership"
|
||||
expect(response.body).to include("Settings for")
|
||||
end
|
||||
|
||||
it "renders heads up dupe account message with proper param" do
|
||||
get "/settings?state=previous-registration"
|
||||
expect(response.body).to include("There is an existing account authorized with that social account")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue