basic layout template

This commit is contained in:
Min Zeya Phyo
2017-04-05 08:24:21 +06:30
parent bcdce092cc
commit 0ddc7bdb44
66 changed files with 7049 additions and 48 deletions

View File

@@ -0,0 +1,36 @@
module TokenVerification
extend ActiveSupport::Concern
included do
before_action :authenticate
end
protected
# Authenticate the user with token based authentication
def authenticate
authenticate_token || render_unauthorized
end
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
end
end
end
def render_unauthorized(realm = "Application")
self.headers["WWW-Authenticate"] = %(Token realm="#{realm.gsub(/"/, "")}")
render json: 'Bad credentials', status: :unauthorized
end
end