Sha256: 7c89d2746d0fa9d5546e3476679976984c30b1b58a3b4e9226b6969b502ffc68

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

class Clearance::UsersController < Clearance::BaseController
  before_filter :redirect_signed_in_users, only: [:create, :new]
  skip_before_filter :require_login, only: [:create, :new]
  skip_before_filter :authorize, only: [:create, :new]

  def new
    @user = user_from_params
    render template: "users/new"
  end

  def create
    @user = user_from_params

    if @user.save
      sign_in @user
      redirect_back_or url_after_create
    else
      render template: "users/new"
    end
  end

  private

  def avoid_sign_in
    warn "[DEPRECATION] Clearance's `avoid_sign_in` before_filter is " +
      "deprecated. Use `redirect_signed_in_users` instead. " +
      "Be sure to update any instances of `skip_before_filter :avoid_sign_in`" +
      " or `skip_before_action :avoid_sign_in` as well"
    redirect_signed_in_users
  end

  def redirect_signed_in_users
    if signed_in?
      redirect_to Clearance.configuration.redirect_url
    end
  end

  def url_after_create
    Clearance.configuration.redirect_url
  end

  def user_from_params
    email = user_params.delete(:email)
    password = user_params.delete(:password)

    Clearance.configuration.user_model.new(user_params).tap do |user|
      user.email = email
      user.password = password
    end
  end

  def user_params
    params[:user] || Hash.new
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
clearance-1.12.1 app/controllers/clearance/users_controller.rb
clearance-1.12.0 app/controllers/clearance/users_controller.rb
clearance-1.11.0 app/controllers/clearance/users_controller.rb
clearance-1.10.1 app/controllers/clearance/users_controller.rb
clearance-1.9.0 app/controllers/clearance/users_controller.rb
clearance-1.8.1 app/controllers/clearance/users_controller.rb
clearance-1.8.0 app/controllers/clearance/users_controller.rb