Sha256: 854068dcb9353133544322ff76e7eeeaddd4ec8eb5ac19dae0d2acc2018eab4a

Contents?: true

Size: 970 Bytes

Versions: 11

Compression:

Stored size: 970 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.has_key?(:email) }

      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

11 entries across 11 versions & 1 rubygems

Version Path
ecm_user_area2-4.0.2 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-4.0.1 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-3.1.2 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-3.1.1 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-3.1.0 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-3.0.3 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-3.0.2 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-3.0.1 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-3.0.0 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-2.3.0 app/models/ecm/user_area/user_password_reset_request.rb
ecm_user_area2-2.2.0 app/models/ecm/user_area/user_password_reset_request.rb