BigW Consortium Gitlab

Commit 051324e1 by Timothy Andrew

Refactor `authenticate_user_from_private_token!`

- No need to use `if`s when we have a `presence` check already.
parent ade40fdc
...@@ -67,13 +67,7 @@ class ApplicationController < ActionController::Base ...@@ -67,13 +67,7 @@ class ApplicationController < ActionController::Base
# From https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example # From https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example
# https://gist.github.com/josevalim/fb706b1e933ef01e4fb6 # https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
def authenticate_user_from_private_token! def authenticate_user_from_private_token!
user_token = if params[:authenticity_token].presence user_token = params[:authenticity_token].presence || params[:private_token].presence || request.headers['PRIVATE-TOKEN'].presence
params[:authenticity_token].presence
elsif params[:private_token].presence
params[:private_token].presence
elsif request.headers['PRIVATE-TOKEN'].present?
request.headers['PRIVATE-TOKEN']
end
user = user_token && User.find_by_authentication_token(user_token.to_s) user = user_token && User.find_by_authentication_token(user_token.to_s)
if user if user
......
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