Sha256: 530a6f09a2b96e9892914bc2b34d7857a1f8045dcc2e6d855a64defc2060ee9d

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 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
      logger.info "@user: " + @user.inspect
      logger.info "ERRORS?: " + @user.errors.inspect
      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
    email = user_params.delete(:email)
    password = user_params.delete(:password)

    Authenticate.configuration.user_model_class.new(user_params).tap do |user|
      user.email = email
      user.password = password
    end
  end

  def user_params
    key = Authenticate.configuration.user_model_param_key.to_sym
    params[key] || Hash.new
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authenticate-0.2.2 app/controllers/authenticate/users_controller.rb