API login/logout with http header token

This commit is contained in:
Min Zeya Phyo
2017-04-14 23:22:58 +06:30
parent db75780267
commit 5ca9615e38
11 changed files with 47 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
module TokenVerification
extend ActiveSupport::Concern
include ActionController::HttpAuthentication::Token::ControllerMethods
included do
before_action :authenticate
@@ -15,14 +16,9 @@ module TokenVerification
def authenticate_token
authenticate_with_http_token do |token, options|
#@current_user = User.find_by(api_key: token)
@device_access = DeviceAccess.find_by_token(token)
if @device_access
@log = DeviceAccessLog.new
@log.device_access = @device_access
@log.api_route = request.env['PATH_INFO']
@log.remote_ip = request.remote_ip
# @log.client_info =
@log.save
@user = Employee.authenticate_token(token)
if @user
#Maybe log - login?
end
end