mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Merge pull request #184 from mattr-/cucumber-login-backdoor
Move the expire_session route
This commit is contained in:
commit
9c56416dcb
3 changed files with 9 additions and 24 deletions
|
|
@ -47,29 +47,6 @@ class LoginController < ApplicationController
|
|||
logout_user
|
||||
end
|
||||
|
||||
def expire_session
|
||||
# this is a hack to enable cucumber to expire a session by calling this
|
||||
# method. The method will be unavailable for production environment
|
||||
|
||||
@user.forget_me if logged_in?
|
||||
cookies.delete :auth_token
|
||||
session['user_id'] = nil
|
||||
reset_session
|
||||
|
||||
unless Rails.env.production?
|
||||
session['expiry_time'] = Time.now
|
||||
respond_to do |format|
|
||||
format.html { render :text => "Session expired for test purposes"}
|
||||
format.js { render :text => "" }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :text => "Not available for production use"}
|
||||
format.js { render :text => "" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_expiry
|
||||
# Gets called by periodically_call_remote to check whether
|
||||
# the session has timed out yet
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ Tracksapp::Application.routes.draw do
|
|||
root :to => 'todos#index'
|
||||
|
||||
match 'login' => 'login#login'
|
||||
match 'login/expire_session' => 'login#expire_session'
|
||||
match 'login/check_expiry' => 'login#check_expiry'
|
||||
match 'logout' => 'login#logout'
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,14 @@ class SessionBackdoorController < ::ApplicationController
|
|||
cookies[:auth_token] = { :value => user.remember_token, :expires => user.remember_token_expires_at }
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
def expire_session
|
||||
current_user.forget_me if logged_in?
|
||||
cookies.delete :auth_token
|
||||
session['user_id'] = nil
|
||||
reset_session
|
||||
session['expiry_time'] = Time.now
|
||||
end
|
||||
end
|
||||
|
||||
module TracksLoginHelper
|
||||
|
|
@ -20,6 +28,7 @@ module TracksLoginHelper
|
|||
_routes.draw do
|
||||
# here you can add any route you want
|
||||
match "/test_login_backdoor", to: "session_backdoor#create"
|
||||
match "login/expire_session", to: "session_backdoor#expire_session"
|
||||
end
|
||||
ActiveSupport.on_load(:action_controller) { _routes.finalize! }
|
||||
ensure
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue