Improve login form

This commit is contained in:
Trevor Vallender 2023-08-18 20:55:12 +01:00
parent 88ccf7d958
commit db908d4ea4
3 changed files with 21 additions and 2 deletions

View File

@ -10,7 +10,8 @@ class SessionsController < ApplicationController
session[:user_id] = @user.id session[:user_id] = @user.id
redirect_to @user, notice: t(".logged_in") redirect_to @user, notice: t(".logged_in")
else else
redirect_to root_path, alert: t(".login_fail") flash.now.alert = t(".login_fail")
render :new
end end
end end

View File

@ -1,5 +1,5 @@
<% @title = "Log in" %> <% @title = "Log in" %>
<%= form_with url: sessions_path, method: :post do |f| %> <%= form_with url: sessions_path, method: :post, id: "session_form" do |f| %>
<h2><%= t ".log_in" %></h2> <h2><%= t ".log_in" %></h2>
<%= f.label :username %> <%= f.label :username %>

View File

@ -0,0 +1,18 @@
<% @title = "Log in" %>
<%= turbo_stream.replace "flash_wrapper" do %>
<%= render "shared/flash" %>
<% end %>
<%= turbo_stream.replace "session_form" do %>
<%= form_with url: sessions_path, method: :post, id: "session_form" do |f| %>
<h2><%= t ".log_in" %></h2>
<%= f.label :username %>
<%= f.text_field :username %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.submit t(".log_in") %>
<% end %>
<% end %>