Sha256: 493858329fc69a28c8016654fa9e8250ffad731f728d2b9013a86a6ea9154b5a

Contents?: true

Size: 974 Bytes

Versions: 5

Compression:

Stored size: 974 Bytes

Contents

module Ecm
  module UserArea
    class UserPasswordResetRequest
      include ActiveModel::Model
      extend ActiveModel::Callbacks
      include ActiveModel::Validations::Callbacks

      attr_accessor :user, :email, :host

      def self.call(attributes)
        new(attributes).save
      end

      def self.i18n_scope
        :activerecord
      end

      validates :email, :host, presence: true
      validates :user, presence: true

      before_validation :load_user
      after_validation :delete_error_on_user, if: ->() { errors.get(:email).present? }

      def save
        return unless valid?
        self.user.reset_perishable_token
        self.user.save
        Ecm::UserArea::UserMailer.password_reset_email(self.user, host).deliver_later
      end

      private

      def load_user
        self.user = Ecm::UserArea::User.where(email: self.email).first
      end

      def delete_error_on_user
        errors.delete(:user)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecm_user_area2-2.0.0 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-1.2.10 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-1.2.9 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-1.2.8 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-1.2.6 app/models/ecm/user_area/user_password_reset_request.rb