Sha256: 20fab039c24c872f831f5930b848baa9249fb194cc150b325b1450a4aff46930

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

module Boxroom
  class ResetPasswordController < Boxroom::ApplicationController
    include Boxroom::BaseController

    before_action :require_valid_token, :only => [:edit, :update]
    skip_before_action :require_login

    def new
    end

    def create
      user = User.find_by_email(params[:email])

      unless user.nil?
        user.refresh_reset_password_token
        UserMailer.reset_password_email(user).deliver_now
      end

      redirect_to new_reset_password_url, :notice => t(:instruction_email_sent, :email => params[:email])
    end

    # Note: @user is set in require_valid_token
    def edit
    end

    # Note: @user is set in require_valid_token
    def update
      if @user.update_attributes(permitted_params.user.merge({:password_required => true}))
        redirect_to new_session_url, :notice => t(:password_reset_successfully)
      else
        render :action => 'edit'
      end
    end

    private

    def require_valid_token
      @user = User.find_by_reset_password_token(params[:id])

      if @user.nil? || @user.reset_password_token_expires_at < Time.now
        redirect_to new_reset_password_url, :alert => t(:reset_url_expired)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
boxroom-0.0.5 app/controllers/boxroom/reset_password_controller.rb
boxroom-0.0.4 app/controllers/boxroom/reset_password_controller.rb
boxroom-0.0.3 app/controllers/boxroom/reset_password_controller.rb
boxroom-0.0.2 app/controllers/boxroom/reset_password_controller.rb
boxroom-0.0.1 app/controllers/boxroom/reset_password_controller.rb