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
|
|
|
{
|
|
|
|
const NEW_EMAIL = 'new-email';
|
|
|
|
|
2014-05-06 19:39:41 +02:00
|
|
|
public function isSatisfied()
|
|
|
|
{
|
|
|
|
return $this->hasArgument(self::NEW_EMAIL);
|
|
|
|
}
|
|
|
|
|
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-07 00:34:02 +02:00
|
|
|
if (!$this->hasArgument(self::NEW_EMAIL) or empty($this->getArgument(self::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;
|
|
|
|
$newEmail = UserModel::validateEmail($this->getArgument(self::NEW_EMAIL));
|
|
|
|
|
|
|
|
$oldEmail = $user->emailConfirmed;
|
|
|
|
if ($oldEmail == $newEmail)
|
|
|
|
return $user;
|
|
|
|
|
2014-05-04 15:43:38 +02:00
|
|
|
$user->emailUnconfirmed = $newEmail;
|
|
|
|
$user->emailConfirmed = null;
|
|
|
|
|
2014-05-05 21:20:40 +02:00
|
|
|
if (Auth::getCurrentUser()->getId() == $user->getId())
|
2014-05-04 13:39:00 +02:00
|
|
|
{
|
|
|
|
if (!empty($newEmail))
|
2014-05-04 15:43:38 +02:00
|
|
|
ActivateUserEmailJob::sendEmail($user);
|
2014-05-04 13:39:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-04 15:43:38 +02:00
|
|
|
$user->confirmEmail();
|
2014-05-04 13:39:00 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 19:39:41 +02:00
|
|
|
if ($this->getContext() == self::CONTEXT_NORMAL)
|
2014-05-04 17:53:40 +02:00
|
|
|
UserModel::save($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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|