Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # == Schema Information
- #
- # Table name: users
- #
- # *id*:: <tt>integer, not null, primary key</tt>
- # *email*:: <tt>string, default(""), not null</tt>
- # *encrypted_password*:: <tt>string, default(""), not null</tt>
- # *reset_password_token*:: <tt>string</tt>
- # *reset_password_sent_at*:: <tt>datetime</tt>
- # *remember_created_at*:: <tt>datetime</tt>
- # *sign_in_count*:: <tt>integer, default(0), not null</tt>
- # *current_sign_in_at*:: <tt>datetime</tt>
- # *last_sign_in_at*:: <tt>datetime</tt>
- # *current_sign_in_ip*:: <tt>inet</tt>
- # *last_sign_in_ip*:: <tt>inet</tt>
- # *created_at*:: <tt>datetime</tt>
- # *updated_at*:: <tt>datetime</tt>
- # *name*:: <tt>string</tt>
- # *confirmation_token*:: <tt>string</tt>
- # *confirmed_at*:: <tt>datetime</tt>
- # *confirmation_sent_at*:: <tt>datetime</tt>
- # *unconfirmed_email*:: <tt>string</tt>
- # *role*:: <tt>integer</tt>
- #
- # Indexes
- #
- # index_users_on_email (email) UNIQUE
- # index_users_on_reset_password_token (reset_password_token) UNIQUE
- #--
- # == Schema Information End
- #++
- class User < ActiveRecord::Base
- include UserRoles
- has_many :sites
- has_many :accounts
- has_many :apis
- has_many :web_hooks, through: :sites
- has_many :packages, through: :sites
- has_many :promotions, through: :sites
- has_many :orders, through: :packages
- has_many :customers, through: :packages
- has_many :transactions, through: :orders
- has_many :assignments
- has_many :roles, through: :assignments
- has_many :access_sites, through: :assignments, source: :site
- def self.find_or_create_from_assignment(email, role, site)
- user = User.find_or_initialize_by(email: email)
- unless user.id
- password = Devise.friendly_token.first(10)
- user.password = user.password_confirmation = password
- user.save
- end
- UserMailer.invitation(user, role.to_s, site, password).deliver_later
- user
- end
- def set_default_role
- self.role ||= :user
- end
- def to_s
- email
- end
- def ability
- @ability ||= Ability.new(self)
- end
- # Include default devise modules. Others available are:
- # :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable, :registerable, :confirmable,
- :recoverable, :rememberable, :trackable, :validatable
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement