mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 19:20:37 +02:00
Merge remote-tracking branch 'origin/master' into 1580-registrar-api-contacts-endpoint
This commit is contained in:
commit
a80d037677
37 changed files with 376 additions and 411 deletions
|
@ -1,7 +0,0 @@
|
|||
module Devise
|
||||
module Models
|
||||
# Devise fails without this module (and model: false does not help)
|
||||
module IdCardAuthenticatable
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,49 +0,0 @@
|
|||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Warden::Strategies.add(:id_card_authenticatable, Devise::Strategies::IdCardAuthenticatable)
|
20
lib/serializers/registrant_api/company.rb
Normal file
20
lib/serializers/registrant_api/company.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Serializers
|
||||
module RegistrantApi
|
||||
class Company
|
||||
attr_reader :company, :country_code
|
||||
|
||||
def initialize(company:, country_code:)
|
||||
@company = company
|
||||
@country_code = country_code
|
||||
end
|
||||
|
||||
def to_json(*_args)
|
||||
{
|
||||
name: company.company_name,
|
||||
registry_no: company.registration_number,
|
||||
country_code: @country_code,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue