Skip to content

Commit

Permalink
adjust email verification checker
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jun 22, 2021
1 parent 5eb5e25 commit fb905d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
24 changes: 10 additions & 14 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ protected function updateUser(IUser $user, array $data, bool $throwOnData = fals
$updated = true;

if ($userData !== $data) {
$data = $this->checkEmailVerification($userData, $data, $user);
$this->updateExistingUser($user, $data);
} else {
// nothing needs to be done if new and old data set are the same
Expand Down Expand Up @@ -340,28 +339,23 @@ protected function searchUsersForRelatedCollection(string $property, array $valu

/**
* check if we need to ask the server for email verification, if yes we create a cronjob
*
* @param $oldData
* @param $newData
* @param IUser $user
* @return array
*/
protected function checkEmailVerification($oldData, $newData, IUser $user): array {
if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) {
protected function checkEmailVerification(IAccount $updatedAccount, array $oldData): void {
$property = $updatedAccount->getProperty(self::PROPERTY_EMAIL);
if ($oldData[self::PROPERTY_EMAIL]['value'] !== $property->getValue()) {
$this->jobList->add(VerifyUserData::class,
[
'verificationCode' => '',
'data' => $newData[self::PROPERTY_EMAIL]['value'],
'data' => $property->getValue(),
'type' => self::PROPERTY_EMAIL,
'uid' => $user->getUID(),
'uid' => $updatedAccount->getUser()->getUID(),
'try' => 0,
'lastRun' => time()
]
);
$newData[self::PROPERTY_EMAIL]['verified'] = self::VERIFICATION_IN_PROGRESS;
}

return $newData;
$property->setVerified(self::VERIFICATION_IN_PROGRESS);
}
}

/**
Expand Down Expand Up @@ -633,7 +627,9 @@ public function updateAccount(IAccount $account): void {
$this->testPropertyScope($property, $allowedScopes, true);
}

$this->updateVerificationStatus($account, $this->getUser($account->getUser(), false));
$oldData = $this->getUser($account->getUser(), false);
$this->updateVerificationStatus($account, $oldData);
$this->checkEmailVerification($account, $oldData);

$this->updateUser($account->getUser(), $data, true);
}
Expand Down
5 changes: 1 addition & 4 deletions tests/lib/Accounts/AccountManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,14 @@ public function getInstance($mockedMethods = null) {
* @param bool $updateExisting
*/
public function testUpdateUser($newData, $oldData, $insertNew, $updateExisting) {
$accountManager = $this->getInstance(['getUser', 'insertNewUser', 'updateExistingUser', 'checkEmailVerification']);
$accountManager = $this->getInstance(['getUser', 'insertNewUser', 'updateExistingUser']);
/** @var IUser $user */
$user = $this->createMock(IUser::class);

// FIXME: should be an integration test instead of this abomination
$accountManager->expects($this->once())->method('getUser')->with($user)->willReturn($oldData);

if ($updateExisting) {
$accountManager->expects($this->once())->method('checkEmailVerification')
->with($oldData, $newData, $user)->willReturn($newData);
$accountManager->expects($this->once())->method('updateExistingUser')
->with($user, $newData);
$accountManager->expects($this->never())->method('insertNewUser');
Expand All @@ -300,7 +298,6 @@ public function testUpdateUser($newData, $oldData, $insertNew, $updateExisting)

if (!$insertNew && !$updateExisting) {
$accountManager->expects($this->never())->method('updateExistingUser');
$accountManager->expects($this->never())->method('checkEmailVerification');
$accountManager->expects($this->never())->method('insertNewUser');
$this->eventDispatcher->expects($this->never())->method('dispatch');
} else {
Expand Down

0 comments on commit fb905d4

Please sign in to comment.