| Module | UsrSystem |
| In: |
lib/usr_system.rb
|
overwrite if you want to have special behavior in case the usr is not authorized to access the current operation. the default action is to redirect to the login screen example use : a popup window might just close itself for instance
# File lib/usr_system.rb, line 21
21: def access_denied
22: redirect_to :controller => "/usr", :action => "login"
23: end
authenticate_usr filter. add
before_filter :authenticate_usr
# File lib/usr_system.rb, line 9
9: def authenticate_usr
10: return true if authenticated_usr?
11: session[:return_to] = request.request_uri
12: access_denied
13: return false
14: end
# File lib/usr_system.rb, line 34
34: def authenticated_usr?
35: if session[:usr_id]
36: @current_usr = Usr.find_by_id(session[:usr_id])
37: return false if @current_usr.nil?
38: return true
39: end
40:
41: # If not, is the usr being authenticated by a token (created by signup/forgot password actions)?
42: return false if not params['usr']
43: id = params['usr']['id']
44: key = params['key']
45: if id and key
46: @current_usr = Usr.authenticate_by_token(id, key)
47: session[:usr_id] = @current_usr ? @current_usr.id : nil
48: return true if not @current_usr.nil?
49: end
50:
51: # Everything failed
52: return false
53: end