We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
46 lines
1.2 KiB
Ruby
46 lines
1.2 KiB
Ruby
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|
def twitter
|
|
sign_in_with :twitter_login, :twitter
|
|
end
|
|
|
|
def facebook
|
|
sign_in_with :facebook_login, :facebook
|
|
end
|
|
|
|
def google_oauth2
|
|
sign_in_with :google_login, :google_oauth2
|
|
end
|
|
|
|
def after_sign_in_path_for(resource)
|
|
if resource.registering_with_oauth
|
|
finish_signup_path
|
|
else
|
|
super(resource)
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def sign_in_with(feature, provider)
|
|
raise ActionController::RoutingError.new("Not Found") unless Setting["feature.#{feature}"]
|
|
|
|
auth = request.env["omniauth.auth"]
|
|
|
|
identity = Identity.first_or_create_from_oauth(auth)
|
|
@user = current_user || identity.user || User.first_or_initialize_for_oauth(auth)
|
|
|
|
if save_user
|
|
identity.update!(user: @user)
|
|
sign_in_and_redirect @user, event: :authentication
|
|
set_flash_message(:notice, :success, kind: provider.to_s.capitalize) if is_navigational_format?
|
|
else
|
|
session["devise.#{provider}_data"] = auth
|
|
redirect_to new_user_registration_path
|
|
end
|
|
end
|
|
|
|
def save_user
|
|
@user.save || @user.save_requiring_finish_signup
|
|
end
|
|
end
|