插入重复的数据

时间:2015-09-11 10:36:00

标签: phoenix-framework

我试图根据Guardian软件包为Phoenix制作一个身份验证系统。除了当我创建一个新用户(注册)用户被插入两次时,几乎所有东西都没问题:

skeleton_dev=# Select * from users;
 id | name |   email   |                      encrypted_password                      | password |     inserted_at     |     updated_at      
----+------+-----------+--------------------------------------------------------------+----------+---------------------+---------------------
  1 | pj   | pj@pj.com | $2b$12$M2WNdw5mJkUzirwbReKT0ux1HgLFcouq.SEOWEz5dDswCWI4i/uoW |          | 2015-09-11 09:55:08 | 2015-09-11 09:55:08
  2 | pj   | pj@pj.com | $2b$12$zqHStaEXNwpVoyg8StYwT.U3BEOyZDq1tsTIA.cjzlZYsuwzL4e7u |          | 2015-09-11 09:55:09 | 2015-09-11 09:55:09
(2 rows)

我认为问题必须在控制器中,但我找不到任何奇怪的事情:

  def new(conn, _params) do
    changeset = User.create_changeset(%User{})
    render(conn, "new.html", changeset: changeset)
  end

  def create(conn, %{"user" => user_params}) do
    changeset = User.create_changeset(%User{}, user_params)

    if changeset.valid? do
      user = Repo.insert(changeset)

      conn
      |> put_flash(:info, "User created successfully.")
      |> Guardian.Plug.sign_in(user, :token, perms: %{ default: Guardian.Permissions.max })     #------ Autenticação ----------
      |> redirect(to: user_path(conn, :index))                                                  #------ Autenticação -------------
    else
      render(conn, "new.html", changeset: changeset)
    end
  end

这可能是什么问题?

0 个答案:

没有答案