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>
This commit is contained in:
Thomas Citharel
2023-09-07 12:18:46 +02:00
parent 7e13e2baa7
commit 7e4934513a
5 changed files with 40 additions and 12 deletions

View File

@@ -71,7 +71,9 @@ defmodule Mobilizon.Web.AuthController do
render(conn, "callback.html", %{
access_token: access_token,
refresh_token: refresh_token,
user: user
user: user,
username: username_from_ueberauth(auth),
name: display_name_from_ueberauth(auth)
})
else
err ->
@@ -114,6 +116,18 @@ defmodule Mobilizon.Web.AuthController do
defp email_from_ueberauth(_), do: nil
defp username_from_ueberauth(%Ueberauth.Auth{info: %Ueberauth.Auth.Info{nickname: nickname}})
when is_valid_string(nickname),
do: nickname
defp username_from_ueberauth(_), do: nil
defp display_name_from_ueberauth(%Ueberauth.Auth{info: %Ueberauth.Auth.Info{name: name}})
when is_valid_string(name),
do: name
defp display_name_from_ueberauth(_), do: nil
@spec provider_config(String.t()) :: {:ok, any()} | {:error, :not_supported | :unknown_error}
defp provider_config(provider_name) do
with ueberauth when is_list(ueberauth) <- Application.get_env(:ueberauth, Ueberauth),