Skip to content

Commit

Permalink
Add activateUser mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesedmonston committed Mar 10, 2021
1 parent 5910994 commit 5781d3f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Settings extends Model
public $invalidRefreshToken = 'Invalid Refresh Token';
public $invalidEmailAddress = 'Invalid email address';

public $userActivated = 'Successfully activated user';
public $passwordSaved = 'Successfully saved password';
public $passwordUpdated = 'Successfully updated password';
public $passwordResetSent = 'You will receive an email if it matches an account in our system';
Expand Down
22 changes: 22 additions & 0 deletions src/services/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ public function registerGqlMutations(Event $event)
},
];

$event->mutations['activateUser'] = [
'description' => 'Activates user. Requires `code` and `id` from Craft activation email. Returns success message.',
'type' => Type::nonNull(Type::string()),
'args' => [
'code' => Type::nonNull(Type::string()),
'id' => Type::nonNull(Type::string()),
],
'resolve' => function ($source, array $arguments) use ($users, $settings, $errorService) {
$code = $arguments['code'];
$id = $arguments['id'];

$user = $users->getUserByUid($id);

if (!$user || !$users->isVerificationCodeValidForUser($user, $code)) {
$errorService->throw($settings->invalidRequest, 'INVALID');
}

$users->activateUser($user);
return $settings->userActivated;
},
];

$event->mutations['setPassword'] = [
'description' => 'Sets password for unauthenticated user. Requires `code` and `id` from Craft reset password email. Returns success message.',
'type' => Type::nonNull(Type::string()),
Expand Down
7 changes: 7 additions & 0 deletions src/templates/_sections/messages.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
<hr/>
<h2>Responses</h2>

{{ forms.textField({
label: 'User Activated',
name: 'userActivated',
value: settings.userActivated,
required: true,
}) }}

{{ forms.textField({
label: 'Password Saved',
name: 'passwordSaved',
Expand Down

0 comments on commit 5781d3f

Please sign in to comment.