mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Fix mess with registrant user routes
This commit is contained in:
parent
94b8ffd158
commit
6e99521d59
6 changed files with 54 additions and 55 deletions
|
@ -2,7 +2,7 @@ require 'open3'
|
|||
|
||||
class ApiUser < User
|
||||
include EppErrors
|
||||
devise :database_authenticatable, :trackable, :timeoutable, #:id_card_authenticatable,
|
||||
devise :database_authenticatable, :trackable, :timeoutable,
|
||||
authentication_keys: [:username]
|
||||
|
||||
def epp_code_map
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class RegistrantUser < User
|
||||
attr_accessor :idc_data
|
||||
|
||||
devise :trackable, :timeoutable
|
||||
devise :trackable, :timeoutable, :id_card_authenticatable
|
||||
|
||||
def ability
|
||||
@ability ||= Ability.new(self)
|
||||
|
|
|
@ -21,5 +21,4 @@ class User < ApplicationRecord
|
|||
|
||||
User.find_by(identity_code: identity_code, country_code: country_code)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -281,9 +281,9 @@ Devise.setup do |config|
|
|||
# so you need to do it manually. For the users scope, it would be:
|
||||
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
||||
|
||||
# require 'devise/models/id_card_authenticatable'
|
||||
# require 'devise/strategies/id_card_authenticatable'
|
||||
require 'devise/models/id_card_authenticatable'
|
||||
require 'devise/strategies/id_card_authenticatable'
|
||||
|
||||
# routes = [nil, :new, :destroy]
|
||||
# config.add_module :id_card_authenticatable, strategy: true, route: { session: routes }
|
||||
routes = [nil, :new, :destroy]
|
||||
config.add_module :id_card_authenticatable, strategy: true, route: { session: routes }
|
||||
end
|
||||
|
|
|
@ -77,14 +77,14 @@ Rails.application.routes.draw do
|
|||
devise_for :users, path: '', class_name: 'ApiUser', skip: %i[sessions]
|
||||
|
||||
devise_scope :registrar_user do
|
||||
# get 'login/mid' => 'sessions#login_mid'
|
||||
# post 'login/mid' => 'sessions#mid'
|
||||
# post 'login/mid_status' => 'sessions#mid_status'
|
||||
get 'login/mid' => 'sessions#login_mid'
|
||||
post 'login/mid' => 'sessions#mid'
|
||||
post 'login/mid_status' => 'sessions#mid_status'
|
||||
|
||||
# /registrar/id path is hardcoded in Apache config for authentication with Estonian ID-card
|
||||
# post 'id' => 'sessions#id_card', as: :id_card_sign_in
|
||||
#
|
||||
# post 'mid' => 'sessions#mid'
|
||||
post 'id' => 'sessions#id_card', as: :id_card_sign_in
|
||||
|
||||
post 'mid' => 'sessions#mid'
|
||||
|
||||
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',
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
module Devise
|
||||
module Strategies
|
||||
class IdCardAuthenticatable < Devise::Strategies::Authenticatable
|
||||
# def valid?
|
||||
# env['SSL_CLIENT_S_DN_CN'].present?
|
||||
# end
|
||||
#
|
||||
# def authenticate!
|
||||
# resource = mapping.to
|
||||
# user = resource.find_by_id_card(id_card)
|
||||
#
|
||||
# if user
|
||||
# success!(user)
|
||||
# else
|
||||
# fail
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# private
|
||||
#
|
||||
# def id_card
|
||||
# id_card = IdCard.new
|
||||
# id_card.first_name = first_name
|
||||
# id_card.last_name = last_name
|
||||
# id_card.personal_code = personal_code
|
||||
# id_card.country_code = country_code
|
||||
# id_card
|
||||
# end
|
||||
#
|
||||
# def first_name
|
||||
# env['SSL_CLIENT_S_DN_CN'].split(',').second.force_encoding('utf-8')
|
||||
# end
|
||||
#
|
||||
# def last_name
|
||||
# env['SSL_CLIENT_S_DN_CN'].split(',').first.force_encoding('utf-8')
|
||||
# end
|
||||
#
|
||||
# def personal_code
|
||||
# env['SSL_CLIENT_S_DN_CN'].split(',').last
|
||||
# end
|
||||
#
|
||||
# def country_code
|
||||
# env['SSL_CLIENT_I_DN_C']
|
||||
# end
|
||||
def valid?
|
||||
env['SSL_CLIENT_S_DN_CN'].present?
|
||||
end
|
||||
|
||||
def authenticate!
|
||||
resource = mapping.to
|
||||
user = resource.find_by_id_card(id_card)
|
||||
|
||||
if user
|
||||
success!(user)
|
||||
else
|
||||
fail
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def id_card
|
||||
id_card = IdCard.new
|
||||
id_card.first_name = first_name
|
||||
id_card.last_name = last_name
|
||||
id_card.personal_code = personal_code
|
||||
id_card.country_code = country_code
|
||||
id_card
|
||||
end
|
||||
|
||||
def first_name
|
||||
env['SSL_CLIENT_S_DN_CN'].split(',').second.force_encoding('utf-8')
|
||||
end
|
||||
|
||||
def last_name
|
||||
env['SSL_CLIENT_S_DN_CN'].split(',').first.force_encoding('utf-8')
|
||||
end
|
||||
|
||||
def personal_code
|
||||
env['SSL_CLIENT_S_DN_CN'].split(',').last
|
||||
end
|
||||
|
||||
def country_code
|
||||
env['SSL_CLIENT_I_DN_C']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Warden::Strategies.add(:id_card_authenticatable, Devise::Strategies::IdCardAuthenticatable)
|
||||
Warden::Strategies.add(:id_card_authenticatable, Devise::Strategies::IdCardAuthenticatable)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue