philomena/lib/philomena_web/controllers/avatar_controller.ex

34 lines
1 KiB
Elixir
Raw Normal View History

2019-12-07 17:26:45 +01:00
defmodule PhilomenaWeb.AvatarController do
use PhilomenaWeb, :controller
alias Philomena.Users
plug PhilomenaWeb.FilterBannedUsersPlug
plug PhilomenaWeb.ScraperPlug, [params_name: "user", params_key: "avatar"] when action in [:update]
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.")
|> redirect(to: Routes.avatar_path(conn, :edit))
{:error, :user, changeset, _changes} ->
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.")
|> redirect(to: Routes.avatar_path(conn, :edit))
end
2019-12-16 20:24:38 +01:00
end