Skip to content

Commit

Permalink
Error on logging in sort of works now
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Oct 1, 2024
1 parent 048d429 commit ba91b41
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions app/controllers/alerts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class AlertsController < ApplicationController
extend T::Sig

before_action :authenticate_user!, except: %i[unsubscribe signed_out sign_in]
after_action :verify_authorized, except: %i[index unsubscribe signed_out sign_in]
before_action :authenticate_user!, except: %i[unsubscribe signed_out sign_in user_session]
after_action :verify_authorized, except: %i[index unsubscribe signed_out sign_in user_session]
after_action :verify_policy_scoped, only: :index

layout "profile", except: %i[unsubscribe signed_out sign_in]
Expand Down Expand Up @@ -92,6 +92,16 @@ def signed_out
# TODO: Rename
def sign_in
# TODO: Use strong parameters instead
@alert = Alert.new(address: params[:alert][:address], radius_meters: params[:alert][:radius_meters])
@user = User.new(email: params[:user][:email], password: params[:user][:password])
@alert = Alert.new(address: params[:user][:address], radius_meters: params[:user][:radius_meters])
end

# TODO: Rename
def user_session
@user = warden.authenticate!({ scope: :user, recall: "Alerts#sign_in", locale: I18n.locale })
# set_flash_message!(:notice, :signed_in)
# sign_in(resource_name, resource)
# yield resource if block_given?
# respond_with resource, location: after_sign_in_path_for(resource)
end
end
2 changes: 1 addition & 1 deletion app/views/alerts/sign_in.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Applications within <%= meters_in_words(@alert.radius_meters) %> of <%= @alert.address %>
</p>

<%= form_with model: User.new, url: user_session_alerts_path do |f| %>
<%= form_with model: @user, url: user_session_alerts_path do |f| %>
<%# TODO: Add error display and styling %>
<div class="flex flex-col items-center">
<div class="w-full">
Expand Down
6 changes: 3 additions & 3 deletions app/views/alerts/signed_out.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<%# TODO: Add create account flow %>

<%= form_with model: @alert, url: sign_in_alerts_path, method: "get" do |f| %>
<%= f.hidden_field :address %>
<%= f.hidden_field :radius_meters %>
<%= form_with model: User, url: sign_in_alerts_path, method: "get" do |f| %>
<%= f.hidden_field :address, value: @alert.address %>
<%= f.hidden_field :radius_meters, value: @alert.radius_meters %>
<%= f.button "Sign in" %>
<% end %>

0 comments on commit ba91b41

Please sign in to comment.