mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Change Base64 encoding to be url_safe, add crude implementation of a Controller
This commit is contained in:
parent
dc8230dcc2
commit
35c3f0a5bf
6 changed files with 50 additions and 7 deletions
41
app/controllers/api/v1/registrant/domains_controller.rb
Normal file
41
app/controllers/api/v1/registrant/domains_controller.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require 'rails5_api_controller_backport'
|
||||
require 'auth_token/auth_token_decryptor'
|
||||
|
||||
module Api
|
||||
module V1
|
||||
module Registrant
|
||||
class DomainsController < ActionController::API
|
||||
before_filter :authenticate
|
||||
|
||||
def index
|
||||
registrant = ::Registrant.find_by(ident: current_user.registrant_ident)
|
||||
unless registrant
|
||||
render json: Domain.all
|
||||
else
|
||||
domains = Domain.where(registrant_id: registrant.id)
|
||||
render json: domains
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def bearer_token
|
||||
pattern = /^Bearer /
|
||||
header = request.headers['Authorization']
|
||||
header.gsub(pattern, '') if header && header.match(pattern)
|
||||
end
|
||||
|
||||
def authenticate
|
||||
decryptor = AuthTokenDecryptor.create_with_defaults(bearer_token)
|
||||
decryptor.decrypt_token
|
||||
|
||||
if decryptor.valid?
|
||||
sign_in decryptor.user
|
||||
else
|
||||
render json: { error: "Not authorized" }, status: 403
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue