Save IP and login date from directly registered accounts

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-01-31 19:33:33 +01:00
parent 5c43713d85
commit 1db5c4ae2d
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
1 changed files with 9 additions and 2 deletions

View File

@ -152,11 +152,18 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
- send a validation email to the user
"""
@spec create_user(any, %{email: String.t()}, any) :: {:ok, User.t()} | {:error, String.t()}
def create_user(_parent, %{email: email} = args, _resolution) do
def create_user(_parent, %{email: email} = args, %{context: context}) do
current_ip = Map.get(context, :ip)
user_agent = Map.get(context, :user_agent, "")
now = DateTime.utc_now()
with {:ok, email} <- lowercase_domain(email),
:registration_ok <- check_registration_config(email),
:not_deny_listed <- check_registration_denylist(email),
{:ok, %User{} = user} <- Users.register(%{args | email: email}) do
{:ok, %User{} = user} <-
args
|> Map.merge(%{email: email, current_sign_in_ip: current_ip, current_sign_in_at: now})
|> Users.register() do
Email.User.send_confirmation_email(user, Map.get(args, :locale, "en"))
{:ok, user}
else