Class: Blogaze::Models::User
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Blogaze::Models::User
- Defined in:
- lib/blogaze/models/user.rb
Overview
User model
Instance Method Summary collapse
- #before_create ⇒ Object
-
#change_password(new_password) ⇒ Object
Changes the users password.
-
#check_password(password) ⇒ Object
Check if the users password matches the supplied password.
-
#validate ⇒ Object
Validations.
Instance Method Details
#before_create ⇒ Object
59 60 61 62 |
# File 'lib/blogaze/models/user.rb', line 59 def before_create self.password = BCrypt::Password.create(self.password) self.group_id = 3 end |
#change_password(new_password) ⇒ Object
Changes the users password.
35 36 37 |
# File 'lib/blogaze/models/user.rb', line 35 def change_password(new_password) self.password = BCrypt::Password.create(new_password) end |
#check_password(password) ⇒ Object
Check if the users password matches the supplied password.
26 27 28 |
# File 'lib/blogaze/models/user.rb', line 26 def check_password(password) BCrypt::Password.new(self.password) == password end |
#validate ⇒ Object
Validations
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/blogaze/models/user.rb', line 42 def validate super # Username validates_unique :username validates_min_length 4, :username, :message => 'must be at least 4 characters' if new? validates_presence :username, :message => 'can\'t be empty' # Password validates_presence :password, :message => 'cant be blank' validates_min_length 6, :password, :message => 'must be at least 6 characters' # Email validates_unique :email validates_format /(.*)@(.*)\.(.*)/, :email, :message => 'is not a valid email' end |