Module: ProxES::Helpers::Authentication
- Included in:
- Security
- Defined in:
- lib/proxes/helpers/authentication.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #check_basic ⇒ Object
- #current_user ⇒ Object
- #current_user=(user) ⇒ Object
- #logout ⇒ Object
Instance Method Details
#authenticate ⇒ Object
15 16 17 |
# File 'lib/proxes/helpers/authentication.rb', line 15 def authenticate authenticated? end |
#authenticate! ⇒ Object
23 24 25 26 |
# File 'lib/proxes/helpers/authentication.rb', line 23 def authenticate! raise NotAuthenticated unless env['rack.session']['user_id'] true end |
#authenticated? ⇒ Boolean
19 20 21 |
# File 'lib/proxes/helpers/authentication.rb', line 19 def authenticated? !env['rack.session']['user_id'].nil? end |
#check_basic ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/proxes/helpers/authentication.rb', line 32 def check_basic auth = Rack::Auth::Basic::Request.new(env) return unless auth.provided? return unless auth.basic? identity = ProxES::Identity.find(username: auth.credentials[0]) raise NotAuthenticated unless identity self.current_user = identity.user if identity.authenticate(auth.credentials[1]) end |
#current_user ⇒ Object
5 6 7 8 9 |
# File 'lib/proxes/helpers/authentication.rb', line 5 def current_user return nil unless env['rack.session'] && env['rack.session']['user_id'] @users ||= Hash.new {|h,k| h[k] = User[k]} @users[env['rack.session']['user_id']] end |
#current_user=(user) ⇒ Object
11 12 13 |
# File 'lib/proxes/helpers/authentication.rb', line 11 def current_user=(user) env['rack.session']['user_id'] = user.id end |
#logout ⇒ Object
28 29 30 |
# File 'lib/proxes/helpers/authentication.rb', line 28 def logout env['rack.session'].delete('user_id') end |