From 1db5c4ae2d49d5adbda2c0825ee0320322b525d6 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 31 Jan 2023 19:33:33 +0100 Subject: [PATCH] Save IP and login date from directly registered accounts Signed-off-by: Thomas Citharel --- lib/graphql/resolvers/user.ex | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/graphql/resolvers/user.ex b/lib/graphql/resolvers/user.ex index ca9fdf7c3..69d2c4f3d 100644 --- a/lib/graphql/resolvers/user.ex +++ b/lib/graphql/resolvers/user.ex @@ -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