refactor(auth): use heex templates
Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
13 files changed
+54
-34
No files matched your search
@@ -23,14 +23,23 @@ defmodule KetbinWeb.PageController do
|
||||
if paste.is_url do
|
||||
redirect(conn, external: paste.content)
|
||||
else
|
||||
render(conn, "show.html", paste: paste, show_edit: show_edit, extension: List.first(tail) || "")
|
||||
render(conn, "show.html",
|
||||
paste: paste,
|
||||
show_edit: show_edit,
|
||||
extension: List.first(tail) || ""
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def showlink(%{assigns: %{show_edit: show_edit}} = conn, %{"id" => id}) do
|
||||
[head | tail] = String.split(id, ".")
|
||||
paste = Pastes.get_paste!(head)
|
||||
render(conn, "show.html", paste: paste, show_edit: show_edit, extension: (if tail == [], do: "", else: tail))
|
||||
|
||||
render(conn, "show.html",
|
||||
paste: paste,
|
||||
show_edit: show_edit,
|
||||
extension: if(tail == [], do: "", else: tail)
|
||||
)
|
||||
end
|
||||
|
||||
def raw(conn, %{"id" => id}) do
|
||||
|
||||
@@ -97,15 +97,16 @@ defmodule KetbinWeb.UserAuth do
|
||||
end
|
||||
|
||||
def owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do
|
||||
[head|_tail] = String.split(id, ".")
|
||||
[head | _tail] = String.split(id, ".")
|
||||
paste = Pastes.get_paste!(head)
|
||||
assign(conn, :show_edit, (user && user.id == paste.belongs_to) || false)
|
||||
end
|
||||
|
||||
def ensure_owns_paste(%{params: %{"id" => id}, assigns: %{current_user: user}} = conn, _params) do
|
||||
[head|_tail] = String.split(id, ".")
|
||||
[head | _tail] = String.split(id, ".")
|
||||
paste = Pastes.get_paste!(head)
|
||||
allow_edit = (user && user.id == paste.belongs_to) || false
|
||||
|
||||
unless allow_edit do
|
||||
conn
|
||||
|> put_flash(:error, "You don't own this paste!")
|
||||
|
||||
@@ -46,6 +46,7 @@ defmodule KetbinWeb.UserSettingsController do
|
||||
|> UserAuth.log_in_user(user)
|
||||
|
||||
conn
|
||||
|
||||
{:error, changeset} ->
|
||||
render(conn, "edit.html", password_changeset: changeset)
|
||||
end
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-2
@@ -1,4 +1,4 @@
|
||||
<h1 class="font-bold text-4xl text-amber pt-4 w-full text-center">Settings</h1>
|
||||
<h1 class="font-bold text-4xl text-amber pt-4 w-full text-center">Settings</h1>
|
||||
|
||||
<div class="flex w-full h-full justify-center items-center">
|
||||
<%= form_for @email_changeset, Routes.user_settings_path(@conn, :update), [class: "flex flex-col h-full justify-center items-start m-auto"], fn f -> %>
|
||||
@@ -63,4 +63,4 @@
|
||||
<%= submit "Change password" %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div>
|
||||
</div>
|
||||
Reference in new issue
Block a user