mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
upto 3.12: added password + validation
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
class User < ApplicationRecord
|
||||
include RatingAverage
|
||||
|
||||
has_secure_password
|
||||
|
||||
validates :username, uniqueness: true, length: { minimum: 3, maximum: 30 }
|
||||
validates :password, length: { minimum: 3 }
|
||||
validate :has_proper_characters_in_password
|
||||
|
||||
has_many :ratings
|
||||
has_many :beers, through: :ratings
|
||||
has_many :memberships, dependent: :destroy
|
||||
has_many :beer_clubs, through: :memberships
|
||||
|
||||
def has_proper_characters_in_password
|
||||
regex = "(?=.*[[:upper:]])(?=.*[0-9])"
|
||||
if not password.match(regex)
|
||||
errors.add :password, "doesn't contain uppercase letter and a number"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user