mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +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
|
@ -1,33 +0,0 @@
|
||||||
class Registrant
|
|
||||||
class TaraController < ApplicationController
|
|
||||||
skip_authorization_check
|
|
||||||
|
|
||||||
# rubocop:disable Style/AndOr
|
|
||||||
def callback
|
|
||||||
session[:omniauth_hash] = user_hash
|
|
||||||
@registrant_user = RegistrantUser.find_or_create_by_omniauth_data(user_hash)
|
|
||||||
|
|
||||||
if @registrant_user
|
|
||||||
flash[:notice] = t(:signed_in_successfully)
|
|
||||||
sign_in_and_redirect(:registrant_user, @registrant_user)
|
|
||||||
else
|
|
||||||
show_error and return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# rubocop:enable Style/AndOr
|
|
||||||
|
|
||||||
def cancel
|
|
||||||
redirect_to root_path, notice: t(:sign_in_cancelled)
|
|
||||||
end
|
|
||||||
|
|
||||||
def show_error
|
|
||||||
redirect_to new_registrant_user_session_url, alert: t(:no_such_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def user_hash
|
|
||||||
request.env['omniauth.auth']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,33 +0,0 @@
|
||||||
class Registrar
|
|
||||||
class TaraController < ApplicationController
|
|
||||||
skip_authorization_check
|
|
||||||
|
|
||||||
# rubocop:disable Style/AndOr
|
|
||||||
def callback
|
|
||||||
session[:omniauth_hash] = user_hash
|
|
||||||
@api_user = ApiUser.from_omniauth(user_hash)
|
|
||||||
|
|
||||||
if @api_user
|
|
||||||
flash[:notice] = t(:signed_in_successfully)
|
|
||||||
sign_in_and_redirect(:registrar_user, @api_user)
|
|
||||||
else
|
|
||||||
show_error and return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# rubocop:enable Style/AndOr
|
|
||||||
|
|
||||||
def cancel
|
|
||||||
redirect_to root_path, notice: t(:sign_in_cancelled)
|
|
||||||
end
|
|
||||||
|
|
||||||
def show_error
|
|
||||||
redirect_to new_registrar_user_session_url, alert: t(:no_such_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def user_hash
|
|
||||||
request.env['omniauth.auth']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
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
|
|
@ -280,6 +280,4 @@ Devise.setup do |config|
|
||||||
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
|
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
|
||||||
# so you need to do it manually. For the users scope, it would be:
|
# so you need to do it manually. For the users scope, it would be:
|
||||||
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
||||||
|
|
||||||
routes = [nil, :new, :destroy]
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,12 +76,6 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
devise_for :users, path: '', class_name: 'ApiUser', skip: %i[sessions]
|
devise_for :users, path: '', class_name: 'ApiUser', skip: %i[sessions]
|
||||||
|
|
||||||
devise_scope :registrar_user do
|
|
||||||
match '/open_id/callback', via: %i[get post], to: 'tara#callback', as: :tara_callback
|
|
||||||
match '/open_id/cancel', via: %i[get post delete], to: 'tara#cancel',
|
|
||||||
as: :tara_cancel
|
|
||||||
end
|
|
||||||
|
|
||||||
resources :invoices, except: %i[new create edit update destroy] do
|
resources :invoices, except: %i[new create edit update destroy] do
|
||||||
resource :delivery, controller: 'invoices/delivery', only: %i[new create]
|
resource :delivery, controller: 'invoices/delivery', only: %i[new create]
|
||||||
|
|
||||||
|
@ -158,6 +152,22 @@ Rails.application.routes.draw do
|
||||||
post 'sessions', to: 'registrar/sessions#create', as: :registrar_user_session
|
post 'sessions', to: 'registrar/sessions#create', as: :registrar_user_session
|
||||||
|
|
||||||
delete 'sign_out', to: 'registrar/sessions#destroy', as: :destroy_registrar_user_session
|
delete 'sign_out', to: 'registrar/sessions#destroy', as: :destroy_registrar_user_session
|
||||||
|
|
||||||
|
# TARA
|
||||||
|
match '/open_id/callback', via: %i[get post], to: 'sso/tara#registrar_callback'
|
||||||
|
match '/open_id/cancel', via: %i[get post delete], to: 'sso/tara#cancel'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scope :registrant do
|
||||||
|
devise_scope :registrant_user do
|
||||||
|
get 'sign_in', to: 'registrant/sessions#new', as: :new_registrant_user_session
|
||||||
|
post 'sessions', to: 'registrant/sessions#create', as: :registrant_user_session
|
||||||
|
delete 'sign_out', to: 'registrant/sessions#destroy', as: :destroy_registrant_user_session
|
||||||
|
|
||||||
|
# TARA
|
||||||
|
match '/open_id/callback', via: %i[get post], to: 'sso/tara#registrant_callback'
|
||||||
|
match '/open_id/cancel', via: %i[get post delete], to: 'sso/tara#cancel'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -166,16 +176,6 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
# POST /registrant/sign_in is not used
|
# POST /registrant/sign_in is not used
|
||||||
devise_for :users, path: '', class_name: 'RegistrantUser'
|
devise_for :users, path: '', class_name: 'RegistrantUser'
|
||||||
devise_scope :registrant_user do
|
|
||||||
get 'login/mid' => 'sessions#login_mid'
|
|
||||||
post 'login/mid' => 'sessions#mid'
|
|
||||||
post 'login/mid_status' => 'sessions#mid_status'
|
|
||||||
post 'mid' => 'sessions#mid'
|
|
||||||
|
|
||||||
match '/open_id/callback', via: %i[get post], to: 'tara#callback', as: :tara_registrant_callback
|
|
||||||
match '/open_id/cancel', via: %i[get post delete], to: 'tara#cancel',
|
|
||||||
as: :tara_registrant_cancel
|
|
||||||
end
|
|
||||||
|
|
||||||
resources :registrars, only: :show
|
resources :registrars, only: :show
|
||||||
resources :domains, only: %i[index show] do
|
resources :domains, only: %i[index show] do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue