Sha256: 1c8dc1a76cb5d52522f8f2dc2e1b9dfc9d3456d330ee2515cbe0a58eb2f03223

Contents?: true

Size: 776 Bytes

Versions: 2

Compression:

Stored size: 776 Bytes

Contents

class SignInsController::Create < BaseAction
  def perform
    return build_view(Todos::IndexRedirect) if current_user
    return build_view(Defaults::BadRequestView, status: :bad_request, errors: [user_params.error_message]) unless user_params.fetch
    return build_view(SignIns::NewView, status: :not_found) unless user

    if user.authenticate(user_params.fetch[:password])
      SignInService.perform!(session, user)
      build_view(Todos::IndexRedirect)
    else
      build_view(SignIns::NewView, status: :unprocessable_entity, errors: ["Incorrect credentials"])
    end
  end

  private

  def user_params
    @user_params ||= ::SignInsController::UserParams.build(params)
  end

  def user
    @user ||= User.where(email: user_params.fetch[:email]).first
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aldous-1.0.1 examples/basic_todo/app/controller_actions/sign_ins_controller/create.rb
aldous-1.0.0 examples/basic_todo/app/controller_actions/sign_ins_controller/create.rb