-
-
Save sahidursuman/cea9fe634844de8a92035b1b740775a4 to your computer and use it in GitHub Desktop.
before_filter that checks for a login token and logs the user in if it's valid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maybe_login_from_token | |
Rails.logger.info "maybe_login_from_token: '#{ params[:token] }'" | |
return if (token = params[:token]).blank? | |
if (user = User.find_by_token(token)) | |
Rails.logger.info "One time login token used for user #{ user.id }" | |
sign_in(user) | |
else | |
Rails.logger.info "No user found from token: '#{ token }'" | |
end | |
# strip token regardless of success | |
redirect_to request.path, | |
params.except(:token, :action, :controller) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment