Guest User

Untitled

a guest
Mar 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. class User
  2. include DataMapper::Resource
  3. include DataMapper::Validate
  4.  
  5. SchoolStatus = Enum[:prospective,:undergrad,:graduate,:faculty,:alumni,:none]
  6.  
  7. property :id, Integer, :serial => true
  8.  
  9. property :username, String, :nullable => false, :unique_index => true, :unique => true
  10. property :password, String, :nullable => false
  11. property :first_name, String, :nullable => false
  12. property :last_name, String, :nullable => false
  13. property :primary_email, String, :nullable => false, :unique => true, :unique_index => true
  14.  
  15. property :class_year, String, :length => 4, :format => /^(\d{4})?$/
  16. property :school_status, SchoolStatus
  17. property :field_of_study, String
  18. property :residence, String
  19.  
  20.  
  21. has n, :email_accounts
  22. has n, :user_networks
  23.  
  24. has n, :networks, :through => :user_networks, :class_name => 'Network'
  25.  
  26. attr_accessor :email
  27. attr_accessor :network
  28.  
  29. validates_present :email
  30. validates_present :network
  31. validates_length :password, :min => 6
  32. validates_length :username, :min => 1
  33.  
  34. before :save, :transfer_properties
  35.  
  36. def transfer_properties
  37. puts "in transfer properties"
  38. self.primary_email = self.email
  39. self.email_accounts << EmailAccount.new( :confirmed => false, :email => self.email )
  40. self.user_networks << UserNetwork.new( :network => Network.first( :network_type.eql => :site ) )
  41. self.user_networks << UserNetwork.new( :network => Network.get(self.network) )
  42. end
  43.  
  44. end
Add Comment
Please, Sign In to add comment