Sha256: 022935e31a37200c8c247c66e8070fd9a6796435cb1f51c81fcba0ed16365de6

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 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: nil, opened_at: Time.now)

    Rails.logger.debug "Signing up user with identity: #{identity.inspect}."
    return false if identified_by(identity).valid_at.alive.merge(Unidom::Visitor::Identificating.valid_at.alive).count>0

    user           = create! opened_at: opened_at
    identificating = Unidom::Visitor::Identificating.identificate user, identity

    Rails.logger.debug "Authenticate user #{user.id} with password: #{password.inspect}."
    if password.present?
      credential     = Unidom::Visitor::Password.create! clear_text: password, opened_at: opened_at
      authenticating = Unidom::Visitor::Authenticating.authenticate user, credential
    end

    user

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unidom-visitor-0.8.1 app/models/unidom/visitor/user.rb
unidom-visitor-0.8 app/models/unidom/visitor/user.rb
unidom-visitor-0.7 app/models/unidom/visitor/user.rb
unidom-visitor-0.6 app/models/unidom/visitor/user.rb