something awful login data
all the stuff to add 2 fields to the user object and to access the logged0in user in a liveview session
This commit is contained in:
@ -4,12 +4,27 @@ defmodule SomethingErlangWeb.UserSettingsController do
|
||||
alias SomethingErlang.Accounts
|
||||
alias SomethingErlangWeb.UserAuth
|
||||
|
||||
plug :assign_email_and_password_changesets
|
||||
plug :assign_changesets
|
||||
|
||||
def edit(conn, _params) do
|
||||
render(conn, "edit.html")
|
||||
end
|
||||
|
||||
def update(conn, %{"action" => "update_sadata"} = params) do
|
||||
%{"user" => user_params} = params
|
||||
user = conn.assigns.current_user
|
||||
|
||||
case Accounts.update_sadata(user, user_params) do
|
||||
{:ok, _user} ->
|
||||
conn
|
||||
|> put_flash(:info, "Settings updated successfully.")
|
||||
|> redirect(to: Routes.user_settings_path(conn, :edit))
|
||||
|
||||
{:error, changeset} ->
|
||||
render(conn, "edit.html", sadata_changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def update(conn, %{"action" => "update_email"} = params) do
|
||||
%{"current_password" => password, "user" => user_params} = params
|
||||
user = conn.assigns.current_user
|
||||
@ -64,10 +79,11 @@ defmodule SomethingErlangWeb.UserSettingsController do
|
||||
end
|
||||
end
|
||||
|
||||
defp assign_email_and_password_changesets(conn, _opts) do
|
||||
defp assign_changesets(conn, _opts) do
|
||||
user = conn.assigns.current_user
|
||||
|
||||
conn
|
||||
|> assign(:sadata_changeset, Accounts.change_user_sadata(user))
|
||||
|> assign(:email_changeset, Accounts.change_user_email(user))
|
||||
|> assign(:password_changeset, Accounts.change_user_password(user))
|
||||
end
|
||||
|
Reference in New Issue
Block a user