Mise à jour des attributs des utilisateurs

This commit is contained in:
Jérémy Lecour 2022-01-22 19:18:44 +01:00 committed by Jérémy Lecour
parent a42eb7d379
commit 83c0712947
2 changed files with 22 additions and 1 deletions

View File

@ -38,6 +38,9 @@ class UsersController < ApplicationController
def update
respond_to do |format|
if @user.update(user_params)
if @user.unconfirmed? && params.fetch(:user, {}).fetch(:confirm, "0") == "1"
@user.confirm!
end
format.html { redirect_to user_url(@user), notice: "User was successfully updated." }
format.json { render :show, status: :ok, location: @user }
else
@ -65,6 +68,6 @@ class UsersController < ApplicationController
# Only allow a list of trusted parameters through.
def user_params
params.fetch(:user, {})
params.require(:user).permit(:name, :email)
end
end

View File

@ -11,6 +11,24 @@
</div>
<% end %>
<% if user.confirmed? %>
<div>
<%= form.label :email, "Confirmed Email" %>
<%= form.text_field :email %>
</div>
<% else %>
<div>
<%= form.label :email, "Unconfirmed Email" %>
<%= text_field_tag :email, user.confirmable_email, disabled: true %>
<br /><%= form.label :confirm, "Confirm?" %>
<%= form.check_box :confirm %>
</div>
<% end %>
<div>
<%= form.label :name %>
<%= form.text_field :name %>
</div>
<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
</div>