我正在开发一个基于这篇文章的聊天网络应用程序项目:https://curiosum.com/blog/elixir-phoenix-liveview-messenger-part-3。我已经到达了实现用户授权的部分,并且遇到了一个奇怪的问题。根据文章及其 github 表示,一切都已正确设置。有两个按钮 - “注册”和“注册”分别指向 /session/new 和 /registration/new。他们的 html 表示在路径 lib/chat_web/templates/pow/session/new.html.eex 和 lib/chat_web/templates/pow/registration/new.html.eex 中,因为它们应该是。但是当我按下这些按钮时,它们会不断将我重定向到同一个 html 页面,即 lib/chat_web/templates/layout/app.html.eex。如果我删除了 new.html.eex 文件,重定向最终会出现 Could not render "new.html" 错误,这表明路由是正确的。我真的不知道我是这个问题的原因。链接到我的存储库中的分支:https://github.com/ArturMarekNowak/Chat/tree/wip/authorization
/lib/chat_web/templates/layout/app.html.eex
<%= if Pow.Plug.current_user(@conn) do %>
<li><%= link "Profile", to: Routes.pow_registration_path(@conn, :edit) %></li>
<li><%= link "Sign out", to: Routes.pow_session_path(@conn, :delete), method: :delete %></li>
<% else %>
<li><%= link "Register", to: "/registration/new" %></li>
<li><%= link "Sign in", to: Routes.pow_session_path(@conn, :new) %></li>
<% end %>
/lib/chat_web/router.ex
defmodule ChatWeb.Router do
use ChatWeb, :router
use Pow.Phoenix.Router
import Phoenix.LiveView.Router
pipeline :browser do
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_live_flash)
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
plug(:put_root_layout, {ChatWeb.LayoutView, :root})
end
pipeline :api do
plug(:accepts, ["json"])
end
pipeline :protected do
plug(Pow.Plug.RequireAuthenticated,
error_handler: Pow.Phoenix.PlugErrorHandler
)
end
scope "/" do
pipe_through(:browser)
pow_routes()
end
scope "/", ChatWeb do
pipe_through(:browser)
get("/", PageController, :index)
end
# Make conversation routes protected by requiring authentication
scope "/", ChatWeb do
pipe_through([:browser, :protected])
resources("/conversations", ConversationController)
live("/conversations/:conversation_id/users/:user_id", ConversationLive, as: :conversation)
end
end
/lib/chat_web/views/pow/session_view.ex
defmodule ChatWeb.Pow.SessionView do
use ChatWeb, :view
end
/lib/chat_web/templates/pow/session/new.html.eex
<h1>Register</h1>
<%= form_for @changeset, @action, [as: :user], fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= label f, Pow.Ecto.Schema.user_id_field(@changeset) %>
<%= text_input f, Pow.Ecto.Schema.user_id_field(@changeset) %>
<%= error_tag f, Pow.Ecto.Schema.user_id_field(@changeset) %>
<%= label f, :nickname %>
<%= text_input f, :nickname %>
<%= error_tag f, :nickname %>
<%= label f, :password %>
<%= password_input f, :password %>
<%= error_tag f, :password %>
<%= label f, :confirm_password %>
<%= password_input f, :confirm_password %>
<%= error_tag f, :confirm_password %>
<div>
<%= submit "Register" %>
</div>
<% end %>
<span><%= link "Sign in", to: Routes.pow_session_path(@conn, :new) %></span>
• 显示“Splash”图像直到上传新图像,然后显示新图像 x 秒
• 如何正确发送带有附件的 python 电子邮件和带有替代纯文本正文的 HTML 正文
• 为什么这个 python 代码抛出 OverflowError?
• 如何使用.htaccess允许一个文件访问同一目录下的图片,但不让其他人直接看到图片?
• HTML“细节”元素 - 不要在特定区域触发“切换”事件(例如操作按钮)
• 如何将字符串保存为缓存目录中的 html 文件并从缓存目录中检索该文件并在 android studio 的 Web 视图中显示它?
• 如何使用 Python 和 HTML 在电子邮件中水平对齐和并排显示图像?
• 为什么我将静态文件放入公用文件夹并添加代码 app.use(express.static("public")); 后我的 ejs 文件没有被渲染
• boostrap3 片段在 Django 模板中不起作用
• 为什么 Puppeteer 显示的文本乱七八糟且换行不均匀?