Sha256: f2a6d4ae1c92ae862c079b7df3a5fcde5fcaf9781acd659ce59a43217766c40d

Contents?: true

Size: 677 Bytes

Versions: 25

Compression:

Stored size: 677 Bytes

Contents

require 'bcrypt'

class User < ActiveRecord::Base
  include BCrypt

  attr_accessor :password_confirmation

  validates_presence_of :email

  validate do |record|
    record.errors.add(:password, :blank) unless record.encrypted_password.present?
  end

  validates_confirmation_of :password, if: ->{ password.present? }

  def password
    return if self.encrypted_password.blank?
    @password ||= Password.new(self.encrypted_password)
  end

  def password=(new_password)
    if new_password.nil?
      self.encrypted_password = nil
    elsif new_password.present?
      @password = Password.create(new_password)
      self.encrypted_password = @password
    end
  end


end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ecrire-0.31.1 lib/ecrire/app/models/user.rb
ecrire-0.31.0 lib/ecrire/app/models/user.rb
ecrire-0.30.3 lib/ecrire/app/models/user.rb
ecrire-0.30.2 lib/ecrire/app/models/user.rb
ecrire-0.30.1 lib/ecrire/app/models/user.rb
ecrire-0.30.0 lib/ecrire/app/models/user.rb
ecrire-0.29.0 lib/ecrire/app/models/user.rb
ecrire-0.28.3 lib/ecrire/app/models/user.rb
ecrire-0.28.2 lib/ecrire/app/models/user.rb
ecrire-0.28.1 lib/ecrire/app/models/user.rb
ecrire-0.28.0 lib/ecrire/app/models/user.rb
ecrire-0.27.0 lib/ecrire/app/models/user.rb
ecrire-0.26.3 lib/ecrire/app/models/user.rb
ecrire-0.26.2 lib/ecrire/app/models/user.rb
ecrire-0.26.1 lib/ecrire/app/models/user.rb
ecrire-0.26.0 lib/ecrire/app/models/user.rb
ecrire-0.25.2 lib/ecrire/app/models/user.rb
ecrire-0.25.1 lib/ecrire/app/models/user.rb
ecrire-0.25.0 lib/ecrire/app/models/user.rb
ecrire-0.24.1 lib/ecrire/app/models/user.rb