Sha256: accacd9237775921190598b1c77e98d144eef216c867db8ab2f67649d1e4bd66

Contents?: true

Size: 989 Bytes

Versions: 5

Compression:

Stored size: 989 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

    # Validations
    validates :username, :presence => true, :uniqueness => true

    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

5 entries across 5 versions & 1 rubygems

Version Path
phcdevworks_accounts-3.2.4 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-3.2.3 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-3.2.2 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-3.2.1 app/models/phcdevworks_accounts/user.rb
phcdevworks_accounts-3.2.0 app/models/phcdevworks_accounts/user.rb