Sha256: af76391b91096d0c446de98c4b831b72cd29ec1b202f027958f67e3108b0e065

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

class Authenticate::UsersController < Authenticate::AuthenticateController
  before_action :redirect_signed_in_users, only: [:create, :new]
  skip_before_action :require_authentication, only: [:create, :new], raise: false

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

  def create
    @user = user_from_params

    if @user.save
      login @user
      redirect_back_or url_after_create
    else
      render template: 'users/new'
    end
  end

  private

  def redirect_signed_in_users
    if authenticated?
      redirect_to Authenticate.configuration.redirect_url
    end
  end

  def url_after_create
    Authenticate.configuration.redirect_url
  end

  def user_from_params
    param_key = Authenticate.configuration.user_model_param_key.to_sym # :user, :user_profile, etc
    user_params = params[param_key] ? user_params(param_key) : Hash.new
    Authenticate.configuration.user_model_class.new(user_params)
  end

  # Override this method to allow additional user attributes.
  # Default impl allows username and email to service both styles of authentication.
  #
  # * param_key - String used for parameter names, ActiveModel::Naming.param_key
  #
  def user_params(param_key)
    params.require(param_key).permit(:username, :email, :password)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authenticate-0.3.0 app/controllers/authenticate/users_controller.rb
authenticate-0.2.3 app/controllers/authenticate/users_controller.rb