0

I'm working on a project where I use Craft CMS to manage user sessions and store user preferences such as site version and preferred language. However, for privacy reasons (GDPR compliance), I'm not storing any user data, including name, first name, or email address, in Craft CMS.

I need to create users from a Controller without requiring an email address and automatically activate their accounts. The idea is that I handle user creation and login using a third-party API.

I've tried creating the user without an email address using the following code, but the account remains inactive, so I can't start the session:

$user = new User();
$user->username = $apiUserId;
$user->password = StringHelper::randomString(16, true);
Craft::$app->getElements()->saveElement($user);

Is there a way to create a user without an email address and automatically activate the account on save?

UPDATE:

I've found that I can activate the user after that code using Craft::$app->users->activateUser($user);.

However, I'm still looking to register the user without any email address (currently I'm setting a dummy one from $user->email = '[email protected]';).

2
  • Can you generate a junk email address? i.e. [email protected]?
    – Brad Bell
    Commented Oct 17, 2023 at 16:43
  • Yes that's what I did, but it feels a bit dirty.
    – Romain P.
    Commented Oct 18, 2023 at 7:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.