2014-05-04 13:39:00 +02:00
|
|
|
<?php
|
2014-05-04 17:53:40 +02:00
|
|
|
class EditUserEmailJob extends AbstractUserEditJob
|
2014-05-04 13:39:00 +02:00
|
|
|
{
|
|
|
|
const NEW_EMAIL = 'new-email';
|
|
|
|
|
|
|
|
public function execute()
|
|
|
|
{
|
2014-05-04 14:57:44 +02:00
|
|
|
if (getConfig()->registration->needEmailForRegistering)
|
|
|
|
if (!$this->hasArguemnt(self::NEW_EMAIL) or empty($this->getArgument(self::NEW_EMAIL)))
|
|
|
|
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-04 17:53:40 +02:00
|
|
|
if (!$this->skipSaving)
|
|
|
|
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-06 18:09:32 +02:00
|
|
|
Privilege::ChangeUserEmail,
|
2014-05-04 16:27:15 +02:00
|
|
|
Access::getIdentity($this->user));
|
2014-05-04 13:39:00 +02:00
|
|
|
}
|
|
|
|
}
|