Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Utilisateur < ActiveRecord::Base
- # NAME VALIDATION
- name_regex = /\A[a-zA-Z-.\s]{2,}\z/i
- validates :prenom, :presence => true
- validates_format_of :prenom, :with => name_regex
- validates :nom, :presence => true
- validates_format_of :nom, :with => name_regex
- # DATE OF BIRTH VALIDATION
- validates :date_nsc, :presence => true
- # ADDRESS VALIDATION
- validates :adresse, :presence => true
- # PHONE VALIDATION
- phone_regex = /\d{10}/ # This is not perfect.
- validates :tel, :presence => true
- validates_format_of :tel, :with => phone_regex
- # E-MAIL VALIDATION
- email_regex = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
- validates :mail, :presence => true,
- :uniqueness => {:case_sensitive => false}
- validates_format_of :mail, :with => email_regex,
- :message => "is invalid"
- # PASSWORD VALIDATION
- validates :mdp, :presence => true
- class << self
- def authenticate(email, submitted_password)
- user = Utilisateur.find_by_mail(email)
- (user && user.mdp = submitted_password) ? user : nil
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement