Module: AppRail::Airtable::Authenticatable::ClassMethods
- Defined in:
- lib/app_rail/airtable/authenticatable.rb
Instance Method Summary collapse
- #create(email:, password:) ⇒ Object
- #find_by_access_token(access_token) ⇒ Object
- #find_by_email(email) ⇒ Object
- #find_by_email_and_password(email, password) ⇒ Object
- #next_access_token ⇒ Object
- #password_hash(password) ⇒ Object
Instance Method Details
#create(email:, password:) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/app_rail/airtable/authenticatable.rb', line 19 def create(email:, password:) raise AlreadyExistsError if find_by_email(email) user = new('Email' => email, 'Password Hash' => password_hash(password), 'Access Token' => next_access_token) user.create user end |
#find_by_access_token(access_token) ⇒ Object
36 37 38 |
# File 'lib/app_rail/airtable/authenticatable.rb', line 36 def find_by_access_token(access_token) all(filter: "{Access Token} = \"#{access_token}\"").first end |
#find_by_email(email) ⇒ Object
32 33 34 |
# File 'lib/app_rail/airtable/authenticatable.rb', line 32 def find_by_email(email) all(filter: "{Email} = \"#{email}\"").first end |
#find_by_email_and_password(email, password) ⇒ Object
27 28 29 30 |
# File 'lib/app_rail/airtable/authenticatable.rb', line 27 def find_by_email_and_password(email, password) user = find_by_email(email) user&.valid_password?(password) ? user : nil end |
#next_access_token ⇒ Object
44 45 46 |
# File 'lib/app_rail/airtable/authenticatable.rb', line 44 def next_access_token SecureRandom.hex end |
#password_hash(password) ⇒ Object
40 41 42 |
# File 'lib/app_rail/airtable/authenticatable.rb', line 40 def password_hash(password) BCrypt::Password.create(password) end |