Sha256: b046fcbd5dce80e45d58cb35fb5d4e4699ffabf22cb5043c96992f8957032521

Contents?: true

Size: 911 Bytes

Versions: 15

Compression:

Stored size: 911 Bytes

Contents

module PhcdevworksAccounts
  class User < ApplicationRecord
  
    # Autogenerate Organization ID
    before_create :phcdevworks_generate_org_id

    # User Gravatar Support
    include Gravtastic
    gravtastic

    # Add Users Roles
    enum role: [:user, :editor, :admin]
    after_initialize :phcdevworks_set_default_role

    # Include default devise modules. Others available are:
    # :trackable, :confirmable, :lockable and :omniauthable
    devise :database_authenticatable, :registerable, :recoverable, :rememberable,  :validatable, :timeoutable

    private

    # Autogenerate User Organization ID
    def phcdevworks_generate_org_id
      self.org_id = SecureRandom.hex(5)
    end

    # First Signup Admin and Rest Default to User
    def phcdevworks_set_default_role
      if User.all.count < 1
        self.role ||= :admin
      elsif
        self.role ||= :user
      end
    end
  
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
phcdevworks_accounts-1.2.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-1.1.2 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-1.1.1 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-1.1.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-1.0.1 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-1.0.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.9.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.8.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.7.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.6.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.5.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.4.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.3.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.2.0 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-0.1.0 app/models/phcdevworks_accounts/user.rb