wintermeyer
I use this controller to setup a new registration form:
defmodule AniminaWeb.AccountsController do
use AniminaWeb, :controller
alias Animina.Accounts
alias Animina.Accounts.User
alias AshPhoenix.Form
def register(conn, _params) do
conn =
conn
|> assign(:form_id, "sign-up-form")
|> assign(:cta, "Account anlegen")
|> assign(:action, ~p"/auth/user/password/register")
|> assign(:is_register?, true)
|> assign(
:form,
Form.for_create(User, :register_with_password, api: Accounts, as: "user")
)
render(conn, :register, layout: false)
end
end
It renders this template:
<.top_navigation />
<div class="py-6 space-y-10 px-5">
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
<ul class="error-messages">
<%= if @form.errors do %>
<%= for {k, v} <- @errors do %>
<li>
<%= humanize("#{k} #{v}") %>
</li>
<% end %>
<% end %>
</ul>
<.form :let={f} for={@form} action={@action} method="POST" class="space-y-6">
<%= if @is_register? do %>
<div>
<label for="username" class="block text-sm font-medium leading-6 text-gray-900">
Username
</label>
<div class="mt-2">
<%= text_input(f, :username,
class:
"block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6",
placeholder: "Pusteblume1977",
type: :text,
required: true,
autofocus: true
) %>
</div>
</div>
<% end %>
<div>
<label for="email" class="block text-sm font-medium leading-6 text-gray-900">
E-Mail Addresse
</label>
<div class="mt-2">
<%= text_input(f, :email,
class:
"block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6",
placeholder: "eddie@beispiel.de",
type: :email,
required: true
) %>
</div>
</div>
<div>
<div class="flex items-center justify-between">
<label for="password" class="block text-sm font-medium leading-6 text-gray-900">
Passwort
</label>
<%= unless @is_register? do %>
<div class="text-sm">
<a href="#" class="font-semibold text-indigo-600 hover:text-indigo-500">
Passwort vergessen?
</a>
</div>
<% end %>
</div>
<div class="mt-2">
<%= password_input(f, :password,
class:
"block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6",
placeholder: "Passwort"
) %>
</div>
</div>
<div>
<%= submit(@cta,
class:
"flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
) %>
</div>
</.form>
</div>
</div>
</div>
Any validation error leads to a call of this function in AuthController:
def failure(conn, _activity, _reason) do
conn
|> put_status(401)
|> render("failure.html")
end
But I’d like to go back to the original create form and display it with all the values and the validation errors. Do I have to code this in the failure/3 function or is there an AshAuthentication switch which I can use for this?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #elixirconf-us
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Yes, you’d put the redirect in your
failure/3handler. I think the rendering offailure.htmlshould eventually be removed from the guide and the default behavior should be to redirect.wintermeyer
What is the best way to solve this? The following code doesn’t display the old values and doesn’t give the validation errors:
zachdaniel
The tooling clearly could use some improvement for the non-live view cases here.
@jimsynz might be able to help more than me. Does the
reasoncontain a failed form in this case? Or just the error from the form? Or perhaps theconncontains the failed form in the assigns?What you’d want to do ideally is reassigned the form that failed to submit. That would render errors and old values.
wintermeyer
How can I use this
reasonto assign the needed values to the new form?zachdaniel
I’m adding a new utility to
AshPhoenixto support this. Specifically, it will beAshPhoenix.Form.add_error(form, error).wintermeyer
Is there a way to add
reason.changesetto the form so that I at have the old values?zachdaniel
Oh, interesting. You can replace the form source, i.e
%{form | source: reason.changeset}zachdaniel
Oh, interesting. You can replace the form source, i.e
%{form | source: reason.changeset}. I’ve addedAshPhoenix.Form.add_error/3toash_phoenixmain that you can try as well.wintermeyer
I don’t understand that because this doesn’t work (because
formis not there):The error:
zachdaniel
Right, I was referring the form that you were creating manually
Form.for_create(User, :register_with_password, api: Accounts, as: "user")I think in your case, the best thing to do would be something like this: