require "authem/token"

module Authem
  module User
    extend ActiveSupport::Concern

    included do
      has_many :authem_sessions, as: :subject, class_name: "Authem::Session"
      has_secure_password

      alias_attribute :password_reset_token, :reset_password_token

      validates :email,
        uniqueness: true,
        presence: true,
        format: { with: /\A\S+@\S+\z/, allow_blank: true }

      before_create{ self.password_reset_token = Authem::Token.generate }
    end

    def email=(value)
      super value.try(:downcase)
    end

    def reset_password(password, confirmation)
      if password.blank?
        errors.add :password, :blank
        return false
      end

      self.password = password
      self.password_confirmation = confirmation

      update_column :password_reset_token, Authem::Token.generate if save
    end
  end
end

require "authem/token"

module Authem
  module User
    extend ActiveSupport::Concern

    included do
      has_many :authem_sessions, as: :subject, class_name: "Authem::Session"
      has_secure_password

      validates :email,
        uniqueness: true,
        presence: true,
        format: { with: /\A\S+@\S+\z/, allow_blank: true }

      before_create{ self.password_reset_token = Authem::Token.generate }
    end

    def email=(value)
      super value.try(:downcase)
    end

    def reset_password(password, confirmation)
      if password.blank?
        errors.add :password, :blank
        return false
      end

      self.password = password
      self.password_confirmation = confirmation

      update_column :password_reset_token, Authem::Token.generate if save
    end
  end
end

Revert "Alias old new password_reset_token field to old reset_password_token"
Revert "Alias old new password_reset_token field to old reset_password_token"

This reverts commit c3df59d56afebdcd337913a18c59981815735b42.
