Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. # == Schema Information
  2. #
  3. # Table name: users
  4. #
  5. # *id*:: <tt>integer, not null, primary key</tt>
  6. # *email*:: <tt>string, default(""), not null</tt>
  7. # *encrypted_password*:: <tt>string, default(""), not null</tt>
  8. # *reset_password_token*:: <tt>string</tt>
  9. # *reset_password_sent_at*:: <tt>datetime</tt>
  10. # *remember_created_at*:: <tt>datetime</tt>
  11. # *sign_in_count*:: <tt>integer, default(0), not null</tt>
  12. # *current_sign_in_at*:: <tt>datetime</tt>
  13. # *last_sign_in_at*:: <tt>datetime</tt>
  14. # *current_sign_in_ip*:: <tt>inet</tt>
  15. # *last_sign_in_ip*:: <tt>inet</tt>
  16. # *created_at*:: <tt>datetime</tt>
  17. # *updated_at*:: <tt>datetime</tt>
  18. # *name*:: <tt>string</tt>
  19. # *confirmation_token*:: <tt>string</tt>
  20. # *confirmed_at*:: <tt>datetime</tt>
  21. # *confirmation_sent_at*:: <tt>datetime</tt>
  22. # *unconfirmed_email*:: <tt>string</tt>
  23. # *role*:: <tt>integer</tt>
  24. #
  25. # Indexes
  26. #
  27. # index_users_on_email (email) UNIQUE
  28. # index_users_on_reset_password_token (reset_password_token) UNIQUE
  29. #--
  30. # == Schema Information End
  31. #++
  32.  
  33. class User < ActiveRecord::Base
  34. include UserRoles
  35. has_many :sites
  36. has_many :accounts
  37. has_many :apis
  38. has_many :web_hooks, through: :sites
  39. has_many :packages, through: :sites
  40. has_many :promotions, through: :sites
  41. has_many :orders, through: :packages
  42. has_many :customers, through: :packages
  43. has_many :transactions, through: :orders
  44. has_many :assignments
  45. has_many :roles, through: :assignments
  46. has_many :access_sites, through: :assignments, source: :site
  47.  
  48.  
  49. def self.find_or_create_from_assignment(email, role, site)
  50. user = User.find_or_initialize_by(email: email)
  51. unless user.id
  52. password = Devise.friendly_token.first(10)
  53. user.password = user.password_confirmation = password
  54. user.save
  55. end
  56. UserMailer.invitation(user, role.to_s, site, password).deliver_later
  57. user
  58. end
  59.  
  60. def set_default_role
  61. self.role ||= :user
  62. end
  63.  
  64. def to_s
  65. email
  66. end
  67.  
  68. def ability
  69. @ability ||= Ability.new(self)
  70. end
  71.  
  72. # Include default devise modules. Others available are:
  73. # :confirmable, :lockable, :timeoutable and :omniauthable
  74. devise :database_authenticatable, :registerable, :confirmable,
  75. :recoverable, :rememberable, :trackable, :validatable
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement