我正在为ex_admin实施身份验证,是否应该为登录页面做自己的自定义UI?
我使用以下视图进行工作
<h2>Login Page</h2>
<%= form_for @changeset, @action, fn f -> %>
<div class="form-group">
<%= label f, :username, class: "control-label" %>
<%= text_input f, :email, class: "form-control" %>
<%= error_tag f, :email %>
</div>
<div class="form-group">
<%= label f, :password, class: "control-label" %>
<%= password_input f, :password, class: "form-control" %>
<%= error_tag f, :password %>
</div>
<div class="form-group">
<%= submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>
我的控制器看起来像这样
defmodule CanvasPostWeb.SessionController do
use CanvasPostWeb, :controller
alias CanvasPostWeb.Router.Helpers
alias CanvasPost.Auth
alias CanvasPost.Auth.Verify
def current_user(conn) do
Auth.Guardian.Plug.current_resource(conn)
end
def index(conn, params) do
changeset = Auth.change_user(%Auth.User{})
maybe_user = Guardian.Plug.current_resource(conn)
conn
|> render("session.html", changeset: changeset, action: session_path(conn, :login))
end
def login(conn, %{"user" => %{"email" => email, "password" => password}}) do
Verify.authenticate_user(email, password)
|> login_reply(conn)
end
defp login_reply({:error, error}, conn) do
conn
|> put_flash(:error, error)
|> redirect(to: "/")
end
defp login_reply({:ok, user}, conn) do
conn
|> put_flash(:success, "Welcome back!")
|> Auth.Guardian.Plug.sign_in(user)
|> redirect(to: "/admin")
end
def logout(conn, _) do
conn
|> Auth.Guardian.Plug.sign_out
|> put_flash(:info, "You have been logged out")
|> redirect(to: session_path(conn, :index))
end
end
添加exadmin auth实现时,哪种身份验证工作正常
defimpl ExAdmin.Authentication, for: Plug.Conn do
alias CanvasPostWeb.Router.Helpers
alias CanvasPost.ExAdmin.Auth
def use_authentication?(_), do: true
def current_user(conn), do: CanvasPostWeb.SessionController.current_user(conn)
def current_user_name(conn), do: CanvasPostWeb.SessionController.current_user(conn).email
def session_path(conn, action), do: Helpers.session_path(conn, :index)
def session_path(conn, :destroy), do: Helpers.session_path(conn, :delete, 0)
end
但这是使用ex_admin实现身份验证的正确方法。在Wiki中链接的contacts_demo中,还有一个自定义UI登录页面。但是当我查看css文件时,我看到它们包含登录表单的样式。在ex_admin中没有用于身份验证的UI是否正确?