Class: Challah::PasswordProvider
- Inherits:
-
Object
- Object
- Challah::PasswordProvider
- Defined in:
- lib/challah/providers/password_provider.rb
Class Method Summary collapse
Class Method Details
.save(user) ⇒ Object
3 4 5 |
# File 'lib/challah/providers/password_provider.rb', line 3 def self.save(user) set(uid: user.username, token: user.password, user_id: user.id, authorization: user.class.) end |
.set(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/challah/providers/password_provider.rb', line 7 def self.set( = {}) user_id = .fetch(:user_id) uid = .fetch(:uid, '') token = .fetch(:token, '') auth_model = .fetch(:authorization, ::Authorization) if token.to_s.blank? = auth_model.get({ user_id: user_id, provider: :password }) if token = .token end else token = Challah::Encrypter.encrypt(token) end auth_model.set({ provider: :password, user_id: user_id, uid: uid, token: token }) end |
.valid?(record) ⇒ Boolean
34 35 36 37 38 |
# File 'lib/challah/providers/password_provider.rb', line 34 def self.valid?(record) password_validator = Challah.[:password_validator] password_validator.new(force: true).validate(record) record.errors[:password].size.zero? end |