trenpixster / addict Goto Github PK
View Code? Open in Web Editor NEWUser management lib for Phoenix Framework
License: MIT License
User management lib for Phoenix Framework
License: MIT License
Is there a way to adapt this for channel authentication? Maybe this would be easier if it was just storing a session token on the client, so I'm considering overriding the SessionInteractor's login / logout methods.
It'd be great to be able to auto-populate a Phoenix project with sensitive defaults through a mix task.
Something like
mix addict.gen.user
would generate the minimum bares user model.mix addict.gen.email_templates
would generate the minimum bares email templates.One added plus would be to do this in the project's namespace and also add the required keys to config.exs
.
In an effort to further look into both parameter sanitization at the controller level and validations at the model level, I had some discussions with José about changesets and they seem to be the way forward. His original proposal is outlined here and it has since been implemented into ecto (master). This is coupled with phoenix master as well which will be released as 0.10
this weekend (per chrismccord).
My proposal is to created Addict.User
that is use
ed in a developer-specified user model that adds the various changeset
functions (see José's proposal) we need to validate parameters in AddictController
. These changeset
functions will also provide direct tie in with validations for both predefined and custom validations as well. Two birds; one stone. 😄
Documentation for ecto changesets can be found here.
Any thoughts on this approach?
Ok, I have the everything up and running until the forms (also following the example you provide). When I click the buttons to submit a request I get a CSRF error.
On the browser console it says:
POST http://localhost:4000/register 403 (Forbidden)
send @ jquery.js:8630
ajax @ jquery.js:8166
jQuery.each.jQuery.(anonymous function) @ jquery.js:8311
(anonymous function) @ (index):110
dispatch @ jquery.js:4435
jQuery.event.add.elemData.handle @ jquery.js:4121
And also:
XHR finished loading: POST "http://localhost:4000/register".
send @ jquery.js:8630
ajax @ jquery.js:8166
jQuery.each.jQuery.(anonymous function) @ jquery.js:8311
(anonymous function) @ (index):110
dispatch @ jquery.js:4435
jQuery.event.add.elemData.handle @ jquery.js:4121
On my console I have:
** (exit) an exception was raised:
** (Plug.CSRFProtection.InvalidCSRFTokenError) invalid CSRF (Cross Site Forgery Protection) token, make sure all requests include a '_csrf_token' param or an 'x-csrf-
token' header
(plug) lib/plug/csrf_protection.ex:132: Plug.CSRFProtection.call/2
(loginSystem) web/router.ex:5: LoginSystem.Router.browser/2
(loginSystem) web/router.ex:1: LoginSystem.Router.do_call/2
(loginSystem) lib/loginSystem/endpoint.ex:1: LoginSystem.Endpoint.phoenix_pipeline/1
(loginSystem) lib/plug/debugger.ex:90: LoginSystem.Endpoint."call (overridable 3)"/2
(loginSystem) lib/phoenix/endpoint/render_errors.ex:34: LoginSystem.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
== Compilation error on file web/views/page_view.ex ==
** (CompileError) web/views/page_view.ex:2: module Ataca.Router.Helpers is not loaded and could not be found
(ataca) expanding macro: Ataca.Web.using/1
web/views/page_view.ex:2: Ataca.PageView (module)
(elixir) expanding macro: Kernel.use/2
web/views/page_view.ex:2: Ataca.PageView (module)
(elixir) lib/kernel/parallel_compiler.ex:100: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/8
Is there a way to have backdoor auth for a testing suite?
I'm new to Elixir so I'm probably doing something wrong, but I cant get registrations working.
I have tried a eex form and the ajax form but keep getting:
Request: POST /register ** (exit) an exception was raised: ** (ErlangError) erlang error: {:nocatch, "Unable to create user, invalid hash. Required params: email, password, username"}
But it seems like it should work?
[info] POST /register [debug] Processing by Addict.Controller.register/2 Parameters: %{"email" => "[email protected]", "password" => "[FILTERED]", "username" => "johndoe"} Pipelines: []
This is my Schema:
schema "users" do
field :first_name, :string
field :last_name, :string
field :username, :string
field :email, :string
field :subdomain, :string
field :custom_domain, :string
field :hash, :string
field :recovery_hash, :string
has_many :posts, Agentport.Post
has_many :testimonials, Agentport.Testimonial
timestamps
end
@required_fields ~w(username email hash recovery_hash timestamps)
@optional_fields ~w(first_name last_name, subdomain, custom_domain)
The only thing I can think of is that I had trouble installing addict due to conflicting requirements on ecto so I had to add {:ecto, "~> 1.0.0", override: true},
to get it to install. Could this be the issue?
Hi,
I'm new to addict and relatively new to Phoenix and Elixir as well, so I might have done something wrong on my end, but I'm seeing an error immediately upon visiting the "/login" and "/register" pages. Here's the error:
[error] #PID<0.336.0> running Email.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /login
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function Email.Addict.AddictController.init/1 (module Email.Addict.AddictController is not available)
Email.Addict.AddictController.init(:login)
(Email) web/router.ex:1: anonymous fn/1 in Email.Router.match_route/4
(Email) lib/phoenix/router.ex:261: Email.Router.dispatch/2
(Email) web/router.ex:1: Email.Router.do_call/2
(Email) lib/email/endpoint.ex:1: Email.Endpoint.phoenix_pipeline/1
(Email) lib/plug/debugger.ex:93: Email.Endpoint."call (overridable 3)"/2
(Email) lib/phoenix/endpoint/render_errors.ex:34: Email.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
With pipe_while_ok
from exlibris the flow can be redone in some points where we can avoid the message proxying when an :error
occurs.
I'd like to replace pipe_while_ok
with a better name though 😄
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.
I get the following error:
➜ addict_demo git:(master) ✗ mix addict.generate.configs
[x] Please remove the existing Addict configuration before generating a new one
[o] Done!
It looks like addict_config_already_exists?
needs a little more logic.
Hello! Thanks for creating Addict, it's great :)
I'm following the example app, but when it comes to the log out link, it's done with JavaScript (it sends the request and then redirects with JS). I want to do it directly, so that the response from the server is the redirect.
I started with the link on the layout:
<%= link "Log out", to: logout_path(@conn, :logout), method: :post %>
This works, but then all we see is an empty "{}" response on the browser. So, I use the post actions to put a flash and redirect, like this:
# config.exs
config :addict,
...
post_logout: &MyApp.AddictPostActions.post_logout/3
# addict_post_actions.ex
defmodule MyApp.AddictPostActions do
import Phoenix.Controller, only: [put_flash: 3, redirect: 2]
alias MyApp.Router.Helpers
def post_logout(conn, status, model) do
conn
|> put_flash(:ok, "Bye!")
|> redirect(to: Helpers.page_path(conn, :index))
end
end
And this almost works, but I get this error and a "You are being redirected" message is shown in the browser.
[error] #PID<0.384.0> running MyApp.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /logout
** (exit) an exception was raised:
** (Plug.Conn.AlreadySentError) the response was already sent
(plug) lib/plug/conn.ex:458: Plug.Conn.resp/3
(plug) lib/plug/conn.ex:445: Plug.Conn.send_resp/3
lib/addict/controller.ex:1: Addict.AddictController.action/2
lib/addict/controller.ex:1: Addict.AddictController.phoenix_controller_pipeline/2
(rocket) lib/phoenix/router.ex:261: MyApp.Router.dispatch/2
(rocket) web/router.ex:1: MyApp.Router.do_call/2
(rocket) lib/rocket/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
(rocket) lib/plug/debugger.ex:93: MyApp.Endpoint."call (overridable 3)"/2
(rocket) lib/phoenix/endpoint/render_errors.ex:34: MyApp.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
How can this be done?
I have been searching for forever to find those functions. I think their usage is very frequent, so it would be great if they could be mentioned in the Readme.
I've installed addict on clean new phoenix app. When trying to log in with incorrect data app responses with '500' error and this log:
Request: POST /login
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function Mix.Utils.camelize/1 (module Mix.Utils is not available)
Mix.Utils.camelize("authentication")
(addict) lib/addict/controller.ex:137: anonymous fn/1 in Addict.AddictController.return_error/3
(elixir) lib/enum.ex:1088: Enum."-map/2-lists^map/1-0-"/2
(addict) lib/addict/controller.ex:136: Addict.AddictController.return_error/3
(addict) lib/addict/controller.ex:1: Addict.AddictController.action/2
(addict) lib/addict/controller.ex:1: Addict.AddictController.phoenix_controller_pipeline/2
(blog_phoenix) lib/phoenix/router.ex:261: BlogPhoenix.Router.dispatch/2
(blog_phoenix) web/router.ex:1: BlogPhoenix.Router.do_call/2
How can I properly handle it?
I tried installing addict in my Phoenix Project however I'm getting an error.
I tried the exact same process on a colleague's Mac OS X and he does not get the error, while I on Windows do.
The error comes from the comeonin dependency. I've also tried it in both Phoenix 0.14 and the 0.15 update that was released yesterday.
Steps to recreate:
$ mix phoenix.new testAddict
$ cd testAddict
$ mix ecto.create
$ mix phoenix.server
defp deps do [{:phoenix, "~> 0.15"}, {:phoenix_ecto, "~> 0.8"}, {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 1.4"}, {:phoenix_live_reload, "~> 0.5", only: :dev}, {:addict, "~> 0.0.5"}, {:cowboy, "~> 1.0"}] end
Compile dependencies:
$ mix deps.get
Results:
Running dependency resolution
Dependency resolution completed successfully
addict: v0.0.5
comeonin: v0.11.3
mailgun: v0.0.2
* Getting addict (Hex package)
Checking package (https://s3.amazonaws.com/s3.hex.pm/tarballs/addict-0.0.5.tar)
Using locally cached package
Unpacked package tarball (c:/Users/mesos_000/.hex/packages/addict-0.0.5.tar)
* Getting mailgun (Hex package)
Checking package (https://s3.amazonaws.com/s3.hex.pm/tarballs/mailgun-0.0.2.tar)
Using locally cached package
Unpacked package tarball (c:/Users/mesos_000/.hex/packages/mailgun-0.0.2.tar)
* Getting comeonin (Hex package)
Checking package (https://s3.amazonaws.com/s3.hex.pm/tarballs/comeonin-0.11.3.tar)
Using locally cached package
Unpacked package tarball (c:/Users/mesos_000/.hex/packages/comeonin-0.11.3.tar)
Run Phoenix project again:
$ mix phoenix.server
Results (here's the error):
==> mailgun
Compiled lib/mailgun.ex
Compiled lib/client.ex
Generated mailgun app
==> comeonin
could not compile dependency comeonin, mix compile failed. You can recompile this dependency with `mix deps.compile comeonin` or update it with `mix deps.update comeonin`
** (ErlangError) erlang error: :enoent
(elixir) lib/system.ex:440: System.cmd("nmake", ["/F", "Makefile.win", "priv\\bcrypt_nif.dll"], [stderr_to_stdout: true])
mix.exs:15: Mix.Tasks.Compile.Comeonin.run/1
(elixir) lib/enum.ex:977: anonymous fn/3 in Enum.map/2
(elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:977: Enum.map/2
(mix) lib/mix/tasks/compile.all.ex:15: Mix.Tasks.Compile.All.run/1
(mix) lib/mix/tasks/compile.ex:64: Mix.Tasks.Compile.run/1
(mix) lib/mix/tasks/deps.compile.ex:105: anonymous fn/2 in Mix.Tasks.Deps.Compile.do_mix/1
Attempt suggestions:
$ mix deps.compile comeonin
Results:
Running dependency resolution
Dependency resolution completed successfully
comeonin: v0.11.3
$ mix phoenix.server
Result: same error as above.
$ mix deps.update comeonin
Results:
==> comeonin
could not compile dependency comeonin, mix compile failed. You can recompile this dependency with `mix deps.compile comeonin` or update it with `mix deps.update comeonin`
** (ErlangError) erlang error: :enoent
(elixir) lib/system.ex:440: System.cmd("nmake", ["/F", "Makefile.win", "priv\\bcrypt_nif.dll"], [stderr_to_stdout: true])
mix.exs:15: Mix.Tasks.Compile.Comeonin.run/1
(elixir) lib/enum.ex:977: anonymous fn/3 in Enum.map/2
(elixir) lib/enum.ex:1261: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:977: Enum.map/2
(mix) lib/mix/tasks/compile.all.ex:15: Mix.Tasks.Compile.All.run/1
(mix) lib/mix/tasks/compile.ex:64: Mix.Tasks.Compile.run/1
(mix) lib/mix/tasks/deps.compile.ex:105: anonymous fn/2 in Mix.Tasks.Deps.Compile.do_mix/1
It would be nice if addict would support activating an user account by a confirmation link.
Your documentation says to put this in your configuration file:
post_login: &MyApp.PostLoginAction.log/3
This type of configuration won't work with exrm releases. You should change your implementation to use the following format:
post_login: {MyApp.PostLoginAction, :log}
and use the following to run the callback:
{mod, fun} = Application.get_env :addict, :post_login
apply mod, fun, [arg1, arg2, arg3]
I've been burned with this probably a few times....
So, actions like /register take appropriate database effect, but explode trying to return a json response with the aforementioned error.
Unfortunately the Poison error thrown gives a stacktrace that's very unhelpful! So I rather have to guess that this is happening in Addict.Controller
's register
code when it tries to call json conn, message
, as this happens with default addict routes handling the /register
POST:
[info] POST /register
[debug] Processing by Addict.Controller.register/2
Parameters: %{"_csrf_token" => "QDFUHx4yDgxVF3tCHwVaHzBzQVMZEAAApe6hzuyNfdC8MlhEBKr4Jw==", "email" => "[email protected]", "format" => "html", "password" => "[FILTERED]", "username" => "mrluc"}
Pipelines: [:browser]
[debug] BEGIN [] OK query=0.4ms
[debug] INSERT INTO "users" ("email", "hash", "inserted_at", "recovery_hash", "updated_at", "username") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" ["[email protected]", "$pbkdf2-sha512$60000$Aji.Gc/s3A7oiM/TWWH3WA$E7eill52.Jg7KMhYifgOW0ZXG/A8mebWrlsfaHyM14WdDhSa9yEDAN6C6UFpikGYsUMpH74WcpMNwE6jGUVOGw", {{2015, 8, 14}, {23, 17, 4, 0}}, nil, {{2015, 8, 14}, {23, 17, 4, 0}}, "mrluc"] OK query=0.9ms
[debug] COMMIT [] OK query=6.4ms
[info] Sent 500 in 968ms
[error] #PID<0.490.0> running Flashbang.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /register
** (exit) an exception was raised:
** (Poison.EncodeError) unable to encode value: {nil, "users"}
(poison) lib/poison/encoder.ex:213: Poison.Encoder.Any.encode/2
(poison) lib/poison/encoder.ex:156: anonymous fn/4 in Poison.Encoder.Map.encode/2
(stdlib) lists.erl:1261: :lists.foldl/3
(poison) lib/poison/encoder.ex:157: Poison.Encoder.Map.encode/2
(poison) lib/poison/encoder.ex:156: anonymous fn/4 in Poison.Encoder.Map.encode/2
(stdlib) lists.erl:1261: :lists.foldl/3
(poison) lib/poison/encoder.ex:157: Poison.Encoder.Map.encode/2
(poison) lib/poison/encoder.ex:156: anonymous fn/4 in Poison.Encoder.Map.encode/2
Since when generating via Phoenix's mix task the forms send data enclosed in a user
, it'd be nice for controllers to accept this format so that no overriding is required by the developer.
I am integrate addict to my existing project and figure out authorization isn't trigger by form action but js.
I can simply copy & paste those css & js to my existing file, or change js to form action, but still, I think move those code into separate file under static web is more appropriate.
Required validations for the User model:
email
username
Referenced here: elixir-ecto/ecto#840
The User
struct returned from the Repo contains a tuple, which Poison can't encode:
%AppName.User{__meta__: %Ecto.Schema.Metadata{source: {nil, "users"}, state: :loaded}}
Could convert with Tuple.to_list/1
but as José suggested on ecto/840, should we even be sending __meta__
down the pipe to the client?
Creating an issue to better track updates to this TODO.
Seeing how you envision the pieces fitting together would be greatly appreciated!
The pre-made controller tests that Phoenix generates will break when you add authentication using Addict.
How can I log in the conn
before doing these tests?
I believe that this is very valuable information to put in the Readme.
The app is appropriately configured:
iex>iex(5)> Mix.Config.read! "config/config.exs"
...
addict: [not_logged_in_url: "/error", db: Flashbang.Repo, user: Flashbang.User,
...
And this config appears to be getting to Addict.Repository
:
iex(1)> Application.get_env :addict, :user
Flashbang.User
However, when following instructions to POST to the /register
route, I get the following:
[info] POST /register
[debug] Processing by Addict.Controller.register/2
Parameters: %{"_csrf_token" => "ZmAVDy0sA3VfBV0bKyJRFCNtBCllEAAAV4wxIkt7lveayKcNQU7N6w==", "email" => "[email protected]", "format" => "html", "password" => "[FILTERED]", "username" => "h"}
Pipelines: [:browser]
[info] Sent 500 in 197ms
[error] #PID<0.311.0> running Flashbang.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /register
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function: MyApp.MyUser.__struct__/0 (module MyApp.MyUser is not available)
MyApp.MyUser.__struct__()
(elixir) lib/kernel.ex:1503: Kernel.struct/2
lib/addict/repository.ex:22: Addict.Repository.create/1
lib/addict/interactors/addict_manager_interactor.ex:161: Addict.ManagerInteractor.create/4
lib/addict/controller.ex:95: Addict.Controller.register/2
lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
(flashbang) lib/phoenix/router.ex:265: Flashbang.Router.dispatch/2
(flashbang) web/router.ex:1: Flashbang.Router.do_call/2
Any ideas where the MyApp.MyUser reference is coming from? I git-grepped for it and it's not in my project, and as shown above addict's configuration seems to be correct...
Addict should integrate with Linguist to be able to support custom languages besides english
(I will look into this later)
I'm very new to elixir, phoenix and addict, so maybe it's a dumb question.
I created new app, added 'addict', configured it all properly - everything works well locally.
Now I want to deploy my app, so I'm running mix release
. First time I did it, I faced this error:
Cannot add file sys.config to tar file - [{error,{83,erl_parse,["syntax error before: ",["Fun"]]}}]
===> Provider (tar) failed with: {error,
{rlx_prv_archive,
{tar_unknown_generation_error,
"blog_phoenix","0.0.1"}}}
I checked sys.config file and found that it fails on this line of config.exs:
extra_validation: fn ({valid, errors}, user_params) -> {valid, errors} end,
It's being converted to this content in sys.config:
{extra_validation,#Fun<erl_eval.12.50752066>}
Then I found configs.md here and tried to replace this: extra_validation: fn ({valid, errors}, user_params) -> {valid, errors} end
with this: extra_validation: BlogPhoenix.User.validation
Of course I added this to my User model:
def validate({valid, errors}, user_params), do: {valid, errors}
Now 'mix release' fails with undefined function BlogPhoenix.User.validate/0 (module BlogPhoenix.User is not available)
.
Do you have any idea how to fix it and why initial code didn't worked at all?
$ mix phoenix.routes
register_path POST /register Addict.AddictController :register
register_path GET /register Addict.AddictController :register
login_path POST /login Addict.AddictController :login
login_path GET /login Addict.AddictController :login
logout_path POST /logout Addict.AddictController :logout
logout_path GET /logout Addict.AddictController :logout
recover_password_path POST /recover_password Addict.AddictController :recover_password
recover_password_path GET /recover_password Addict.AddictController :recover_password
reset_password_path POST /reset_password Addict.AddictController :reset_password
reset_password_path GET /reset_password Addict.AddictController :reset_password
Attempting to use the logout_path like so: link "Logout", to: logout_path(@conn, :logout)
will fail with an error.
Just a bug tracking oauth2 server support. Not sure if it is in scope.
We should delegate all the methods that deal with session to a separate Module who's only concern would be to handle sessions, and another for handling Hashing specificities.
I'd leave status
codes and "render
" requirements on the controller.
Currently, addict depends on:
{:phoenix, ">= 0.8.0"}
{:ecto, ">= 0.6.0"}
While current version of those packages are:
{:phoenix, ">= 0.10.0"}
{:ecto, ">= 0.9.0"}
I suggest to update the dependencies.
Love this project, thanks so much! This may be out of scope of Addict; I'm adding it as an issue to help others who run into it.
Walking through the readme
setup guide, I encountered an error when attempting to create an account on the /register
route.
Error:
[error] #PID<0.976.0> running Workshop.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /register
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
(elixir) lib/io.ex:346: IO.chardata_to_string(nil)
(elixir) lib/path.ex:467: Path.join/2
(elixir) lib/path.ex:449: Path.join/1
lib/client.ex:44: Mailgun.Client.send_without_attachments/2
lib/addict/mailers/mailgun.ex:11: Addict.Mailers.Mailgun.send_email/4
lib/addict/interactors/register.ex:26: Addict.Interactors.Register.do_register/2
lib/addict/controller.ex:16: Addict.AddictController.register/2
lib/addict/controller.ex:1: Addict.AddictController.action/2
lib/addict/controller.ex:1: Addict.AddictController.phoenix_controller_pipeline/2
(workshop) lib/phoenix/router.ex:261: Workshop.Router.dispatch/2
(workshop) web/router.ex:1: Workshop.Router.do_call/2
(workshop) lib/workshop/endpoint.ex:1: Workshop.Endpoint.phoenix_pipeline/1
(workshop) lib/plug/debugger.ex:93: Workshop.Endpoint."call (overridable 3)"/2
(workshop) lib/phoenix/endpoint/render_errors.ex:34: Workshop.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
Steps to reproduce:
/register/
endpoint and create an account. Server throws a 500.[warning] Repo.insert/2 is deprecated, please use Repo.insert!/2 instead
lib/addict/repository.ex:22: Addict.Repository.create/1
lib/addict/interactors/addict_manager_interactor.ex:161: Addict.ManagerInteractor.create/4
lib/addict/controller.ex:95: Addict.Controller.register/2
lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
Generated app through mix phoenix.new
, followed Addict setup instructions.
POSTing to /register
:
Request: POST /register
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function: nil.__struct__/0
nil.__struct__()
(elixir) lib/kernel.ex:1503: Kernel.struct/2
lib/addict/repository.ex:22: Addict.Repository.create/1
lib/addict/interactors/addict_manager_interactor.ex:161: Addict.ManagerInteractor.create/4
lib/addict/controller.ex:95: Addict.Controller.register/2
lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
(bacro) lib/phoenix/router.ex:265: Bacro.Router.dispatch/2
(bacro) web/router.ex:1: Bacro.Router.do_call/2
POSTing to /login
:
Request: POST /login
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function: nil.__schema__/1
nil.__schema__(:source)
lib/addict/repository.ex:74: Addict.Repository.find_by_email/1
lib/addict/interactors/addict_manager_interactor.ex:161: Addict.ManagerInteractor.verify_password/4
lib/addict/controller.ex:95: Addict.Controller.login/2
lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
(bacro) lib/phoenix/router.ex:265: Bacro.Router.dispatch/2
(bacro) web/router.ex:1: Bacro.Router.do_call/2
(bacro) lib/bacro/endpoint.ex:1: Bacro.Endpoint.phoenix_pipeline/1
config.exs
config :addict, not_logged_in_url: "/error",
db: Bacro.Repo,
user: Bacro.User,
register_from_email: "Registration <[email protected]>",
register_subject: "Welcome to yourawesomeapp!",
password_recover_from_email: "Password Recovery <[email protected]>",
password_recover_subject: "You requested a password recovery link",
email_templates: Bacro.Presenters.EmailPresenter
router.ex
defmodule Bacro.Router do
use Bacro.Web, :router
use Addict.RoutesHelper
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", Bacro do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
get "/auth/register", AuthController, :register
end
scope "/" do
addict :routes
end
end
$ mix phoenix.routes
page_path GET / Bacro.PageController :index
auth_path GET /auth/register Bacro.AuthController :register
register_path POST /register Addict.Controller :register
login_path POST /login Addict.Controller :login
logout_path POST /logout Addict.Controller :logout
recover_password_path POST /recover_password Addict.Controller :recover_password
reset_password_path POST /reset_password Addict.Controller :reset_password
mix.lock
%{"addict": {:hex, :addict, "0.0.5"},
"comeonin": {:hex, :comeonin, "0.11.3"},
"cowboy": {:hex, :cowboy, "1.0.2"},
"cowlib": {:hex, :cowlib, "1.0.1"},
"decimal": {:hex, :decimal, "1.1.0"},
"ecto": {:hex, :ecto, "0.14.3"},
"fs": {:hex, :fs, "0.9.2"},
"mailgun": {:hex, :mailgun, "0.0.2"},
"phoenix": {:hex, :phoenix, "0.15.0"},
"phoenix_ecto": {:hex, :phoenix_ecto, "0.8.1"},
"phoenix_html": {:hex, :phoenix_html, "1.4.0"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "0.5.1"},
"plug": {:hex, :plug, "0.14.0"},
"poison": {:hex, :poison, "1.4.0"},
"poolboy": {:hex, :poolboy, "1.5.1"},
"postgrex": {:hex, :postgrex, "0.9.1"},
"ranch": {:hex, :ranch, "1.1.0"}}
I'm new to Elixir and Phoenix, so let me know if there is anything else helpful that I can attach.
Hi,
Comeonin is now at version 1.1. There have been lots of changes, including more helpful build messages, and I recommend you update it.
At least for me, I'm getting this behavior; it causes the last stage in registration, sending user email, to explode with:
(UndefinedFunctionError) undefined function: :ok.username/1 (module :ok is not available)
:ok.username({:ok, %Flashbang.User{__meta__: %Ecto.Schema.Metadata{source: {nil, "users"}, state: :loaded}, email: "az", hash: "$pbkdf2-sha512$60000$tv82nurn18WwchXaLHdxhg$qDPWQVlr/lg3WQznHCms84CL/Oek8VQ93whhznVkyt6Qm.rlQPB4YA2JjLdKk.Vo8LSheUibSrkKSJ1KjSwGtw", id: 3, inserted_at: #Ecto.DateTime<2015-08-14T22:27:01Z>, recovery_hash: nil, updated_at: #Ecto.DateTime<2015-08-14T22:27:01Z>, username: "z"}})
lib/addict/email_gateway.ex:7: Addict.EmailGateway.send_welcome_email/2
lib/addict/interactors/addict_manager_interactor.ex:162: Addict.ManagerInteractor.send_welcome_email/2
lib/addict/controller.ex:95: Addict.Controller.register/2
lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
(flashbang) lib/phoenix/router.ex:265: Flashbang.Router.dispatch/2
(flashbang) web/router.ex:1: Flashbang.Router.do_call/2
(flashbang) lib/flashbang/endpoint.ex:1: Flashbang.Endpoint.phoenix_pipeline/1
After digging a bit I believe a recent commit that touched Addict.Repository.create
caused this.
Hi,
It would be good to get further explanation of the new email template requirements. I've upgraded from 0.1 and now nothing quite works. I've had to put the templates directly in the config, as the modules aren't found at the time of the config parsing. Also, adding <%= email %> raises a token error:
** (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:11: Addict.Mailers.MailSender.send_register/1
as though email isn't known when parsing the template. Any ideas?
Thanks,
Lee
It seems that the user model is not being set from the configuration.
This is my config
# Configure Addict
config :addict, not_logged_in_url: "/error",
db: Hello.Repo,
user: Hello.User,
....
And whenever I try the login route I get:
Request: POST /login
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function: nil.__schema__/1
nil.__schema__(:source)
lib/addict/repository.ex:74: Addict.Repository.find_by_email/1
Any clues?
Much appreciated!
And again it's me who is not familiar with Phoenix :)
I'm wondering why addict's generator puts css/js files right in priv/static/{css,js} ? As far as I can see, this folder is mentioned in .gitignore for many projects. Say if I'm cooperating with my friend via git, only one of us will have assets files by default. It doesn't seem to be a correct behavior, but maybe I'm wrong about something.
Does addict support allowing email address to be the user's username? Can I override the username field or should I just both fields equal to the user's email address for now?
HI,
I am using addict with Phoenix: 1.0.3, I have followed README guide to use login in my app. I am getting following error when I make a call to login:
[error] #PID<0.2576.0> running MyApp.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /login
** (exit) an exception was raised:
** (UndefinedFunctionError) undefined function: MyApp.Addict.Controller.init/1 (module MyApp.Addict.Controller is not available)
MyApp.Addict.Controller.init(:login)
(my_app) web/router.ex:1: anonymous fn/1 in MyApp.Router.match/4
(my_app) lib/phoenix/router.ex:255: MyApp.Router.dispatch/2
(my_app) web/router.ex:1: MyApp.Router.do_call/2
(my_app) lib/my_app/endpoint.ex:1: MyApp.Endpoint.phoenix_pipeline/1
(my_app) lib/plug/debugger.ex:90: MyApp.Endpoint."call (overridable 3)"/2
(my_app) lib/phoenix/endpoint/render_errors.ex:34: MyApp.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
Followed the directions for setup and am getting this error. Any ideas?
** (UndefinedFunctionError) undefined function: Myapp.Addict.Controller.init/1 (module Myapp.Addict.Controller is not available)
Thanks,
Jon
I plan on implementing this sooner or later for an app I'm building. Please assign this to me.
Hello, according to the documentation,
Addict by default validates that the password is at least 6 characters long and the e-mail is valid and unique.
But, out of the box, it does not validate the uniqueness of the email. It lets me insert 2 users with the same email.
Now, if I add a unique index on the database table with create unique_index(:users, [:email])
, I prevent that from happening at the database layer, but the DB error is not converted to a changeset error as unique_constraint
is supposed to do, a 500 internal server error is raised.
My user model has multiple associations on it and apparently breaks in the SessionInteractor when trying to render JSON because the associations are not loaded. I would like a way to configure the attributes to send with the user instead of just removing a few attributes in the sanitize_user method.
Hi, I find addict very useful, but had difficulties setting it up. To enhance the experience for new developers I want to add to the documentation (i.e. README). To start I need to clarify the following:
Otherwise great work, I will start some discussions on ideas I have ;-).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.