Commit 54843309 authored by hellekin's avatar hellekin

Fix authentication check

parent 14626e7e
......@@ -46,6 +46,10 @@ module INCOMMON
end
alias is_incommon? current_agent_is_incommon?
def my_username?(username)
authenticated? && user.username == username
end
# Only provide access to Agent users to the leaders, whose role is to manage
# them. Other Agent roles will see an empty array.
def users
......
......@@ -35,9 +35,22 @@ class User < ApplicationRecord
def initialize(*attributes)
super
@authenticated = false
@restricted = false
end
# Override authenticate method to allow authorization policies for checking
# whether the user has authenticated already or not.
def authenticate(password)
user = super(password)
@authenticated = user.present?
user.presence
end
def authenticated?
@authenticated == true
end
def restrict!
Rails.logger.info "Called restrict! on #{username}"
@restricted = true
......
......@@ -16,10 +16,9 @@ class SerializableAgent < SerializableIncommonResource
attribute :summary
attribute :description
attribute :visible
# attribute :translations
attribute :type
# attribute :uuid
attribute :uuid
attribute :visible
attribute :created_at
attribute :updated_at
......
Fabricator(:user) do
username "MyString"
password ""
auth_token "MyString"
nonce "MyString"
api_token "MyString"
username "some_encrypted_string"
password "some_encrypted_string"
auth_token "a_secure_token"
nonce "a_secure_token"
api_token { SecureRandom.uuid }
end
# == Schema Information
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment