2019-12-07 17:26:45 +01:00
|
|
|
defmodule PhilomenaWeb.AvatarController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
alias Philomena.Users
|
|
|
|
|
|
|
|
plug PhilomenaWeb.FilterBannedUsersPlug
|
2020-01-11 05:20:19 +01:00
|
|
|
|
|
|
|
plug PhilomenaWeb.ScraperPlug,
|
|
|
|
[params_name: "user", params_key: "avatar"] when action in [:update]
|
2019-12-07 17:26:45 +01:00
|
|
|
|
|
|
|
def edit(conn, _params) do
|
|
|
|
changeset = Users.change_user(conn.assigns.current_user)
|
2019-12-16 20:24:38 +01:00
|
|
|
render(conn, "edit.html", title: "Editing Avatar", changeset: changeset)
|
2019-12-07 17:26:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update(conn, %{"user" => user_params}) do
|
|
|
|
case Users.update_avatar(conn.assigns.current_user, user_params) do
|
|
|
|
{:ok, _user} ->
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Successfully updated avatar.")
|
2024-06-06 22:28:35 +02:00
|
|
|
|> redirect(to: ~p"/avatar/edit")
|
2019-12-07 17:26:45 +01:00
|
|
|
|
2020-09-08 05:38:27 +02:00
|
|
|
{:error, changeset} ->
|
2019-12-07 17:26:45 +01:00
|
|
|
render(conn, "edit.html", changeset: changeset)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete(conn, _params) do
|
|
|
|
{:ok, _user} = Users.remove_avatar(conn.assigns.current_user)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_flash(:info, "Successfully removed avatar.")
|
2024-06-06 22:28:35 +02:00
|
|
|
|> redirect(to: ~p"/avatar/edit")
|
2019-12-07 17:26:45 +01:00
|
|
|
end
|
2019-12-16 20:24:38 +01:00
|
|
|
end
|