mobilizon/lib/web/views/auth_view.ex
Thomas Citharel 7e4934513a
feat(auth): pre-initialize registration fields with information from 3rd-party provider
When using a 3rd-party auth provider, we now use the given username & display name information from
the provider to fill fields from the profile RegistrationView.

Partly addresses #1105

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2023-09-07 12:18:46 +02:00

45 lines
1.4 KiB
Elixir

defmodule Mobilizon.Web.AuthView do
@moduledoc """
View for the auth routes
"""
use Mobilizon.Web, :view
alias Mobilizon.Service.Metadata.Instance
alias Mobilizon.Web.PageView
alias Phoenix.HTML.Tag
@spec render(String.t(), map()) :: String.t() | Plug.Conn.t()
def render(
"callback.html",
%{
conn: _conn,
access_token: access_token,
refresh_token: refresh_token,
user: %{
id: user_id,
email: user_email,
role: user_role,
default_actor_id: user_actor_id
},
username: username,
name: name
} = assigns
) do
info_tags = [
Tag.tag(:meta, name: "auth-access-token", content: access_token),
Tag.tag(:meta, name: "auth-refresh-token", content: refresh_token),
Tag.tag(:meta, name: "auth-user-id", content: user_id),
Tag.tag(:meta, name: "auth-user-email", content: user_email),
Tag.tag(:meta, name: "auth-user-role", content: String.upcase(to_string(user_role))),
Tag.tag(:meta, name: "auth-user-actor-id", content: user_actor_id),
Tag.tag(:meta, name: "auth-user-suggested-actor-username", content: username),
Tag.tag(:meta, name: "auth-user-suggested-actor-name", content: name)
]
with tags <- Instance.build_tags() ++ info_tags,
assigns <- Map.put(assigns, :tags, tags) do
PageView.render("index.html", assigns)
end
end
end