mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Renamed back accounts controller & modified auth validations
This commit is contained in:
parent
9f6c628453
commit
a44ac5359d
4 changed files with 13 additions and 14 deletions
|
@ -1,9 +1,9 @@
|
||||||
module Repp
|
module Repp
|
||||||
module V1
|
module V1
|
||||||
class AccountController < BaseController # rubocop:disable Metrics/ClassLength
|
class AccountsController < BaseController # rubocop:disable Metrics/ClassLength
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
api :get, '/repp/v1/account'
|
api :get, '/repp/v1/accounts'
|
||||||
desc 'Get all activities'
|
desc 'Get all activities'
|
||||||
def index
|
def index
|
||||||
records = current_user.registrar.cash_account.activities
|
records = current_user.registrar.cash_account.activities
|
||||||
|
@ -20,7 +20,7 @@ module Repp
|
||||||
types_for_select: AccountActivity.types_for_select })
|
types_for_select: AccountActivity.types_for_select })
|
||||||
end
|
end
|
||||||
|
|
||||||
api :get, '/repp/v1/account/details'
|
api :get, '/repp/v1/accounts/details'
|
||||||
desc 'Get current registrar account details'
|
desc 'Get current registrar account details'
|
||||||
def details
|
def details
|
||||||
registrar = current_user.registrar
|
registrar = current_user.registrar
|
||||||
|
@ -34,7 +34,7 @@ module Repp
|
||||||
render_success(data: resp)
|
render_success(data: resp)
|
||||||
end
|
end
|
||||||
|
|
||||||
api :put, '/repp/v1/account'
|
api :put, '/repp/v1/accounts'
|
||||||
desc 'Update current registrar account details'
|
desc 'Update current registrar account details'
|
||||||
def update
|
def update
|
||||||
registrar = current_user.registrar
|
registrar = current_user.registrar
|
||||||
|
@ -47,7 +47,7 @@ module Repp
|
||||||
message: I18n.t('registrar.account.update.saved'))
|
message: I18n.t('registrar.account.update.saved'))
|
||||||
end
|
end
|
||||||
|
|
||||||
api :post, '/repp/v1/account/update_auto_reload_balance'
|
api :post, '/repp/v1/accounts/update_auto_reload_balance'
|
||||||
desc 'Enable current registrar balance auto reload'
|
desc 'Enable current registrar balance auto reload'
|
||||||
def update_auto_reload_balance
|
def update_auto_reload_balance
|
||||||
type = BalanceAutoReloadTypes::Threshold.new(type_params)
|
type = BalanceAutoReloadTypes::Threshold.new(type_params)
|
||||||
|
@ -62,7 +62,7 @@ module Repp
|
||||||
message: I18n.t('registrar.settings.balance_auto_reload.update.saved'))
|
message: I18n.t('registrar.settings.balance_auto_reload.update.saved'))
|
||||||
end
|
end
|
||||||
|
|
||||||
api :get, '/repp/v1/account/disable_auto_reload_balance'
|
api :get, '/repp/v1/accounts/disable_auto_reload_balance'
|
||||||
desc 'Disable current registrar balance auto reload'
|
desc 'Disable current registrar balance auto reload'
|
||||||
def disable_auto_reload_balance
|
def disable_auto_reload_balance
|
||||||
registrar = current_user.registrar
|
registrar = current_user.registrar
|
||||||
|
@ -73,7 +73,7 @@ module Repp
|
||||||
message: I18n.t('registrar.settings.balance_auto_reload.destroy.disabled'))
|
message: I18n.t('registrar.settings.balance_auto_reload.destroy.disabled'))
|
||||||
end
|
end
|
||||||
|
|
||||||
api :get, '/repp/v1/account/balance'
|
api :get, '/repp/v1/accounts/balance'
|
||||||
desc "Get account's balance"
|
desc "Get account's balance"
|
||||||
def balance
|
def balance
|
||||||
resp = { balance: current_user.registrar.cash_account.balance,
|
resp = { balance: current_user.registrar.cash_account.balance,
|
|
@ -6,8 +6,8 @@ module Repp
|
||||||
around_action :log_request
|
around_action :log_request
|
||||||
before_action :authenticate_user
|
before_action :authenticate_user
|
||||||
before_action :validate_webclient_ca
|
before_action :validate_webclient_ca
|
||||||
before_action :check_ip_restriction
|
|
||||||
before_action :validate_client_certs
|
before_action :validate_client_certs
|
||||||
|
before_action :check_ip_restriction
|
||||||
before_action :set_paper_trail_whodunnit
|
before_action :set_paper_trail_whodunnit
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -126,7 +126,7 @@ module Repp
|
||||||
end
|
end
|
||||||
|
|
||||||
def webclient_request?
|
def webclient_request?
|
||||||
return if Rails.env.test?
|
return false if Rails.env.test? || Rails.env.development?
|
||||||
|
|
||||||
ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
|
ENV['webclient_ips'].split(',').map(&:strip).include?(request.ip)
|
||||||
end
|
end
|
||||||
|
@ -147,8 +147,9 @@ module Repp
|
||||||
|
|
||||||
def validate_client_certs
|
def validate_client_certs
|
||||||
return if Rails.env.development? || Rails.env.test?
|
return if Rails.env.development? || Rails.env.test?
|
||||||
|
return if webclient_request?
|
||||||
return if @current_user.pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'],
|
return if @current_user.pki_ok?(request.env['HTTP_SSL_CLIENT_CERT'],
|
||||||
request.env['HTTP_SSL_CLIENT_S_DN_CN'], api: false)
|
request.env['HTTP_SSL_CLIENT_S_DN_CN'])
|
||||||
|
|
||||||
@response = { code: 2202, message: 'Invalid certificate' }
|
@response = { code: 2202, message: 'Invalid certificate' }
|
||||||
render(json: @response, status: :unauthorized)
|
render(json: @response, status: :unauthorized)
|
||||||
|
|
|
@ -61,8 +61,6 @@ class ApiUser < User
|
||||||
end
|
end
|
||||||
|
|
||||||
def pki_ok?(crt, com, api: true)
|
def pki_ok?(crt, com, api: true)
|
||||||
p crt
|
|
||||||
p com
|
|
||||||
return false if crt.blank? || com.blank?
|
return false if crt.blank? || com.blank?
|
||||||
|
|
||||||
origin = api ? certificates.api : certificates.registrar
|
origin = api ? certificates.api : certificates.registrar
|
||||||
|
|
|
@ -75,9 +75,9 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resource :account, controller: :account, only: %i[index update] do
|
resource :accounts, only: %i[index update] do
|
||||||
collection do
|
collection do
|
||||||
get '/', to: 'account#index'
|
get '/', to: 'accounts#index'
|
||||||
get 'balance'
|
get 'balance'
|
||||||
get 'details'
|
get 'details'
|
||||||
post 'update_auto_reload_balance'
|
post 'update_auto_reload_balance'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue