Uses registering_with_oauth persistent attribute to deactivate checks in certain occasions
This commit is contained in:
@@ -28,13 +28,25 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||||||
identity = Identity.first_or_create_from_oauth(auth)
|
identity = Identity.first_or_create_from_oauth(auth)
|
||||||
@user = current_user || identity.user || User.first_or_initialize_for_oauth(auth)
|
@user = current_user || identity.user || User.first_or_initialize_for_oauth(auth)
|
||||||
|
|
||||||
|
# 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
|
if @user.save
|
||||||
identity.update(user: @user)
|
identity.update(user: @user)
|
||||||
sign_in_and_redirect @user, event: :authentication
|
sign_in_and_redirect @user, event: :authentication
|
||||||
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
|
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
|
||||||
else
|
else
|
||||||
session["devise.#{provider}_data"] = env["omniauth.auth"]
|
# If either the username or email have provoked a failure, we save the user anyway (but marked for revision)
|
||||||
redirect_to new_user_registration_url
|
# 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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,13 +24,17 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def finish_signup
|
def finish_signup
|
||||||
|
current_user.registering_with_oauth = false
|
||||||
|
current_user.validate
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_finish_signup
|
def do_finish_signup
|
||||||
|
current_user.registering_with_oauth = false
|
||||||
|
current_user.validate
|
||||||
|
should_send_confirmation = current_user.errors.include? :email
|
||||||
if current_user.update(sign_up_params)
|
if current_user.update(sign_up_params)
|
||||||
current_user.skip_reconfirmation!
|
current_user.send_confirmation_instructions if should_send_confirmation
|
||||||
sign_in(current_user, bypass: true)
|
sign_in_and_redirect current_user, event: :authentication
|
||||||
redirect_to root_url
|
|
||||||
else
|
else
|
||||||
render :finish_signup
|
render :finish_signup
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user