Renames confirmed_oauth_email to oauth_email
Refactors the way oauth_email is used to cover more cases (fixes pending specs)
This commit is contained in:
@@ -32,23 +32,26 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
|
||||
# If there are no problems with the email/username, then they were provided by oauth or they
|
||||
# correspond to an existing user. Associate the identity and sign in
|
||||
if @user.save
|
||||
unless @user.save
|
||||
# If either the username or email have provoked a failure, we save the user anyway (but marked for revision)
|
||||
# This mark will be detected by applicationcontroller and the user will be redirected to finish_signup
|
||||
@user.registering_with_oauth = true
|
||||
unless @user.save
|
||||
# If we still can't save the user, the email might be invalidating devise's validatable "unique"
|
||||
# constraint. Set email to nil and try again (we'll reset later using oauth_email)
|
||||
@user.email = nil
|
||||
@user.save
|
||||
end
|
||||
end
|
||||
|
||||
if @user.persisted?
|
||||
identity.update(user: @user)
|
||||
sign_in_and_redirect @user, event: :authentication
|
||||
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
|
||||
else
|
||||
# If either the username or email have provoked a failure, we save the user anyway (but marked for revision)
|
||||
# This mark will be detected by applicationcontroller and the user will be redirected to finish_signup
|
||||
@user.registering_with_oauth = true
|
||||
if @user.save
|
||||
identity.update(user: @user)
|
||||
sign_in_and_redirect @user, event: :authentication
|
||||
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
|
||||
else
|
||||
# If the failure is because something else happens, just present the "new user" form
|
||||
session["devise.#{provider}_data"] = auth
|
||||
redirect_to new_user_registration_url
|
||||
end
|
||||
# If the failure is because something else happens, just present the "new user" form
|
||||
session["devise.#{provider}_data"] = auth
|
||||
redirect_to new_user_registration_url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
||||
|
||||
def finish_signup
|
||||
current_user.registering_with_oauth = false
|
||||
current_user.email = current_user.oauth_email if current_user.email.blank?
|
||||
current_user.validate
|
||||
end
|
||||
|
||||
@@ -32,12 +33,12 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
||||
current_user.registering_with_oauth = false
|
||||
if current_user.update(sign_up_params)
|
||||
|
||||
if current_user.confirmed_oauth_email != current_user.email
|
||||
if current_user.oauth_email != current_user.email
|
||||
current_user.update(confirmed_at: nil)
|
||||
current_user.send_confirmation_instructions
|
||||
end
|
||||
if current_user.confirmed_oauth_email.present?
|
||||
current_user.update(confirmed_oauth_email: nil)
|
||||
if current_user.oauth_email.present?
|
||||
current_user.update(oauth_email: nil)
|
||||
end
|
||||
|
||||
sign_in_and_redirect current_user, event: :authentication
|
||||
|
||||
Reference in New Issue
Block a user