This commit is contained in:
Tyrel Souza 2014-04-25 12:03:33 -04:00
parent 177f9e6982
commit e56cad5e3a
2 changed files with 26 additions and 19 deletions

View File

@ -18,27 +18,25 @@ class ApplicationController < ActionController::Base
private
def authenticate_user_from_token!
if request.headers["HTTP_AUTHORIZATION"]
authenticate_or_request_with_http_token do |token, options|
email = token.split[1].split("=")[1]
token = token.split[0]
user_email = email.presence
def authenticate_user_from_token!
if request.headers["HTTP_AUTHORIZATION"]
authenticate_or_request_with_http_token do |token, options|
email = token.split[1].split("=")[1]
token = token.split[0]
user_email = email.presence
end
else
user_email = params[:user_email].presence
token = params[:user_token]
end
else
user_email = params[:user_email].presence
token = params[:user_token]
log_it_in(token, user_email)
end
log_it_in(token, user_email)
end
def log_it_in(token, user_email)
user = user_email && User.find_by_email(user_email)
if user && Devise.secure_compare(user.authentication_token, token)
sign_in user, store: false
def log_it_in(token, user_email)
user = user_email && User.find_by_email(user_email)
if user && Devise.secure_compare(user.authentication_token, token)
sign_in user, store: false
end
end
end
end

View File

@ -0,0 +1,9 @@
require 'spec_helper'
describe ApplicationController do
it "can fail login" do
get "root#index"
end
end