Sha256: d6de497aa050c4235fca9ae7ea2783892c2baf0eda38433e2b73a0dfd66c2e89

Contents?: true

Size: 1.34 KB

Versions: 13

Compression:

Stored size: 1.34 KB

Contents

##
# User 是系统用户。

class Unidom::Visitor::User < Unidom::Visitor::ApplicationRecord

  self.table_name = 'unidom_users'

  include Unidom::Common::Concerns::ModelExtension
  include Unidom::Visitor::Concerns::AsVisitor

  has_many :passwords, through: :authenticatings, source: :credential, source_type: 'Unidom::Visitor::Password'

  ##
  # 注册用户。用户的登录账号是 identity ,密码是 password ,注册时间是 opened_at ,缺省为当前时间。如:
  # Unidom::Visitor::User.sign_up email, password: 'yourpassword'
  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, as: 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, with: credential
    end

    user

  end

end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Visitor::User'

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
unidom-visitor-2.0 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.10 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.9 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.8 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.7 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.6 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.5 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.4 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.3 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.2 app/models/unidom/visitor/user.rb
unidom-visitor-1.13.1 app/models/unidom/visitor/user.rb
unidom-visitor-1.13 app/models/unidom/visitor/user.rb
unidom-visitor-1.12.4 app/models/unidom/visitor/user.rb