FIGVVVAAPER Flashcards
1
Q
def self.find_by_credentials
A
def self.find_by_credentials(username, password) user = User.find_by(username: username) return nil if user.nil? user.is_password?(password) ? user : nil end
2
Q
validates presence
A
validates :users, :password_digest, session_token, presence: true
3
Q
validates length
A
validates :password length: {minimum: 6, allow_nil: true}
4
Q
validates uniqueness
A
validates :username, :session_token, uniqueness: true
5
Q
attr_reader
A
attr_reader :password
6
Q
def after_initialization/before_validation
A
before_validation :ensure_session_token
7
Q
def password=(password) (REMEMBER IT CREATES)
A
self.password_digest = BCrypt::Password.create(password) @password = password
8
Q
def ensure_session_token
A
private
def ensure_session_token self.session_token ||= SecureRandom.base64(64) end
9
Q
def reset_session_token!
A
def reset_session_token!
self. sesison_token = SecureRandom.base64(64)
self. save!
self. session_token
10
Q
def self.generate_session_token
A
SecureRandom::base60(64)