Sha256: 07033e6a3cd57347d4834a4eb541945d3d8db01898d1d36211b62dbbe875c07b

Contents?: true

Size: 751 Bytes

Versions: 3

Compression:

Stored size: 751 Bytes

Contents

module Oxen
  class Account
    include Mongoid::Document
    include Mongoid::Timestamps
    include ::Plug::Mixin
    array_attr :tags
    attr_accessor :password
    field :login, type: String
    field :tags, type: Array
    field :hashed_password, type: String
    field :avatar, type: Hash

    default_scope -> {where(:login.ne => "root")}

    attr_readonly :login

    validates :login, :password, presence: true
    validates :login, uniqueness: true
    validates :password, confirmation: true
    validates :password, length: { minimum: 6 , message: "密码太短"}
    before_save :hashit

    after_destroy :remove_avatar

    private

    def hashit
      self.hashed_password = Digest::SHA2.hexdigest(self.password)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oxen-0.0.3 app/models/oxen/account.rb
oxen-0.0.2 app/models/oxen/account.rb
oxen-0.0.1 app/models/oxen/account.rb