diff --git a/backend/lib/azimutt_web/controllers/user_settings_controller.ex b/backend/lib/azimutt_web/controllers/user_settings_controller.ex index 9fe50b701..106b78a57 100644 --- a/backend/lib/azimutt_web/controllers/user_settings_controller.ex +++ b/backend/lib/azimutt_web/controllers/user_settings_controller.ex @@ -1,6 +1,7 @@ defmodule AzimuttWeb.UserSettingsController do use AzimuttWeb, :controller alias Azimutt.Accounts + alias Azimutt.Organizations alias Azimutt.Utils.Result alias AzimuttWeb.UserAuth action_fallback AzimuttWeb.FallbackController @@ -11,6 +12,25 @@ defmodule AzimuttWeb.UserSettingsController do conn |> show_html(current_user, now) end + def auth(conn, _params) do + current_user = conn.assigns.current_user + now = DateTime.utc_now() + auth_token_changeset = Accounts.change_auth_token(current_user) + conn |> render("auth.html", auth_tokens: Accounts.list_auth_tokens(current_user, now), auth_token_changeset: auth_token_changeset) + end + + def delete_account(conn, _params) do + current_user = conn.assigns.current_user + now = DateTime.utc_now() + + # Accounts.delete_user(current_user, now) + # |> Result.fold( + # fn _ -> conn |> put_flash(:error, "Can't delete your account :/") end, + # fn _ -> conn |> put_flash(:info, "Account deleted") end + # ) |> redirect(to: Routes.page_path(conn, :index)) + conn |> show_html(current_user, now) + end + def update_account(conn, %{"user" => user_params}) do current_user = conn.assigns.current_user now = DateTime.utc_now() @@ -153,7 +173,7 @@ defmodule AzimuttWeb.UserSettingsController do conn |> render("show.html", user: user, - auth_tokens: Accounts.list_auth_tokens(user, now), + organizations: Organizations.list_organizations(user), infos_changeset: infos_changeset, email_changeset: email_changeset, password_changeset: password_changeset, diff --git a/backend/lib/azimutt_web/router.ex b/backend/lib/azimutt_web/router.ex index 1ad5640bf..70268e8d6 100644 --- a/backend/lib/azimutt_web/router.ex +++ b/backend/lib/azimutt_web/router.ex @@ -122,13 +122,16 @@ defmodule AzimuttWeb.Router do pipe_through([:user_settings_root_layout, :empty_layout]) get("/", UserSettingsController, :show) put("/account", UserSettingsController, :update_account) + delete("/account", UserSettingsController, :delete_account) put("/email", UserSettingsController, :update_email) get("/email/:token", UserSettingsController, :confirm_update_email) put("/password", UserSettingsController, :update_password) post("/password", UserSettingsController, :set_password) delete("/providers/:provider", UserSettingsController, :remove_provider) - post("/auth-tokens", UserSettingsController, :create_auth_token) - delete("/auth-tokens/:token_id", UserSettingsController, :delete_auth_token) + + get("/auth", UserSettingsController, :auth) + post("/auth/tokens", UserSettingsController, :create_auth_token) + delete("/auth/tokens/:token_id", UserSettingsController, :delete_auth_token) end resources "/organizations", OrganizationController, param: "organization_id", except: [:index] do diff --git a/backend/lib/azimutt_web/templates/layout/_user_settings_left_bar.html.heex b/backend/lib/azimutt_web/templates/layout/_user_settings_left_bar.html.heex index 79910a18c..9a4b6ea96 100644 --- a/backend/lib/azimutt_web/templates/layout/_user_settings_left_bar.html.heex +++ b/backend/lib/azimutt_web/templates/layout/_user_settings_left_bar.html.heex @@ -2,8 +2,8 @@