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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

validates presence

A

validates :users, :password_digest, session_token, presence: true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

validates length

A

validates :password length: {minimum: 6, allow_nil: true}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

validates uniqueness

A

validates :username, :session_token, uniqueness: true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

attr_reader

A

attr_reader :password

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

def after_initialization/before_validation

A

before_validation :ensure_session_token

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

def password=(password) (REMEMBER IT CREATES)

A
self.password_digest = BCrypt::Password.create(password)
@password = password
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

def ensure_session_token

A

private

def ensure_session_token
self.session_token ||= SecureRandom.base64(64)
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

def reset_session_token!

A

def reset_session_token!

self. sesison_token = SecureRandom.base64(64)
self. save!
self. session_token

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

def self.generate_session_token

A

SecureRandom::base60(64)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly