Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. class Utilisateur < ActiveRecord::Base
  2.  
  3. # NAME VALIDATION
  4. name_regex = /\A[a-zA-Z-.\s]{2,}\z/i
  5. validates :prenom, :presence => true
  6. validates_format_of :prenom, :with => name_regex
  7. validates :nom, :presence => true
  8. validates_format_of :nom, :with => name_regex
  9.  
  10. # DATE OF BIRTH VALIDATION
  11. validates :date_nsc, :presence => true
  12.  
  13. # ADDRESS VALIDATION
  14. validates :adresse, :presence => true
  15.  
  16. # PHONE VALIDATION
  17. phone_regex = /\d{10}/ # This is not perfect.
  18. validates :tel, :presence => true
  19. validates_format_of :tel, :with => phone_regex
  20.  
  21. # E-MAIL VALIDATION
  22. email_regex = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
  23. validates :mail, :presence => true,
  24. :uniqueness => {:case_sensitive => false}
  25. validates_format_of :mail, :with => email_regex,
  26. :message => "is invalid"
  27.  
  28. # PASSWORD VALIDATION
  29. validates :mdp, :presence => true
  30.  
  31. class << self
  32. def authenticate(email, submitted_password)
  33. user = Utilisateur.find_by_mail(email)
  34. (user && user.mdp = submitted_password) ? user : nil
  35. end
  36. end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement