mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Centralize auth messages (#269)
* Add i18n-tasks
* Add auth-related i18n
* Centralize auth messages
* Remove safe navigation
* Revert "Remove safe navigation"
This reverts commit 56b5e01e5e
.
* Remove newline in Gemfile
This commit is contained in:
parent
69698d0463
commit
c5192ee424
17 changed files with 138 additions and 55 deletions
|
@ -1,6 +1,8 @@
|
|||
class PasswordResetsController < ApplicationController
|
||||
layout "auth"
|
||||
|
||||
before_action :set_user_by_token, only: :update
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
|
@ -12,7 +14,7 @@ class PasswordResetsController < ApplicationController
|
|||
).password_reset.deliver_later
|
||||
end
|
||||
|
||||
redirect_to root_path, notice: "If an account with that email exists, we have sent a link to reset your password."
|
||||
redirect_to root_path, notice: t(".requested")
|
||||
end
|
||||
|
||||
def edit
|
||||
|
@ -20,7 +22,7 @@ class PasswordResetsController < ApplicationController
|
|||
|
||||
def update
|
||||
if @user.update(password_params)
|
||||
redirect_to new_session_path, notice: "Your password has been reset."
|
||||
redirect_to new_session_path, notice: t(".success")
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
@ -30,7 +32,7 @@ class PasswordResetsController < ApplicationController
|
|||
|
||||
def set_user_by_token
|
||||
@user = User.find_by_token_for(password_reset: params[:token])
|
||||
redirect_to new_password_reset_path, alert: "Invalid token." unless @user.present?
|
||||
redirect_to new_password_reset_path, alert: t("password_resets.update.invalid_token") unless @user.present?
|
||||
end
|
||||
|
||||
def password_params
|
||||
|
|
|
@ -6,7 +6,7 @@ class PasswordsController < ApplicationController
|
|||
|
||||
def update
|
||||
if current_user.update(password_params)
|
||||
redirect_to root_path, notice: "Your password has been updated successfully."
|
||||
redirect_to root_path, notice: t(".success")
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
|
|
|
@ -14,10 +14,10 @@ class RegistrationsController < ApplicationController
|
|||
|
||||
if @user.save
|
||||
login @user
|
||||
flash[:notice] = "You have signed up successfully."
|
||||
flash[:notice] = t(".success")
|
||||
redirect_to root_path
|
||||
else
|
||||
flash[:alert] = "Invalid input, please try again."
|
||||
flash[:alert] = t(".failure")
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ class RegistrationsController < ApplicationController
|
|||
|
||||
def claim_invite_code
|
||||
unless InviteCode.claim! params[:user][:invite_code]
|
||||
redirect_to new_registration_path, alert: "Invalid invite code, please try again."
|
||||
redirect_to new_registration_path, alert: t("registrations.create.invalid_invite_code")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,13 +9,13 @@ class SessionsController < ApplicationController
|
|||
login user
|
||||
redirect_to root_path
|
||||
else
|
||||
flash.now[:alert] = "Invalid email or password."
|
||||
flash.now[:alert] = t(".invalid_credentials")
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
logout
|
||||
redirect_to root_path, notice: "You have signed out successfully."
|
||||
redirect_to root_path, notice: t(".logout_successful")
|
||||
end
|
||||
end
|
||||
|
|
6
app/helpers/auth_messages_helper.rb
Normal file
6
app/helpers/auth_messages_helper.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
module AuthMessagesHelper
|
||||
def auth_messages(form = nil)
|
||||
render "shared/auth_messages", flash: flash,
|
||||
errors: form&.object&.errors&.full_messages || []
|
||||
end
|
||||
end
|
|
@ -18,12 +18,6 @@
|
|||
</head>
|
||||
|
||||
<body class="h-full">
|
||||
<% flash.each do |type, msg| %>
|
||||
<div>
|
||||
<%= msg %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="flex flex-col justify-center min-h-full px-6 py-12">
|
||||
|
||||
<div class="sm:mx-auto sm:w-full sm:max-w-md">
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
%>
|
||||
|
||||
<%= form_with url: password_reset_path(token: params[:token]), html: {class: 'space-y-6'} do |form| %>
|
||||
<%= auth_messages form %>
|
||||
|
||||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100">
|
||||
<%= form.label :password, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
%>
|
||||
|
||||
<%= form_with url: password_reset_path, html: {class: 'space-y-6'} do |form| %>
|
||||
<%= auth_messages form %>
|
||||
|
||||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100">
|
||||
<%= form.label :email, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %>
|
||||
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: 'required', placeholder: 'you@example.com', class: 'p-4 pt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %>
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<h1>Update Password</h1>
|
||||
|
||||
<%= form_with model: current_user, url: password_path do |form| %>
|
||||
<% if form.object.errors.any? %>
|
||||
<% form.object.errors.full_messages.each do |message| %>
|
||||
<div><%= message %></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= auth_messages form %>
|
||||
|
||||
<div>
|
||||
<%= form.label :password_challenge, "Current Password" %>
|
||||
|
|
|
@ -3,11 +3,7 @@
|
|||
%>
|
||||
|
||||
<%= form_with model: @user, url: registration_path, html: {class: 'space-y-6'} do |form| %>
|
||||
<% if form.object.errors.any? %>
|
||||
<% form.object.errors.full_messages.each do |message| %>
|
||||
<div><%= message %></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= auth_messages form %>
|
||||
|
||||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100">
|
||||
<%= form.label :email, class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
%>
|
||||
|
||||
<%= form_with url: session_path, html: {class: 'space-y-6'} do |form| %>
|
||||
<%= auth_messages form %>
|
||||
|
||||
<div class="relative border border-gray-100 bg-offwhite rounded-xl focus-within:bg-white focus-within:shadow focus-within:opacity-100">
|
||||
<%= form.label :email, "Email address", class: 'p-4 pb-0 block text-sm font-medium text-gray-700' %>
|
||||
<%= form.email_field :email, autofocus: false, autocomplete: "email", required: 'required', placeholder: 'you@example.com', class: 'p-4 pt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %>
|
||||
|
|
7
app/views/shared/_auth_messages.html.erb
Normal file
7
app/views/shared/_auth_messages.html.erb
Normal file
|
@ -0,0 +1,7 @@
|
|||
<% flash.each do |type, msg| %>
|
||||
<div><%= msg %></div>
|
||||
<% end %>
|
||||
|
||||
<% errors.each do |message| %>
|
||||
<div><%= message %></div>
|
||||
<% end %>
|
Loading…
Add table
Add a link
Reference in a new issue