trenpixster / addict

User management lib for Phoenix Framework
MIT License
645 stars 99 forks source link

Error on recovery submission #67

Open Lazarus404 opened 8 years ago

Lazarus404 commented 8 years ago

Hi,

So, I've got Addict set up nicely, but I've noticed an error occurs silently when calling /recover_password:

[error] #PID<0.352.0> running Pickpro.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /recover_password
** (exit) an exception was raised:
    ** (Plug.Conn.AlreadySentError) the response was already sent
        (plug) lib/plug/conn.ex:311: Plug.Conn.put_status/2
        lib/addict/interactors/session_interactor.ex:41: Addict.SessionInteractor.password_recover/2
        lib/addict/controller.ex:95: Addict.Controller.recover_password/2
        lib/addict/controller.ex:89: Addict.Controller.action/2
        lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
        (pickpro) lib/phoenix/router.ex:261: Pickpro.Router.dispatch/2
        (pickpro) web/router.ex:1: Pickpro.Router.do_call/2
        (pickpro) lib/pickpro/endpoint.ex:1: Pickpro.Endpoint.phoenix_pipeline/1
        (pickpro) lib/plug/debugger.ex:92: Pickpro.Endpoint."call (overridable 3)"/2
        (pickpro) lib/phoenix/endpoint/render_errors.ex:34: Pickpro.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

I'm using Phoenix 1.1 and I've forced the Ecto version to 1.1.1, so this might be the issue.

JoschkaSchulz commented 8 years ago

Could it be that it's because of the plug :action that is given in the addict controller? I had a similar problem with login. Maybe it's default in phoenix now?

Lazarus404 commented 8 years ago

It seems to be those email templates, again... It would be good to have a little write up on these. Perhaps explaining where to look so you know what parameters are made available to include in the templates. I think that should be sufficient.

Lazarus404 commented 8 years ago

So, tracking down the issue; in Addict.Mailers.MailSender.convert_to_list, this is returned:

[username: "lee@domain.com", type: "client", tel: "0234567890",
 sector: "Management",
 encrypted_password: "$pbkdf2-sha512$160000$VNuu8F9Mz9DglMpcAgdJBw$fbU349xWvlsioZEExDVCYSp1TqhEVQeVn4DtY4d3BD3rnYrXCL3oxqBz5ft8iwlRKupiYFJmlBjWYpVjPIoInA",
 email: "lee@domain.com", country: "NZ"]

but, the module errors with

[error] #PID<0.428.0> running Pickpro.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /register
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in EEx.Tokenizer.tokenize/5
        (eex) lib/eex/tokenizer.ex:27: EEx.Tokenizer.tokenize(#Function<20.50752066/0 in :erl_eval.expr/5>, 1, [trim: false], [], [])
        (eex) lib/eex/compiler.ex:16: EEx.Compiler.compile/2
        (eex) lib/eex.ex:191: EEx.eval_string/3
        lib/addict/mailers/mail_sender.ex:13: Addict.Mailers.MailSender.send_register/1

I'm gonna see if I can work out why, but any help appreciated. The template I'm using is just a string. It doesn't include any parameters whatsoever.

Thanks

trenpixster commented 8 years ago

@Lazarus404 can you please share the config piece at config.exs that sets the value for email_register_template and the source of what it is pointing at?

Here's my test run:

iex(1)> defmodule Foo do
...(1)> def template_register do
...(1)> "some simple string"
...(1)> end
...(1)> end
{:module, Foo,
 <<70, 79, 82, 49, 0, 0, 5, 20, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 140, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>,
 {:template_register, 0}}
iex(2)> payload = [username: "lee@domain.com", type: "client", tel: "0234567890", sector: "Management", encrypted_password: "$pbkdf2-sha512$160000$VNuu8F9Mz9DglMpcAgdJBw$fbU349xWvlsioZEExDVCYSp1TqhEVQeVn4DtY4d3BD3rnYrXCL3oxqBz5ft8iwlRKupiYFJmlBjWYpVjPIoInA", email: "lee@domain.com", country: "NZ"]
[username: "lee@domain.com", type: "client", tel: "0234567890",
 sector: "Management",
 encrypted_password: "$pbkdf2-sha512$160000$VNuu8F9Mz9DglMpcAgdJBw$fbU349xWvlsioZEExDVCYSp1TqhEVQeVn4DtY4d3BD3rnYrXCL3oxqBz5ft8iwlRKupiYFJmlBjWYpVjPIoInA",
 email: "lee@domain.com", country: "NZ"]
iex(3)> EEx.eval_string Foo.template_register, payload
"some simple string"
iex(4)>

Thanks!