Sha256: cc61a191741e6b3d6e279e99077fef4d8b3b775a0f5d4f957436efc364b8a183

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

module Exposition
  module Concerns
    module Models
      module User
        extend ActiveSupport::Concern
        VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i

        included do
          attr_accessor :remember_token

          validates_presence_of :name, :email
          validates_length_of :name, maximum: 50
          validates_length_of :email, maximum: 244
          validates_length_of :password, minimum: 6
          validates_uniqueness_of :email, case_sensitive: false
          validates_format_of :email, with: VALID_EMAIL_REGEX

          has_secure_password
        end

        class_methods do
        end

        # Returns true if the given token matches the digest.
        def authenticated?(remember_token)
          BCrypt::Password.new(remember_digest).is_password?(remember_token)
        end

        # Remembers a user in the database for use in persistent sessions.
        def set_encrypted_remember_token!
          self.remember_token = generate_new_token
          update_attribute(:remember_digest, Encryptor.encrypt(remember_token))
        end

        private

        def generate_new_token
          SecureRandom.urlsafe_base64
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
exposition-0.0.5.7.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.5.6.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.5.5.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.5.4.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.5.2.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.5.1.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.5.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.4.pre.alpha lib/exposition/concerns/models/user.rb
exposition-0.0.3.pre.alpha lib/exposition/concerns/models/user.rb