From e56cad5e3aaf523e40db0d9b2aa5cf3cd9f0b66f Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 25 Apr 2014 12:03:33 -0400 Subject: [PATCH] testing --- app/controllers/application_controller.rb | 36 +++++++++---------- .../application_controller_spec.rb | 9 +++++ 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 spec/controllers/application_controller_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ac2e915..7301b60 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb new file mode 100644 index 0000000..2a9dc03 --- /dev/null +++ b/spec/controllers/application_controller_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe ApplicationController do + + it "can fail login" do + get "root#index" + end + +end \ No newline at end of file