Sha256: 9d38c50b2bfc306c381fb4bebb17eb8a6e9623af262131de628a68fde4c173a1

Contents?: true

Size: 647 Bytes

Versions: 16

Compression:

Stored size: 647 Bytes

Contents

module Spina
  class User < ApplicationRecord
    has_secure_password
    has_secure_token :password_reset_token

    validates_presence_of :name, :email
    validates_presence_of :password, on: :create
    validate :uniqueness_of_email
    validates :email, format: { with:/\A[^@]+@[^@]+\z/ }

    def admin?
      admin
    end

    def to_s
      name
    end

    def update_last_logged_in!
      self.last_logged_in = Time.now
      self.save!
    end

    private

    def uniqueness_of_email
      if email_changed? && User.where(email: email).exists?
        errors.add(:email, I18n.t('errors.messages.taken'))
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
spina-2.0.2 app/models/spina/user.rb
spina-2.0.1 app/models/spina/user.rb
spina-2.0.0 app/models/spina/user.rb
spina-2.0.0.beta app/models/spina/user.rb
spina-2.0.0.alpha app/models/spina/user.rb
spina-1.2.0 app/models/spina/user.rb
spina-1.1.4 app/models/spina/user.rb
spina-1.1.3 app/models/spina/user.rb
spina-1.1.2 app/models/spina/user.rb
spina-1.1.1 app/models/spina/user.rb
spina-1.1.0 app/models/spina/user.rb
spina-1.0.3 app/models/spina/user.rb
spina-1.0.2 app/models/spina/user.rb
spina-1.0.1 app/models/spina/user.rb
spina-1.0.0 app/models/spina/user.rb
spina-0.12.0 app/models/spina/user.rb