Commit 23de5e026dd8be672b545e739aec26b7cd6e657d

Thomas de Grivel 2021-12-09T12:04:20

fix edit user

diff --git a/lib/kmxgit_web/controllers/user_controller.ex b/lib/kmxgit_web/controllers/user_controller.ex
index 58d49ff..cdbb42f 100644
--- a/lib/kmxgit_web/controllers/user_controller.ex
+++ b/lib/kmxgit_web/controllers/user_controller.ex
@@ -10,10 +10,14 @@ defmodule KmxgitWeb.UserController do
   def edit(conn, params) do
     current_user = conn.assigns.current_user
     if params["login"] == current_user.slug.slug do
-      changeset = User.changeset(current_user)
+      changeset = UserManager.change_user(current_user)
+      email_changeset = UserManager.change_user_email(current_user)
+      password_changeset = UserManager.change_user_password(current_user)
       conn
       |> assign(:changeset, changeset)
+      |> assign(:email_changeset, email_changeset)
       |> assign(:page_title, gettext("Edit user %{login}", login: current_user.slug.slug))
+      |> assign(:password_changeset, password_changeset)
       |> render("edit.html")
     else
       not_found(conn)
diff --git a/lib/kmxgit_web/templates/user/edit.html.heex b/lib/kmxgit_web/templates/user/edit.html.heex
index a13070c..9a237b6 100644
--- a/lib/kmxgit_web/templates/user/edit.html.heex
+++ b/lib/kmxgit_web/templates/user/edit.html.heex
@@ -52,7 +52,8 @@
     </div>
   <% end %>
 
-  <h3>Change email</h3>
+  <hr/>
+  <h2><%= gettext "Change email" %></h2>
 
   <.form let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email">
     <%= if @email_changeset.action do %>
@@ -80,7 +81,8 @@
     </div>
   </.form>
 
-  <h3>Change password</h3>
+  <hr/>
+  <h2><%= gettext "Change password" %></h2>
 
   <.form let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password">
     <%= if @password_changeset.action do %>
@@ -91,20 +93,26 @@
 
     <%= hidden_input f, :action, name: "action", value: "update_password" %>
 
-    <%= label f, :password, "New password" %>
-    <%= password_input f, :password, required: true %>
-    <%= error_tag f, :password %>
+    <div class="mb-3">
+      <%= label f, :password, gettext("New password"), class: "form-label" %>
+      <%= password_input f, :password, class: "form-control", required: true %>
+      <%= error_tag f, :password %>
+    </div>
 
-    <%= label f, :password_confirmation, "Confirm new password" %>
-    <%= password_input f, :password_confirmation, required: true %>
-    <%= error_tag f, :password_confirmation %>
+    <div class="mb-3">
+      <%= label f, :password_confirmation, gettext("Confirm new password"), class: "form-label" %>
+      <%= password_input f, :password_confirmation, class: "form-control", required: true %>
+      <%= error_tag f, :password_confirmation %>
+    </div>
 
-    <%= label f, :current_password, for: "current_password_for_password" %>
-    <%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_password" %>
-    <%= error_tag f, :current_password %>
+    <div class="mb-3">
+      <%= label f, :current_password, for: "current_password_for_password", class: "form-label" %>
+      <%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_password", class: "form-control" %>
+      <%= error_tag f, :current_password %>
+    </div>
 
-    <div>
-      <%= submit "Change password" %>
+    <div class="mb-3">
+      <%= submit gettext("Submit"), class: "btn btn-primary" %>
     </div>
   </.form>
 </div>
diff --git a/lib/kmxgit_web/templates/user_settings/edit.html.heex b/lib/kmxgit_web/templates/user_settings/edit.html.heex
index 9863bc5..83f8500 100644
--- a/lib/kmxgit_web/templates/user_settings/edit.html.heex
+++ b/lib/kmxgit_web/templates/user_settings/edit.html.heex
@@ -1,53 +1,69 @@
-<h1>Settings</h1>
+<div class="container-fluid">
+  <h1>
+    <%= gettext "Edit user" %>
+    <%= @current_user.slug.slug %>
+  </h1>
 
-<h3>Change email</h3>
+  <h2><%= gettext "Change email" %></h2>
 
-<.form let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email">
-  <%= if @email_changeset.action do %>
-    <div class="alert alert-danger">
-      <p>Oops, something went wrong! Please check the errors below.</p>
-    </div>
-  <% end %>
+  <.form let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email">
+    <%= if @email_changeset.action do %>
+      <div class="alert alert-danger">
+        <p>Oops, something went wrong! Please check the errors below.</p>
+      </div>
+    <% end %>
 
-  <%= hidden_input f, :action, name: "action", value: "update_email" %>
+    <%= hidden_input f, :action, name: "action", value: "update_email" %>
 
-  <%= label f, :email %>
-  <%= email_input f, :email, required: true %>
-  <%= error_tag f, :email %>
+    <div class="mb-3">
+      <%= label f, :email, class: "form-label" %>
+      <%= email_input f, :email, class: "form-control", required: true %>
+      <%= error_tag f, :email %>
+    </div>
 
-  <%= label f, :current_password, for: "current_password_for_email" %>
-  <%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_email" %>
-  <%= error_tag f, :current_password %>
+    <div class="mb-3">
+      <%= label f, :current_password, for: "current_password_for_email", class: "form-label" %>
+      <%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_email", class: "form-control" %>
+      <%= error_tag f, :current_password %>
+    </div>
 
-  <div>
-    <%= submit "Change email" %>
-  </div>
-</.form>
+    <div class="mb-3">
+      <%= submit gettext("Submit"), class: "btn btn-primary" %>
+    </div>
+  </.form>
 
-<h3>Change password</h3>
+  <hr/>
+  <h2><%= gettext "Change password" %></h2>
 
-<.form let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password">
-  <%= if @password_changeset.action do %>
-    <div class="alert alert-danger">
-      <p>Oops, something went wrong! Please check the errors below.</p>
-    </div>
-  <% end %>
+  <.form let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password">
+    <%= if @password_changeset.action do %>
+      <div class="alert alert-danger">
+        <p>Oops, something went wrong! Please check the errors below.</p>
+      </div>
+    <% end %>
 
-  <%= hidden_input f, :action, name: "action", value: "update_password" %>
+    <%= hidden_input f, :action, name: "action", value: "update_password" %>
 
-  <%= label f, :password, "New password" %>
-  <%= password_input f, :password, required: true %>
-  <%= error_tag f, :password %>
+    <div class="mb-3">
+      <%= label f, :password, gettext("New password"), class: "form-label" %>
+      <%= password_input f, :password, class: "form-control", required: true %>
+      <%= error_tag f, :password %>
+    </div>
 
-  <%= label f, :password_confirmation, "Confirm new password" %>
-  <%= password_input f, :password_confirmation, required: true %>
-  <%= error_tag f, :password_confirmation %>
+    <div class="mb-3">
+      <%= label f, :password_confirmation, gettext("Confirm new password"), class: "form-label" %>
+      <%= password_input f, :password_confirmation, class: "form-control", required: true %>
+      <%= error_tag f, :password_confirmation %>
+    </div>
 
-  <%= label f, :current_password, for: "current_password_for_password" %>
-  <%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_password" %>
-  <%= error_tag f, :current_password %>
+    <div class="mb-3">
+      <%= label f, :current_password, for: "current_password_for_password", class: "form-label" %>
+      <%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_password", class: "form-control" %>
+      <%= error_tag f, :current_password %>
+    </div>
 
-  <div>
-    <%= submit "Change password" %>
-  </div>
-</.form>
+    <div class="mb-3">
+      <%= submit gettext("Submit"), class: "btn btn-primary" %>
+    </div>
+  </.form>
+</div>