Sha256: aab034fb02b202c8543c5fd9e49efad5eb07a8e861e7327874c7cdf98db7edef

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

class Clearance::ConfirmationsController < ApplicationController
  unloadable

  before_filter :forbid_confirmed_user,    :only => :new
  before_filter :forbid_missing_token,     :only => :new
  before_filter :forbid_non_existent_user, :only => :new
  filter_parameter_logging :token

  def new
    create
  end

  def create
    @user = ::User.find_by_id_and_token(params[:user_id], params[:token])
    @user.confirm_email!

    sign_user_in(@user)
    flash[:success] = t(:confirmed, :scope => [:clearance, :controllers, :confirmations], :default => "Confirmed email and signed in.")
    redirect_to url_after_create
  end

  private

  def forbid_confirmed_user
    user = ::User.find_by_id(params[:user_id])
    if user && user.email_confirmed?
      raise ActionController::Forbidden, "confirmed user"
    end
  end

  def forbid_missing_token
    if params[:token].blank?
      raise ActionController::Forbidden, "missing token"
    end
  end

  def forbid_non_existent_user
    unless ::User.find_by_id_and_token(params[:user_id], params[:token])
      raise ActionController::Forbidden, "non-existent user"
    end
  end

  def url_after_create
    root_url
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vita-clearance-0.6.3.1 app/controllers/clearance/confirmations_controller.rb