mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
af9e779c59
* First (not-yet-working) attempt at self-renaming * Actually working renames * last_renamed_at * Prevent renaming while banned * Move username changing from controller to model * Username change logging * Rate limiting for username changes * username -> name and format * add UBQ * modify interval Co-authored-by: Joey <joeyponi@gmail.com>
33 lines
989 B
Elixir
33 lines
989 B
Elixir
defmodule PhilomenaWeb.Registration.NameController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.Users
|
|
|
|
plug PhilomenaWeb.FilterBannedUsersPlug
|
|
plug :verify_authorized
|
|
|
|
def edit(conn, _params) do
|
|
changeset = Users.change_user(conn.assigns.current_user)
|
|
|
|
render(conn, "edit.html", title: "Editing Name", changeset: changeset)
|
|
end
|
|
|
|
def update(conn, %{"user" => user_params}) do
|
|
case Users.update_name(conn.assigns.current_user, user_params) do
|
|
{:ok, %{account: user}} ->
|
|
conn
|
|
|> put_flash(:info, "Name successfully updated.")
|
|
|> redirect(to: Routes.profile_path(conn, :show, user))
|
|
|
|
{:error, %{account: changeset}} ->
|
|
render(conn, "edit.html", changeset: changeset)
|
|
end
|
|
end
|
|
|
|
defp verify_authorized(conn, _opts) do
|
|
case Canada.Can.can?(conn.assigns.current_user, :change_username, conn.assigns.current_user) do
|
|
true -> conn
|
|
_false -> PhilomenaWeb.NotAuthorizedPlug.call(conn)
|
|
end
|
|
end
|
|
end
|