Commit 93f9d3ad by liyijie

Refector authable auth method

parent 85eb1bd7
...@@ -53,7 +53,8 @@ module RailsApiAuthentication ...@@ -53,7 +53,8 @@ module RailsApiAuthentication
end end
def auth!(request) def auth!(request)
user = auth(request) token = request.env["HTTP_#{self.to_s.upcase}_TOKEN"] || request.env["#{self.to_s.upcase}_TOKEN"]
user = auth(token)
user.nil? ? raise(UserError.new(401, '-1', 'Unauthorized')) : user user.nil? ? raise(UserError.new(401, '-1', 'Unauthorized')) : user
end end
...@@ -94,8 +95,7 @@ module RailsApiAuthentication ...@@ -94,8 +95,7 @@ module RailsApiAuthentication
( valid_code.present? && valid_code == $redis.get("#{self}::#{name}") ) ( valid_code.present? && valid_code == $redis.get("#{self}::#{name}") )
end end
def auth(request) def auth(token)
token = request.env["HTTP_#{self.to_s.upcase}_TOKEN"] || request.env["#{self.to_s.upcase}_TOKEN"]
auth = AuthToken.find(token: token)&.first auth = AuthToken.find(token: token)&.first
if auth.nil? if auth.nil?
nil nil
......
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