mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
28 lines
690 B
Ruby
28 lines
690 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|
def github
|
|
handle_auth('GitHub')
|
|
end
|
|
|
|
def google_oauth2
|
|
handle_auth('Google')
|
|
end
|
|
|
|
private
|
|
|
|
def handle_auth(provider)
|
|
@user = User.from_omniauth(request.env['omniauth.auth'])
|
|
|
|
if @user.persisted?
|
|
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: provider
|
|
sign_in_and_redirect @user, event: :authentication
|
|
else
|
|
redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n")
|
|
end
|
|
end
|
|
|
|
def failure
|
|
redirect_to root_path, alert: "Authentication failed: #{params[:message]}"
|
|
end
|
|
end
|