Class: Challah::PasswordTechnique
- Inherits:
-
Object
- Object
- Challah::PasswordTechnique
- Defined in:
- lib/challah/techniques/password_technique.rb
Overview
Allows authentication by username and password.
Instance Attribute Summary collapse
-
#user_model ⇒ Object
Returns the value of attribute user_model.
Instance Method Summary collapse
-
#authenticate ⇒ Object
if we can successfully authenticate, return a User instance, otherwise nil.
-
#initialize(session) ⇒ PasswordTechnique
constructor
grab the params we want from this request.
- #password? ⇒ Boolean
- #persist? ⇒ Boolean
- #username ⇒ Object
- #username? ⇒ Boolean
Constructor Details
#initialize(session) ⇒ PasswordTechnique
grab the params we want from this request
9 10 11 12 |
# File 'lib/challah/techniques/password_technique.rb', line 9 def initialize(session) @username = session.username? ? session.username : nil @password = session.password? ? session.password : nil end |
Instance Attribute Details
#user_model ⇒ Object
Returns the value of attribute user_model.
6 7 8 |
# File 'lib/challah/techniques/password_technique.rb', line 6 def user_model @user_model end |
Instance Method Details
#authenticate ⇒ Object
if we can successfully authenticate, return a User instance, otherwise nil
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/challah/techniques/password_technique.rb', line 15 def authenticate if username? and password? user = user_model.find_for_session(username) if user if user.active? if user.authenticate(@password) return user end end user.failed_authentication! user = nil end end nil end |
#password? ⇒ Boolean
34 35 36 |
# File 'lib/challah/techniques/password_technique.rb', line 34 def password? !!@password end |
#persist? ⇒ Boolean
38 39 40 |
# File 'lib/challah/techniques/password_technique.rb', line 38 def persist? true end |
#username ⇒ Object
50 51 52 |
# File 'lib/challah/techniques/password_technique.rb', line 50 def username @username end |
#username? ⇒ Boolean
46 47 48 |
# File 'lib/challah/techniques/password_technique.rb', line 46 def username? !!@username end |