Sha256: d8d44e9213d638539da67b6401246929e2d48cb553513cc3afb5b63255f73458
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true require 'proxes/models/base' require 'digest/md5' require 'active_support' require 'active_support/core_ext/object/blank' # Why not store this in Elasticsearch? module ProxES class User < Sequel::Model include ::ProxES::Base one_to_many :identity many_to_many :roles one_to_many :permissions one_to_many :audit_logs def role?(check) !roles_dataset.first(name: check).nil? end def method_missing(method_sym, *arguments, &block) if method_sym.to_s[-1] == '?' role?(method_sym[0..-2]) else super end end def respond_to_missing?(name, _include_private = false) name[-1] == '?' end def gravatar hash = Digest::MD5.hexdigest(email.downcase) "https://www.gravatar.com/avatar/#{hash}" end def validate validates_presence :email return if email.blank? validates_unique :email validates_format(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :email) end # Add the basic roles and identity def after_create check_roles end def check_roles return if role?('anonymous') add_role Role.find_or_create(name: 'user') unless role?('user') end def index_prefix email end def username identity_dataset.first.username end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
proxes-0.7.1 | lib/proxes/models/user.rb |
proxes-0.7.0 | lib/proxes/models/user.rb |