mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Make Registrant/Registrar use same TARA controller
This commit is contained in:
parent
11ee1f9f1e
commit
f83e532fb1
5 changed files with 56 additions and 84 deletions
40
app/controllers/sso/tara_controller.rb
Normal file
40
app/controllers/sso/tara_controller.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Sso
|
||||
class TaraController < ApplicationController
|
||||
skip_authorization_check
|
||||
|
||||
def registrant_callback
|
||||
user = RegistrantUser.find_or_create_by_omniauth_data(user_hash)
|
||||
callback(user, registrar: false)
|
||||
end
|
||||
|
||||
def registrar_callback
|
||||
user = ApiUser.from_omniauth(user_hash)
|
||||
callback(user, registrar: true)
|
||||
end
|
||||
|
||||
# rubocop:disable Style/AndOr
|
||||
def callback(user, registrar: true)
|
||||
session[:omniauth_hash] = user_hash
|
||||
(show error and return) unless user
|
||||
|
||||
flash[:notice] = t(:signed_in_successfully)
|
||||
sign_in_and_redirect(registrar ? :registrar_user : :registrant_user, user)
|
||||
end
|
||||
# rubocop:enable Style/AndOr
|
||||
|
||||
def cancel
|
||||
redirect_to root_path, notice: t(:sign_in_cancelled)
|
||||
end
|
||||
|
||||
def show_error(registrar: true)
|
||||
path = registrar ? new_registrar_user_session_url : new_registrant_user_session_url
|
||||
redirect_to path, alert: t(:no_such_user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_hash
|
||||
request.env['omniauth.auth']
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue