2014-05-04 13:39:00 +02:00
|
|
|
<?php
|
2014-05-06 19:39:41 +02:00
|
|
|
class EditUserEmailJob extends AbstractUserJob
|
2014-05-04 13:39:00 +02:00
|
|
|
{
|
2014-05-06 19:39:41 +02:00
|
|
|
public function isSatisfied()
|
|
|
|
{
|
2014-05-12 00:13:18 +02:00
|
|
|
return $this->hasArgument(JobArgs::ARG_NEW_EMAIL);
|
2014-05-06 19:39:41 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 13:39:00 +02:00
|
|
|
public function execute()
|
|
|
|
{
|
2014-05-04 14:57:44 +02:00
|
|
|
if (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-04 13:39:00 +02:00
|
|
|
$user = $this->user;
|
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-04 13:39:00 +02:00
|
|
|
public function requiresPrivilege()
|
|
|
|
{
|
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-04 16:27:15 +02:00
|
|
|
Access::getIdentity($this->user));
|
2014-05-04 13:39:00 +02:00
|
|
|
}
|
|
|
|
}
|