Keep a blank line before and after private Keep a blank line before and after protected Remove extra empty line at class body end Remove extra blank line Add final newline Use 2 (not 3) spaces for indentation Use 2 (not 4) spaces for indentation Remove space before comma Add space after comma Remove trailing whitespaces Remove unnecessary spacing Use snake_case for variable names Do not use then for multi-line if Remove unused block argument - i Use the new Ruby 1.9 hash syntax Remove unused assignment to variable Indent when as deep as case Align attributes Align end with def
47 lines
1.2 KiB
Ruby
47 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 = 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(@user)
|
|
identity.update(user: @user)
|
|
sign_in_and_redirect @user, event: :authentication
|
|
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
|
|
else
|
|
session["devise.#{provider}_data"] = auth
|
|
redirect_to new_user_registration_url
|
|
end
|
|
end
|
|
|
|
def save_user(user)
|
|
@user.save || @user.save_requiring_finish_signup
|
|
end
|
|
|
|
end |