Sha256: db666bc02cad2a4c82c539735eac2a4178d6a56a1c04f8f18469e491bd29e52c

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

# User 是系统用户。

class Unidom::Visitor::User < ActiveRecord::Base

  self.table_name = 'unidom_users'

  has_many :identificatings, class_name: 'Unidom::Visitor::Identificating', as: :visitor

  has_many :authenticatings, class_name: 'Unidom::Visitor::Authenticating', as: :visitor
  has_many :passwords,       through:    :authenticatings, source: :credential, source_type: 'Unidom::Visitor::Password'

  has_many :recognizations,  class_name: 'Unidom::Visitor::Recognization',  as: :visitor

  scope :identified_by, ->(identity) { joins(:identificatings).merge(::Unidom::Visitor::Identificating.identity_is identity) }

  include Unidom::Common::Concerns::ModelExtension

  def self.sign_up(identity, password)

    return false if identified_by(identity).valid_at.alive.merge(::Identificating.valid_at.alive).count>0

    now        = Time.now
    user       = self.create! opened_at: now
    credential = ::Unidom::Visitor::Password.create! clear_text: password, opened_at: now

    identificating = ::Unidom::Visitor::Identificating.identificate user, identity
    authenticating = ::Unidom::Visitor::Authenticating.authenticate user, credential

    user

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unidom-visitor-0.1.1 app/models/unidom/visitor/user.rb