Programming Phoenix (Pragprog)

Hello again guys,

This time I bring some questions regarding the charter 5 (authentication) I hope you could help to figure then out.

  1. Is the changes function (created at chapter 4) being used (called) in the registration_changeset function? if that’s true is the function cast being invoked 2 times? would be better (for performance at very low low level) just create registration_changeset function without using the changeset function and obviously putting its logic in the registration_changeset function?

  2. There is a point in the book where are updated all the users already presents in DB adding a password. why if all the passwords are being created using the same key the password_hash stored in DB is different in all cases/users?

  3. is correct the password_hash store in DB would be like this ‘$pbkdf2-sha512$160000$p1reFOXMlI1K1qplSHlNNg$/TLJ6ffDICFlwcvFkc0awRBkJXsV6d/DUYoy5QEv/PUAVLgM1kdt2qZQDhzoCck9pEm.gFeLltfx04qSi7SYlg’? including $pbkdf2-sha512$160000$ at the beginning of each one

  4. The final implementation of create function on user_controller

    #antes del cambio
    #case Accounts.create_user(user_params) do
    case Accounts.register_user(user_params) do
      {:ok, user} ->
        conn
        |> RumblWeb.Auth.login(user)
        |> put_flash(:info, "#{user.name} created!")
        |> redirect(to: Routes.user_path(conn, :index))

      {:error, %Ecto.Changeset{} = changeset} ->
        render(conn, "new.html", changeset: changeset)
    end
  end
type or paste code here

throws a warning calling RumblWeb.Auth.login function saying
RumblWeb.Auth.login/2

is undefined or private
why?

  1. Supposed I have several controllers and all of them needs user authentication, what would be the best way to use the authentication plug cross controller? in the route pipeline? How?

  2. Why the authentication plug was developed in the controller folder because as far as I understood is not a controller, in fact wonder why the login function was located in that module instead of being located anywhere else, maybe because it fits better in the controller layer?

Sorry for being so annoying, and thanks in advance to all of you