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
14 15 16 |
# File 'lib/proxes/helpers/authentication.rb', line 14 def authenticate authenticated? end |
#authenticate! ⇒ Object
22 23 24 25 |
# File 'lib/proxes/helpers/authentication.rb', line 22 def authenticate! raise NotAuthenticated unless env['rack.session']['user_id'] true end |
#authenticated? ⇒ Boolean
18 19 20 |
# File 'lib/proxes/helpers/authentication.rb', line 18 def authenticated? !env['rack.session']['user_id'].nil? end |
#check_basic ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/proxes/helpers/authentication.rb', line 31 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 |
# File 'lib/proxes/helpers/authentication.rb', line 5 def current_user return nil unless env['rack.session'] && env['rack.session']['user_id'] @user ||= User[env['rack.session']['user_id']] end |
#current_user=(user) ⇒ Object
10 11 12 |
# File 'lib/proxes/helpers/authentication.rb', line 10 def current_user=(user) env['rack.session']['user_id'] = user.id end |
#logout ⇒ Object
27 28 29 |
# File 'lib/proxes/helpers/authentication.rb', line 27 def logout env['rack.session'].delete('user_id') end |