2014-05-04 13:39:00 +02:00
|
|
|
<?php
|
2014-05-12 16:46:14 +02:00
|
|
|
class EditUserEmailJob extends AbstractJob
|
2014-05-04 13:39:00 +02:00
|
|
|
{
|
2014-05-12 16:46:14 +02:00
|
|
|
protected $userRetriever;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->userRetriever = new UserRetriever($this);
|
|
|
|
}
|
|
|
|
|
2014-05-04 13:39:00 +02:00
|
|
|
public function execute()
|
|
|
|
{
|
2014-05-15 10:32:53 +02:00
|
|
|
if (Core::getConfig()->registration->needEmailForRegistering)
|
2014-05-12 00:13:18 +02:00
|
|
|
if (!$this->hasArgument(JobArgs::ARG_NEW_EMAIL) or empty($this->getArgument(JobArgs::ARG_NEW_EMAIL)))
|
2014-05-04 14:57:44 +02:00
|
|
|
throw new SimpleException('E-mail address is required - you will be sent confirmation e-mail.');
|
|
|
|
|
2014-05-12 16:46:14 +02:00
|
|
|
$user = $this->userRetriever->retrieve();
|
2014-05-12 00:13:18 +02:00
|
|
|
$newEmail = $this->getArgument(JobArgs::ARG_NEW_EMAIL);
|
2014-05-04 13:39:00 +02:00
|
|
|
|
2014-05-07 09:26:04 +02:00
|
|
|
$oldEmail = $user->getConfirmedEmail();
|
2014-05-04 13:39:00 +02:00
|
|
|
if ($oldEmail == $newEmail)
|
|
|
|
return $user;
|
|
|
|
|
2014-05-07 09:26:04 +02:00
|
|
|
$user->setUnconfirmedEmail($newEmail);
|
|
|
|
$user->setConfirmedEmail(null);
|
2014-05-04 13:39:00 +02:00
|
|
|
|
2014-05-06 19:39:41 +02:00
|
|
|
if ($this->getContext() == self::CONTEXT_NORMAL)
|
2014-05-07 09:26:04 +02:00
|
|
|
{
|
2014-05-04 17:53:40 +02:00
|
|
|
UserModel::save($user);
|
2014-05-07 09:26:04 +02:00
|
|
|
self::observeSave($user);
|
|
|
|
}
|
2014-05-04 13:39:00 +02:00
|
|
|
|
2014-05-04 19:23:09 +02:00
|
|
|
Logger::log('{user} changed {subject}\'s e-mail to {mail}', [
|
2014-05-04 13:39:00 +02:00
|
|
|
'user' => TextHelper::reprUser(Auth::getCurrentUser()),
|
|
|
|
'subject' => TextHelper::reprUser($user),
|
|
|
|
'mail' => $newEmail]);
|
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
2014-05-07 09:26:04 +02:00
|
|
|
public static function observeSave($user)
|
|
|
|
{
|
|
|
|
if (Access::check(new Privilege(Privilege::ChangeUserEmailNoConfirm), $user))
|
|
|
|
{
|
|
|
|
$user->confirmEmail();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!empty($user->getUnconfirmedEmail()))
|
|
|
|
ActivateUserEmailJob::sendEmail($user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 16:46:14 +02:00
|
|
|
public function getRequiredArguments()
|
2014-05-12 10:31:34 +02:00
|
|
|
{
|
2014-05-12 16:46:14 +02:00
|
|
|
return JobArgs::Conjunction(
|
|
|
|
$this->userRetriever->getRequiredArguments(),
|
|
|
|
JobArgs::ARG_NEW_EMAIL);
|
2014-05-12 10:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getRequiredPrivileges()
|
2014-05-04 13:39:00 +02:00
|
|
|
{
|
2014-05-04 16:27:15 +02:00
|
|
|
return new Privilege(
|
2014-05-07 00:34:02 +02:00
|
|
|
$this->getContext() == self::CONTEXT_BATCH_ADD
|
|
|
|
? Privilege::RegisterAccount
|
|
|
|
: Privilege::ChangeUserEmail,
|
2014-05-12 16:46:14 +02:00
|
|
|
Access::getIdentity($this->userRetriever->retrieve()));
|
2014-05-04 13:39:00 +02:00
|
|
|
}
|
|
|
|
}
|