Skip to content

Commit

Permalink
Send appropriate activation email for social registrations (fix #72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesedmonston committed Sep 5, 2022
1 parent 9cc11ab commit 08dcc16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/services/SocialService.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function authenticate(array $tokenUser, int $schemaId, int $userGroupId =
'password' => '',
'firstName' => $tokenUser['firstName'],
'lastName' => $tokenUser['lastName'],
], $userGroupId ?? $settings->userGroup);
], $userGroupId ?? $settings->userGroup, true);
}

if ($userGroupId) {
Expand Down
18 changes: 16 additions & 2 deletions src/services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use craft\gql\interfaces\elements\User as ElementsUser;
use craft\gql\resolvers\mutations\Asset;
use craft\gql\types\input\File;
use craft\helpers\Template;
use craft\mail\Mailer;
use craft\records\GqlSchema as GqlSchemaRecord;
use craft\services\Elements;
use craft\services\Fields;
Expand Down Expand Up @@ -507,10 +509,11 @@ public function registerGqlMutations(RegisterGqlMutationsEvent $event)
*
* @param array $arguments
* @param int $userGroup
* @param bool $social
* @return User
* @throws Error
*/
public function create(array $arguments, int $userGroup): User
public function create(array $arguments, int $userGroup, bool $social = false): User
{
$email = $arguments['email'];
$password = $arguments['password'];
Expand Down Expand Up @@ -571,7 +574,18 @@ public function create(array $arguments, int $userGroup): User
}

if ($requiresVerification) {
$usersService->sendActivationEmail($user);
if ($social) {
/** @var Mailer */
$mailerService = Craft::$app->getMailer();
$url = $usersService->getEmailVerifyUrl($user);

$mailerService
->composeFromKey('account_activation', ['link' => Template::raw($url)])
->setTo($user)
->send();
} else {
$usersService->sendActivationEmail($user);
}
}

$this->_updateLastLogin($user);
Expand Down

0 comments on commit 08dcc16

Please sign in to comment.