mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 05:56:20 +02:00
Modified identification request webhook
This commit is contained in:
parent
d04622c49f
commit
0085f99e02
14 changed files with 292 additions and 19 deletions
|
@ -16,7 +16,10 @@ module Eeid
|
|||
return render_unauthorized unless ip_whitelisted?
|
||||
return render_invalid_signature unless valid_hmac_signature?(request.headers['X-HMAC-Signature'])
|
||||
|
||||
verify_contact(permitted_params[:reference])
|
||||
contact = Contact.find_by_code(permitted_params[:reference])
|
||||
poi = catch_poi
|
||||
verify_contact(contact)
|
||||
inform_registrar(contact, poi)
|
||||
render json: { status: 'success' }, status: :ok
|
||||
rescue StandardError => e
|
||||
handle_error(e)
|
||||
|
@ -42,17 +45,32 @@ module Eeid
|
|||
ActiveSupport::SecurityUtils.secure_compare(computed_signature, hmac_signature)
|
||||
end
|
||||
|
||||
def verify_contact(ref)
|
||||
contact = Contact.find_by_code(ref)
|
||||
|
||||
def verify_contact(contact)
|
||||
ref = permitted_params[:reference]
|
||||
if contact&.ident_request_sent_at.present?
|
||||
contact.update(verified_at: Time.zone.now)
|
||||
contact.update(verified_at: Time.zone.now, verification_id: permitted_params[:identification_request_id])
|
||||
Rails.logger.info("Contact verified: #{ref}")
|
||||
else
|
||||
Rails.logger.error("Valid contact not found for reference: #{ref}")
|
||||
end
|
||||
end
|
||||
|
||||
def catch_poi
|
||||
ident_service = Eeid::IdentificationService.new
|
||||
response = ident_service.get_proof_of_identity(permitted_params[:identification_request_id])
|
||||
raise StandardError, response[:error] if response[:error].present?
|
||||
|
||||
response[:data]
|
||||
end
|
||||
|
||||
def inform_registrar(contact, poi)
|
||||
email = contact&.registrar&.email
|
||||
return unless email
|
||||
|
||||
RegistrarMailer.contact_verified(email: email, contact: contact, poi: poi)
|
||||
.deliver_now
|
||||
end
|
||||
|
||||
def ip_whitelisted?
|
||||
allowed_ips = ENV['webhook_allowed_ips'].to_s.split(',').map(&:strip)
|
||||
|
||||
|
@ -67,7 +85,7 @@ module Eeid
|
|||
|
||||
def handle_error(error)
|
||||
Rails.logger.error("Error handling webhook: #{error.message}")
|
||||
render json: { error: 'Internal Server Error' }, status: :internal_server_error
|
||||
render json: { error: error.message }, status: :internal_server_error
|
||||
end
|
||||
|
||||
def handle_throttle_error
|
||||
|
|
|
@ -2,10 +2,10 @@ require 'serializers/repp/contact'
|
|||
module Repp
|
||||
module V1
|
||||
class ContactsController < BaseController # rubocop:disable Metrics/ClassLength
|
||||
before_action :find_contact, only: %i[show update destroy verify]
|
||||
skip_around_action :log_request, only: :search
|
||||
before_action :find_contact, only: %i[show update destroy verify download_poi]
|
||||
skip_around_action :log_request, only: %i[search]
|
||||
|
||||
THROTTLED_ACTIONS = %i[index check search create show update destroy verify].freeze
|
||||
THROTTLED_ACTIONS = %i[index check search create show update destroy verify download_poi].freeze
|
||||
include Shunter::Integration::Throttle
|
||||
|
||||
api :get, '/repp/v1/contacts'
|
||||
|
@ -132,6 +132,19 @@ module Repp
|
|||
render_success(data: data)
|
||||
end
|
||||
|
||||
api :get, '/repp/v1/contacts/download_poi/:contact_code'
|
||||
desc 'Get proof of identity pdf file for a contact'
|
||||
def download_poi
|
||||
authorize! :verify, Epp::Contact
|
||||
ident_service = Eeid::IdentificationService.new
|
||||
response = ident_service.get_proof_of_identity(@contact.verification_id)
|
||||
|
||||
send_data response[:data], filename: "proof_of_identity_#{@contact.verification_id}.pdf",
|
||||
type: 'application/pdf', disposition: 'inline'
|
||||
rescue Eeid::IdentError => e
|
||||
handle_non_epp_errors(@contact, e.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def index_params
|
||||
|
|
|
@ -23,8 +23,8 @@ module Actions
|
|||
|
||||
def create_identification_request
|
||||
ident_service = Eeid::IdentificationService.new
|
||||
request = ident_service.create_identification_request(request_payload)
|
||||
ContactMailer.identification_requested(contact: contact, link: request['link']).deliver_now
|
||||
response = ident_service.create_identification_request(request_payload)
|
||||
ContactMailer.identification_requested(contact: contact, link: response['link']).deliver_now
|
||||
rescue Eeid::IdentError => e
|
||||
Rails.logger.error e.message
|
||||
contact.errors.add(:base, :verification_error)
|
||||
|
|
10
app/mailers/registrar_mailer.rb
Normal file
10
app/mailers/registrar_mailer.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class RegistrarMailer < ApplicationMailer
|
||||
helper ApplicationHelper
|
||||
|
||||
def contact_verified(email:, contact:, poi:)
|
||||
@contact = contact
|
||||
subject = 'Successful Contact Verification'
|
||||
attachments['proof_of_identity.pdf'] = poi
|
||||
mail(to: email, subject: subject)
|
||||
end
|
||||
end
|
|
@ -85,10 +85,17 @@ module Eeid
|
|||
end
|
||||
|
||||
def handle_response(response)
|
||||
parsed_response = JSON.parse(response.body)
|
||||
case response['content-type']
|
||||
when 'application/pdf', 'application/octet-stream'
|
||||
parsed_response = { data: response.body, message: response['content-disposition'] }
|
||||
when %r{application/json}
|
||||
parsed_response = JSON.parse(response.body).with_indifferent_access
|
||||
else
|
||||
raise IdentError, 'Unsupported content type'
|
||||
end
|
||||
|
||||
raise IdentError, parsed_response['error'] unless response.is_a?(Net::HTTPSuccess)
|
||||
|
||||
Rails.logger.debug("Request successful: #{response.body}")
|
||||
parsed_response
|
||||
end
|
||||
|
||||
|
|
|
@ -17,5 +17,9 @@ module Eeid
|
|||
def get_identification_request(id)
|
||||
request_endpoint("/api/ident/v1/identification_requests/#{id}")
|
||||
end
|
||||
|
||||
def get_proof_of_identity(id)
|
||||
request_endpoint("/api/ident/v1/identification_requests/#{id}/proof_of_identity")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
44
app/views/mailers/registrar_mailer/contact_verified.html.erb
Normal file
44
app/views/mailers/registrar_mailer/contact_verified.html.erb
Normal file
|
@ -0,0 +1,44 @@
|
|||
Tere,
|
||||
<br><br>
|
||||
<p>
|
||||
Anname teada, et järgmise kontakti kinnitamisprotsess on edukalt lõpule viidud.
|
||||
</p>
|
||||
<h3>Kontaktandmed:</h3>
|
||||
<ul>
|
||||
<li><strong>Kood:</strong> <%= @contact.code %></li>
|
||||
<li><strong>Nimi:</strong> <%= @contact.name %></li>
|
||||
<li><strong>Identifikaator:</strong> <%= ident_for(@contact) %></li>
|
||||
</ul>
|
||||
<p>
|
||||
Täielikud tulemused leiate manuses olevast PDF-failist.
|
||||
</p>
|
||||
Kui Teil on küsimusi seoses kontakti kinnitamise või muude teenustega registripidaja portaalis, võtke meiega ühendust.
|
||||
</p>
|
||||
<p>
|
||||
Parimate soovidega,
|
||||
</p>
|
||||
<%= render 'mailers/shared/signatures/signature.et.html' %>
|
||||
<hr>
|
||||
<br><br>
|
||||
|
||||
Hi,
|
||||
<br><br>
|
||||
<p>
|
||||
We are writing to inform you that the verification process for the following contact has been successfully completed.
|
||||
</p>
|
||||
<h3>Contact Details:</h3>
|
||||
<ul>
|
||||
<li><strong>Code:</strong> <%= @contact.code %></li>
|
||||
<li><strong>Name:</strong> <%= @contact.name %></li>
|
||||
<li><strong>Ident:</strong> <%= ident_for(@contact) %></li>
|
||||
</ul>
|
||||
<p>
|
||||
The full result can be found in the attached PDF file.
|
||||
</p>
|
||||
<p>
|
||||
If you have any questions regarding the contact verification or other services in the Registrar Portal, please do not hesitate to reach out to us.
|
||||
</p>
|
||||
<p>
|
||||
Best regards,
|
||||
</p>
|
||||
<%= render 'mailers/shared/signatures/signature.en.html' %>
|
32
app/views/mailers/registrar_mailer/contact_verified.text.erb
Normal file
32
app/views/mailers/registrar_mailer/contact_verified.text.erb
Normal file
|
@ -0,0 +1,32 @@
|
|||
Tere,
|
||||
|
||||
Anname teada, et järgmise kontakti kinnitamisprotsess on edukalt lõpule viidud.
|
||||
|
||||
Kontaktandmed:
|
||||
- Kood: <%= @contact.code %>
|
||||
- Nimi: <%= @contact.name %>
|
||||
- Identifikaator: <%= ident_for(@contact) %>
|
||||
|
||||
Täielikke tulemusi saab vaadata kontakti lehelt registripidaja portaalis.
|
||||
|
||||
Kui Teil on küsimusi seoses kontakti kinnitamise või muude teenustega registripidaja portaalis, võtke meiega ühendust.
|
||||
|
||||
Parimate soovidega,
|
||||
<%= render 'mailers/shared/signatures/signature.et.text' %>
|
||||
---
|
||||
|
||||
Hi,
|
||||
|
||||
We are writing to inform you that the verification process for the following contact has been successfully completed.
|
||||
|
||||
Contact Details:
|
||||
- Code: <%= @contact.code %>
|
||||
- Name: <%= @contact.name %>
|
||||
- Ident: <%= ident_for(@contact) %>
|
||||
|
||||
The full result can be viewed on the contact page in the Registrar Portal.
|
||||
|
||||
If you have any questions regarding the contact verification or other services in the Registrar Portal, please do not hesitate to reach out to us.
|
||||
|
||||
Best regards,
|
||||
<%= render 'mailers/shared/signatures/signature.en.text' %>
|
Loading…
Add table
Add a link
Reference in a new issue