mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
Fix codeclimate issues
This commit is contained in:
parent
06f5eb10d4
commit
90b2455032
5 changed files with 13 additions and 14 deletions
|
@ -21,14 +21,14 @@ module API
|
||||||
if token
|
if token
|
||||||
render json: token
|
render json: token
|
||||||
else
|
else
|
||||||
render json: { error: 'Cannot create generate session token'}
|
render json: { error: 'Cannot create generate session token' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def eid_params
|
def eid_params
|
||||||
required_params = [:ident, :first_name, :last_name]
|
required_params = %i[ident first_name last_name]
|
||||||
required_params.each_with_object(params) do |key, obj|
|
required_params.each_with_object(params) do |key, obj|
|
||||||
obj.require(key)
|
obj.require(key)
|
||||||
end
|
end
|
||||||
|
@ -44,10 +44,9 @@ module API
|
||||||
|
|
||||||
def check_ip_whitelist
|
def check_ip_whitelist
|
||||||
allowed_ips = ENV['registrant_api_auth_allowed_ips'].to_s.split(',').map(&:strip)
|
allowed_ips = ENV['registrant_api_auth_allowed_ips'].to_s.split(',').map(&:strip)
|
||||||
|
return if allowed_ips.include?(request.ip) || Rails.env.development?
|
||||||
|
|
||||||
unless allowed_ips.include?(request.ip) || Rails.env.development?
|
render json: { error: 'Not authorized' }, status: :unauthorized
|
||||||
render json: { error: 'Not authorized' }, status: 401
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ module API
|
||||||
def bearer_token
|
def bearer_token
|
||||||
pattern = /^Bearer /
|
pattern = /^Bearer /
|
||||||
header = request.headers['Authorization']
|
header = request.headers['Authorization']
|
||||||
header.gsub(pattern, '') if header && header.match(pattern)
|
header.gsub(pattern, '') if header&.match(pattern)
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate
|
def authenticate
|
||||||
|
@ -29,7 +29,7 @@ module API
|
||||||
if decryptor.valid?
|
if decryptor.valid?
|
||||||
sign_in decryptor.user
|
sign_in decryptor.user
|
||||||
else
|
else
|
||||||
render json: { error: 'Not authorized' }, status: 401
|
render json: { error: 'Not authorized' }, status: :unauthorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,8 +54,8 @@ class RegistrantUser < User
|
||||||
return false unless user_data[:first_name]
|
return false unless user_data[:first_name]
|
||||||
return false unless user_data[:last_name]
|
return false unless user_data[:last_name]
|
||||||
|
|
||||||
user_data.each { |k, v| v.upcase! if v.is_a?(String) }
|
user_data.each_value { |v| v.upcase! if v.is_a?(String) }
|
||||||
user_data[:country_code] ||= "EE"
|
user_data[:country_code] ||= 'EE'
|
||||||
|
|
||||||
find_or_create_by_user_data(user_data)
|
find_or_create_by_user_data(user_data)
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,20 +6,20 @@ class AuthTokenCreator
|
||||||
attr_reader :expires_at
|
attr_reader :expires_at
|
||||||
|
|
||||||
def self.create_with_defaults(user)
|
def self.create_with_defaults(user)
|
||||||
self.new(user, Rails.application.config.secret_key_base, Time.now + DEFAULT_VALIDITY)
|
new(user, Rails.application.config.secret_key_base, Time.now + DEFAULT_VALIDITY)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(user, key, expires_at)
|
def initialize(user, key, expires_at)
|
||||||
@user = user
|
@user = user
|
||||||
@key = key
|
@key = key
|
||||||
@expires_at = expires_at.utc.strftime("%F %T %Z")
|
@expires_at = expires_at.utc.strftime('%F %T %Z')
|
||||||
end
|
end
|
||||||
|
|
||||||
def hashable
|
def hashable
|
||||||
{
|
{
|
||||||
user_ident: user.registrant_ident,
|
user_ident: user.registrant_ident,
|
||||||
user_username: user.username,
|
user_username: user.username,
|
||||||
expires_at: expires_at
|
expires_at: expires_at,
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class AuthTokenCreator
|
||||||
{
|
{
|
||||||
access_token: encrypted_token,
|
access_token: encrypted_token,
|
||||||
expires_at: expires_at,
|
expires_at: expires_at,
|
||||||
type: 'Bearer'
|
type: 'Bearer',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ class AuthTokenDecryptor
|
||||||
attr_reader :user
|
attr_reader :user
|
||||||
|
|
||||||
def self.create_with_defaults(token)
|
def self.create_with_defaults(token)
|
||||||
self.new(token, Rails.application.config.secret_key_base)
|
new(token, Rails.application.config.secret_key_base)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(token, key)
|
def initialize(token, key)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue