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
8 9 10 11 |
# File 'lib/challah/techniques/password_technique.rb', line 8 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.
5 6 7 |
# File 'lib/challah/techniques/password_technique.rb', line 5 def user_model @user_model end |
Instance Method Details
#authenticate ⇒ Object
if we can successfully authenticate, return a User instance, otherwise nil
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/challah/techniques/password_technique.rb', line 14 def authenticate if username? and password? user = user_model.find_for_session(username) if user if user.valid_session? if user.authenticate(@password) return user end end user.failed_authentication! user = nil end end nil end |
#password? ⇒ Boolean
33 34 35 |
# File 'lib/challah/techniques/password_technique.rb', line 33 def password? !!@password end |
#persist? ⇒ Boolean
37 38 39 |
# File 'lib/challah/techniques/password_technique.rb', line 37 def persist? true end |
#username ⇒ Object
49 50 51 |
# File 'lib/challah/techniques/password_technique.rb', line 49 def username @username end |
#username? ⇒ Boolean
45 46 47 |
# File 'lib/challah/techniques/password_technique.rb', line 45 def username? !!@username end |