small medium large xlarge

13 Dec 2017, 21:55
Asterion (5 posts)

Running from iex as per Page 72 of book.

Getting Rumbl.User.struct/1 is undefined?

Mention of lists.mapfoldl/3?

iex 1.5.2

Dependencies: comeonin 2.6.0 connection 1.0.4 cowboy 1.1.2 cowlib 1.0.2 db_connection 1.1.2 decimal 1.4.1 ecto 2.2.7 file_system 0.2.2 gettext 0.13.1 mime 1.1.0 phoenix 1.3.0 phoenix_ecto 3.3.0 phoenix_html 2.10.5 phoenix_live_reload 1.1.3 phoenix_pubsub 1.0.2 plug 1.4.3 poison 3.1.0 poolboy 1.5.1 postgrex 0.13.3 ranch 1.3.2

I guess have to also admit, I seem to be able to insert users with passwords that are supposed to be too short - so no exceptions raised if password length <6??

Everything was fine up until I started working on Part 1.5 Authenticating Users. I have been block copying out of book so as to reduce typos. I have corrected code based upon hints in errata.

How best to backtrack this please? What is the likely place that the problem was injected if code worked as per up until Part 1.5?

24 Dec 2017, 14:47
Lee Sigauke (2 posts)

Can you post the whole error here? and Can I see your user.ex file?

31 Dec 2017, 02:15
Asterion (5 posts)

Many thanks Lee, the user.ex is as follows:

defmodule Rumbl.User do
    use Rumbl.Web, :model
    schema "users" do
        field :name, :string
        field :username, :string
        field :password, :string, virtual: true
        field :password_hash, :string


    def changeset(model, params \\ %{}) do
        |> cast(params, [:name, :username])
        |> validate_required([:name, :username])
        |> validate_length(:username, min: 1, max: 20)

    def registration_changeset(model, params) do
        |> changeset(params)
        |> cast(params, ~w(password))
        |> validate_required(:password)
        |> validate_length(:password, min: 6, max: 100)
        |> put_pass_hash()

    defp put_pass_hash(changeset) do
        case changeset do
            %Ecto.Changeset{valid?: true, changes: %{password: pass}} ->
                put_change(changeset, :password_hash, Comeonin.Bcrypt.hashpwsalt(pass))
            _ ->
31 Dec 2017, 02:13
Asterion (5 posts)

(CompileError) iex:2: Rumbl.User.struct/1 is undefined, cannot expand struct Rumbl.User (stdlib) lists.erl:1353: :lists.mapfoldl/3

Note the bold struct has two underline characters either side. The dopey blog takes them to mean boldtext.

You must be logged in to comment