riverrun / openmaize

No longer maintained - was an Authentication library for Plug-based applications in Elixir
Other
206 stars 30 forks source link

No function clause matching in Openmaize.Login.call #65

Closed johnhamelink closed 8 years ago

johnhamelink commented 8 years ago

Hey there!

When using the latest version of openmaize from hex - either in my own app or with the openmaize-phoenix-example, when I attempt to login I receive an error claiming that there's no function clause matching Openmaize.Login.call.

Here's the stacktrace which includes the function call that was attempted:

[error] #PID<0.367.0> running Welcome.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /sessions
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in Openmaize.Login.call/2
        (openmaize) lib/openmaize/login.ex:74: Openmaize.Login.call(%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{current_user: nil}, before_send: [#Function<0.7834419/1 in Plug.CSRFProtection.call/2>, #Function<4.13001795/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.82590416/1 in Plug.Session.before_send/2>, #Function<1.32426848/1 in Plug.Logger.call/2>, #Function<0.78287744/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>], body_params: %{"_csrf_token" => "bAQhOio5MQBxIC8AMjEHFmcbe1EdJgAA6+WWmlEKEdAzUSdP2u4hTg==", "_utf8" => "✓", "session" => %{"password" => "password", "username" => "johnhamelink"}}, cookies: %{"HFS_SID_" => "0.591043542139232", "_leasedv2_session" => "eVVsMXpML2kyemZYWk5Ka214OEtRRHpUZDVLOUpZeTVzSHJxT1RsMFowWkFpQ1grYys2b3NZVTZsYjRWMzIrd21tOWpZOWRwbW8wMHJLdmpGQVhvc1RJUnZLeEQzSlFpalIrY2xiaktVU1hJV2tXNTRyVWRDLzVFL3dKMnlGRXdsWlRqWkphL2pUYi9UYWl1MHRKTDhFakd2Tjd2WFVSdjRUK3ZRRHRGTHp6SzFtRG1pcUV1SCs2Ry9Td3lhcHFOV1BveEEwUE9MUldQQ2J1QXloZllKaU9rVDk0R1lVT2dieDdGNFZyd1FzSUhIRGJxS25IWDFmYVpac2hPa2lQQzZSRHZ5cHB2dVNOV0NUUUFXa0MreVZEVEJzMjc4aGJ6VDN4eWp6cm5DQVlqRFFBc0NHbHdlQnk4cDl1VkF0M0MwVk5NZU5SVzBmTWdROUtkNEZ0RkJYZzdrbDRaUHFLaStnZFdla3JPMG1FPS0taFpzZ1ZMSDlIejRNajRnYW5RWXBsdz09--a3d18892053b659ccc503c73d372d576266362ce", "_meditation_now_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYU2xUVHVYWEpCRU5rOXA3aUQxRy9Gdz09.SWD_rANEn-KbjwNb3XQdOFUFw4KtW53LTubom80kLe8", "_welcome_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYWi92bUdVdEs0RG56Z2JjRlVuTzlJQT09.4ZPb7-_QvUHDUHsljcJkZ_VQ1hMwShjrZQZNdKw_v-A", "expensifyAuthToken" => "AD99FD8049E7447E52B6C7B319C517837936CF5DA3C70B3F44402EB64E2EA0E35C12A2541069206ED591ADDB12D5E549411591D0D0E17455C6FC96BB0CE13C73343E2DFC0FF2D2AD0DDF04F018825FCFC9ECA09A17731F7CA77BB41CDA9FF1B35D3635AC63D9146455B160EFE23458EFE3DE90FD768194BCE218978E789E14FC", "gsScrollPos" => "", "undefined" => "1"}, halted: false, host: "localhost", method: "POST", owner: #PID<0.367.0>, params: %{"_csrf_token" => "bAQhOio5MQBxIC8AMjEHFmcbe1EdJgAA6+WWmlEKEdAzUSdP2u4hTg==", "_utf8" => "✓", "session" => %{"password" => "password", "username" => "johnhamelink"}}, path_info: ["sessions"], peer: {{127, 0, 0, 1}, 36392}, port: 4000, private: %{Welcome.Router => {[], %{}}, :phoenix_action => :create, :phoenix_controller => Welcome.SessionController, :phoenix_endpoint => Welcome.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {Welcome.LayoutView, :app}, :phoenix_pipelines => [:browser], :phoenix_route => #Function<10.116680344/1 in Welcome.Router.match_route/4>, :phoenix_router => Welcome.Router, :phoenix_view => Welcome.SessionView, :plug_session => %{"_csrf_token" => "Z/vmGUtK4DnzgbcFUnO9IA=="}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{"HFS_SID_" => "0.591043542139232", "_leasedv2_session" => "eVVsMXpML2kyemZYWk5Ka214OEtRRHpUZDVLOUpZeTVzSHJxT1RsMFowWkFpQ1grYys2b3NZVTZsYjRWMzIrd21tOWpZOWRwbW8wMHJLdmpGQVhvc1RJUnZLeEQzSlFpalIrY2xiaktVU1hJV2tXNTRyVWRDLzVFL3dKMnlGRXdsWlRqWkphL2pUYi9UYWl1MHRKTDhFakd2Tjd2WFVSdjRUK3ZRRHRGTHp6SzFtRG1pcUV1SCs2Ry9Td3lhcHFOV1BveEEwUE9MUldQQ2J1QXloZllKaU9rVDk0R1lVT2dieDdGNFZyd1FzSUhIRGJxS25IWDFmYVpac2hPa2lQQzZSRHZ5cHB2dVNOV0NUUUFXa0MreVZEVEJzMjc4aGJ6VDN4eWp6cm5DQVlqRFFBc0NHbHdlQnk4cDl1VkF0M0MwVk5NZU5SVzBmTWdROUtkNEZ0RkJYZzdrbDRaUHFLaStnZFdla3JPMG1FPS0taFpzZ1ZMSDlIejRNajRnYW5RWXBsdz09--a3d18892053b659ccc503c73d372d576266362ce", "_meditation_now_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYU2xUVHVYWEpCRU5rOXA3aUQxRy9Gdz09.SWD_rANEn-KbjwNb3XQdOFUFw4KtW53LTubom80kLe8", "_welcome_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYWi92bUdVdEs0RG56Z2JjRlVuTzlJQT09.4ZPb7-_QvUHDUHsljcJkZ_VQ1hMwShjrZQZNdKw_v-A", "expensifyAuthToken" => "AD99FD8049E7447E52B6C7B319C517837936CF5DA3C70B3F44402EB64E2EA0E35C12A2541069206ED591ADDB12D5E549411591D0D0E17455C6FC96BB0CE13C73343E2DFC0FF2D2AD0DDF04F018825FCFC9ECA09A17731F7CA77BB41CDA9FF1B35D3635AC63D9146455B160EFE23458EFE3DE90FD768194BCE218978E789E14FC", "gsScrollPos" => "", "undefined" => "1"}, req_headers: [{"host", "localhost:4000"}, {"connection", "keep-alive"}, {"content-length", "158"}, {"cache-control", "max-age=0"}, {"origin", "http://localhost:4000"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"}, {"content-type", "application/x-www-form-urlencoded"}, {"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}, {"dnt", "1"}, {"referer", "http://localhost:4000/sessions/new"}, {"accept-encoding", "gzip, deflate"}, {"accept-language", "en-GB,en;q=0.8,en-US;q=0.6"}, {"cookie", "_leasedv2_session=eVVsMXpML2kyemZYWk5Ka214OEtRRHpUZDVLOUpZeTVzSHJxT1RsMFowWkFpQ1grYys2b3NZVTZsYjRWMzIrd21tOWpZOWRwbW8wMHJLdmpGQVhvc1RJUnZLeEQzSlFpalIrY2xiaktVU1hJV2tXNTRyVWRDLzVFL3dKMnlGRXdsWlRqWkphL2pUYi9UYWl1MHRKTDhFakd2Tjd2WFVSdjRUK3ZRRHRGTHp6SzFtRG1pcUV1SCs2Ry9Td3lhcHFOV1BveEEwUE9MUldQQ2J1QXloZllKaU9rVDk0R1lVT2dieDdGNFZyd1FzSUhIRGJxS25IWDFmYVpac2hPa2lQQzZSRHZ5cHB2dVNOV0NUUUFXa0MreVZEVEJzMjc4aGJ6VDN4eWp6cm5DQVlqRFFBc0NHbHdlQnk4cDl1VkF0M0MwVk5NZU5SVzBmTWdROUtkNEZ0RkJYZzdrbDRaUHFLaStnZFdla3JPMG1FPS0taFpzZ1ZMSDlIejRNajRnYW5RWXBsdz09--a3d18892053b659ccc503c73d372d576266362ce; undefined=1; HFS_SID_=0.591043542139232; expensifyAuthToken=AD99FD8049E7447E52B6C7B319C517837936CF5DA3C70B3F44402EB64E2EA0E35C12A2541069206ED591ADDB12D5E549411591D0D0E17455C6FC96BB0CE13C73343E2DFC0FF2D2AD0DDF04F018825FCFC9ECA09A17731F7CA77BB41CDA9FF1B35D3635AC63D9146455B160EFE23458EFE3DE90FD768194BCE218978E789E14FC; gsScrollPos=; _meditation_now_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYU2xUVHVYWEpCRU5rOXA3aUQxRy9Gdz09.SWD_rANEn-KbjwNb3XQdOFUFw4KtW53LTubom80kLe8; _welcome_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYWi92bUdVdEs0RG56Z2JjRlVuTzlJQT09.4ZPb7-_QvUHDUHsljcJkZ_VQ1hMwShjrZQZNdKw_v-A"}], request_path: "/sessions", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "r346e80o59o0q8lfldi5idsnckpnrihr"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}], scheme: :http, script_name: [], secret_key_base: "NWubAA15egYxOBxjxQnkfHvUFus7nEanYQNWq0O+NKA1J+NcrhovPv/fUBh3RdMk", state: :unset, status: nil}, {Welcome.OpenmaizeEcto, :username})
        (welcome) web/controllers/session_controller.ex:1: Welcome.SessionController.phoenix_controller_pipeline/2
        (welcome) lib/welcome/endpoint.ex:1: Welcome.Endpoint.instrument/4
        (welcome) lib/phoenix/router.ex:261: Welcome.Router.dispatch/2
        (welcome) web/router.ex:1: Welcome.Router.do_call/2
        (welcome) lib/welcome/endpoint.ex:1: Welcome.Endpoint.phoenix_pipeline/1
        (welcome) lib/plug/debugger.ex:123: Welcome.Endpoint."call (overridable 3)"/2
        (welcome) lib/welcome/endpoint.ex:1: Welcome.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
riverrun commented 8 years ago

Thanks for letting me know. I'll look into it as soon as I can.

riverrun commented 8 years ago

I've just pushed version 2.1.3 to hex. Can you let me know if that fixes the issue?

johnhamelink commented 8 years ago

@riverrun I'm now getting a different error:

[info] POST /sessions
[debug] Processing by MeditationNow.SessionController.create/2
  Parameters: %{"_csrf_token" => "Gx0lOwAyaiMLPRQ+dzNtIAZ1D2AXJgAAHqqouj2iIxZUNCZIBDHOQQ==", "_utf8" => "✓", "session" => %{"password" => "[FILTERED]", "username" => "johnhamelink"}}
  Pipelines: [:browser]
[debug] QUERY OK source="users" db=1.7ms decode=2.6ms
SELECT u0."id", u0."username", u0."email", u0."password_hash", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."username" = $1) ["johnhamelink"]
[info] Sent 500 in 49ms
[error] #PID<0.393.0> running MeditationNow.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /sessions
** (exit) an exception was raised:
    ** (ArgumentError) Wrong type. The password and hash need to be strings.
        (comeonin) lib/comeonin/bcrypt.ex:122: Comeonin.Bcrypt.checkpw/2
        (openmaize) lib/openmaize/login.ex:99: Openmaize.Login.check_pass/3
        (openmaize) lib/openmaize/login.ex:85: Openmaize.Login.call/2
        (meditation_now) web/controllers/session_controller.ex:1: MeditationNow.SessionController.phoenix_controller_pipeline/2
        (meditation_now) lib/meditation_now/endpoint.ex:1: MeditationNow.Endpoint.instrument/4
        (meditation_now) lib/phoenix/router.ex:261: MeditationNow.Router.dispatch/2
        (meditation_now) web/router.ex:1: MeditationNow.Router.do_call/2
        (meditation_now) lib/meditation_now/endpoint.ex:1: MeditationNow.Endpoint.phoenix_pipeline/1
        (meditation_now) lib/plug/debugger.ex:123: MeditationNow.Endpoint."call (overridable 3)"/2
        (meditation_now) lib/meditation_now/endpoint.ex:1: MeditationNow.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
johnhamelink commented 8 years ago

:point_up: That is because password_hash is nil when registration happens.

This is because it seems like https://github.com/riverrun/openmaize/blob/master/priv/templates/phoenixauth/user_controller.ex#L24 didn't make it into the last release.

riverrun commented 8 years ago

I think the problem is line 31, which should be changeset = User.auth_changeset(%User{}, user_params). I'll have a fix ready later today.

riverrun commented 8 years ago

Just released version 2.1.4. In your case, just change line 21 of the user_controller file from User.changeset to User.auth_changeset -- I'm presuming that your ran mix openmaize.gen.phoenixauth without the confirm option. Let me know how you get on.

johnhamelink commented 8 years ago

@riverrun Thanks, looks good :smile: