Sha256: 0fff20961d938a6ae9da5ac6a73234aaf4552dcdf6ecaee0aa48869e30b12539

Contents?: true

Size: 1.99 KB

Versions: 29

Compression:

Stored size: 1.99 KB

Contents

module Workarea
  class Storefront::Users::PasswordsController < Storefront::ApplicationController
    before_action :require_login, only: [:change, :make_change]
    skip_before_action :require_password_changes

    def new
    end

    def edit
      reset = User::PasswordReset.find_by(token: params[:token]) rescue nil
      redirect_to forgot_password_path unless reset
    end

    def create
      password_reset = User::PasswordReset.setup!(params[:email])
      if password_reset.present?
        Storefront::AccountMailer.password_reset(password_reset.id.to_s).deliver_later
      end

      flash[:success] = t(
        'workarea.storefront.flash_messages.password_reset_email_sent',
        email: params[:email]
      )
      redirect_to forgot_password_path
    end

    def update
      reset = User::PasswordReset.find_by(token: params[:token]) rescue nil

      if reset.blank?
        flash[:error] = t('workarea.storefront.flash_messages.password_reset_expired')
        render :edit
      elsif reset.complete(params[:password])
        flash[:success] = t('workarea.storefront.flash_messages.password_reset')
        redirect_to login_path
      else
        flash[:error] = reset.errors.full_messages.to_sentence
        redirect_to reset_password_path(token: reset.token)
      end
    end

    def change
    end

    def make_change
      unless current_user.authenticate(params[:old_password])
        flash[:error] = t('workarea.storefront.flash_messages.old_password_invalid')
        render :change and return
      end

      if params[:password].blank?
        flash[:error] = t('workarea.storefront.flash_messages.password_required')
        render :change and return
      end

      if current_user.update_attributes(password: params[:password])
        flash[:success] = t('workarea.storefront.flash_messages.password_reset')
        redirect_back_or users_account_path
      else
        flash[:error] = current_user.errors.full_messages
        render :change and return
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
workarea-storefront-3.5.8 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.30 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.7 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.29 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.6 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.28 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.5 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.27 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.4 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.26 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.3 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.25 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.2 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.24 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.1 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.23 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.22 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.0 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.4.21 app/controllers/workarea/storefront/users/passwords_controller.rb
workarea-storefront-3.5.0.beta.1 app/controllers/workarea/storefront/users/passwords_controller.rb