4ba83e6834
Restored JobArgs approach. Previous introduction of hierarchic argument definitions has backfired: it was confusing what class to take arguments from, the concept of sharing arguments between different jobs was unintelligible and one never knew where given argument was actually defined. This appraoch makes it easier to maintain the arguments list and simplifies the code a lot.
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
class EditUserEmailJob extends AbstractUserJob
|
|
{
|
|
public function isSatisfied()
|
|
{
|
|
return $this->hasArgument(JobArgs::ARG_NEW_EMAIL);
|
|
}
|
|
|
|
public function execute()
|
|
{
|
|
if (getConfig()->registration->needEmailForRegistering)
|
|
if (!$this->hasArgument(JobArgs::ARG_NEW_EMAIL) or empty($this->getArgument(JobArgs::ARG_NEW_EMAIL)))
|
|
throw new SimpleException('E-mail address is required - you will be sent confirmation e-mail.');
|
|
|
|
$user = $this->user;
|
|
$newEmail = $this->getArgument(JobArgs::ARG_NEW_EMAIL);
|
|
|
|
$oldEmail = $user->getConfirmedEmail();
|
|
if ($oldEmail == $newEmail)
|
|
return $user;
|
|
|
|
$user->setUnconfirmedEmail($newEmail);
|
|
$user->setConfirmedEmail(null);
|
|
|
|
if ($this->getContext() == self::CONTEXT_NORMAL)
|
|
{
|
|
UserModel::save($user);
|
|
self::observeSave($user);
|
|
}
|
|
|
|
Logger::log('{user} changed {subject}\'s e-mail to {mail}', [
|
|
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
|
'subject' => TextHelper::reprUser($user),
|
|
'mail' => $newEmail]);
|
|
|
|
return $user;
|
|
}
|
|
|
|
public static function observeSave($user)
|
|
{
|
|
if (Access::check(new Privilege(Privilege::ChangeUserEmailNoConfirm), $user))
|
|
{
|
|
$user->confirmEmail();
|
|
}
|
|
else
|
|
{
|
|
if (!empty($user->getUnconfirmedEmail()))
|
|
ActivateUserEmailJob::sendEmail($user);
|
|
}
|
|
}
|
|
|
|
public function requiresPrivilege()
|
|
{
|
|
return new Privilege(
|
|
$this->getContext() == self::CONTEXT_BATCH_ADD
|
|
? Privilege::RegisterAccount
|
|
: Privilege::ChangeUserEmail,
|
|
Access::getIdentity($this->user));
|
|
}
|
|
}
|