diff options
Diffstat (limited to 'lib/authenticated_system.rb')
| -rw-r--r-- | lib/authenticated_system.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb index 7accfaaa..2ec15a77 100644 --- a/lib/authenticated_system.rb +++ b/lib/authenticated_system.rb | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | module AuthenticatedSystem | 1 | module AuthenticatedSystem |
| 2 | SESSION_MAX_AGE = 7.days | ||
| 3 | |||
| 2 | protected | 4 | protected |
| 3 | # Returns true or false if the user is logged in. | 5 | # Returns true or false if the user is logged in. |
| 4 | # Preloads @current_user with the user model if they're logged in. | 6 | # Preloads @current_user with the user model if they're logged in. |
| @@ -98,7 +100,12 @@ module AuthenticatedSystem | |||
| 98 | 100 | ||
| 99 | # Called from #current_user. First attempt to login by the user id stored in the session. | 101 | # Called from #current_user. First attempt to login by the user id stored in the session. |
| 100 | def login_from_session | 102 | def login_from_session |
| 101 | self.current_user = User.find_by_id(session[:user_id]) if session[:user_id] | 103 | return unless session[:user_id] |
| 104 | if session[:logged_in_at].to_i > SESSION_MAX_AGE.ago.to_i | ||
| 105 | self.current_user = User.find_by(:id => session[:user_id]) | ||
| 106 | else | ||
| 107 | session[:user_id] = nil | ||
| 108 | end | ||
| 102 | end | 109 | end |
| 103 | 110 | ||
| 104 | # | 111 | # |
