szurubooru/src/Controllers/UserController.php

618 lines
19 KiB
PHP
Raw Normal View History

2013-10-05 19:24:08 +02:00
<?php
2013-10-05 21:24:20 +02:00
class UserController
2013-10-05 19:24:08 +02:00
{
public function listAction($filter, $page)
2013-10-05 19:24:08 +02:00
{
2014-04-29 21:35:29 +02:00
$context = getContext();
Access::assert(
Privilege::ListUsers);
2013-10-16 13:07:01 +02:00
$suppliedFilter = $filter ?: InputHelper::get('filter') ?: 'order:alpha,asc';
$page = max(1, intval($page));
2014-04-29 21:35:29 +02:00
$usersPerPage = intval(getConfig()->browsing->usersPerPage);
2013-10-16 13:07:01 +02:00
$users = UserSearchService::getEntities($suppliedFilter, $usersPerPage, $page);
$userCount = UserSearchService::getEntityCount($suppliedFilter);
2013-10-16 13:07:01 +02:00
$pageCount = ceil($userCount / $usersPerPage);
$page = min($pageCount, $page);
2013-10-16 13:07:01 +02:00
2014-04-29 21:35:29 +02:00
$context->filter = $suppliedFilter;
$context->transport->users = $users;
$context->transport->paginator = new StdClass;
$context->transport->paginator->page = $page;
$context->transport->paginator->pageCount = $pageCount;
$context->transport->paginator->entityCount = $userCount;
$context->transport->paginator->entities = $users;
$context->transport->paginator->params = func_get_args();
2013-10-05 19:24:08 +02:00
}
2013-11-17 14:52:46 +01:00
public function flagAction($name)
{
$user = UserModel::findByNameOrEmail($name);
Access::assert(
Privilege::FlagUser,
Access::getIdentity($user));
2013-11-17 14:52:46 +01:00
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
2013-11-17 14:52:46 +01:00
2014-04-30 08:08:24 +02:00
$key = TextHelper::reprUser($user);
2013-11-17 14:52:46 +01:00
2014-04-30 08:08:24 +02:00
$flagged = SessionHelper::get('flagged', []);
if (in_array($key, $flagged))
throw new SimpleException('You already flagged this user');
$flagged []= $key;
SessionHelper::set('flagged', $flagged);
2014-04-30 08:08:24 +02:00
LogHelper::log('{user} flagged {subject} for moderator attention', [
'subject' => TextHelper::reprUser($user)]);
2013-11-17 14:52:46 +01:00
}
public function banAction($name)
{
$user = UserModel::findByNameOrEmail($name);
Access::assert(
Privilege::BanUser,
Access::getIdentity($user));
2013-11-17 14:52:46 +01:00
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
2013-11-17 14:52:46 +01:00
2014-04-30 08:08:24 +02:00
$user->banned = true;
UserModel::save($user);
LogHelper::log('{user} banned {subject}', ['subject' => TextHelper::reprUser($user)]);
}
public function unbanAction($name)
{
$user = UserModel::findByNameOrEmail($name);
Access::assert(
Privilege::BanUser,
Access::getIdentity($user));
2013-11-17 14:52:46 +01:00
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
2013-11-17 14:52:46 +01:00
2014-04-30 08:08:24 +02:00
$user->banned = false;
UserModel::save($user);
LogHelper::log('{user} unbanned {subject}', ['subject' => TextHelper::reprUser($user)]);
}
public function acceptRegistrationAction($name)
{
$user = UserModel::findByNameOrEmail($name);
Access::assert(
Privilege::AcceptUserRegistration);
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
$user->staffConfirmed = true;
UserModel::save($user);
LogHelper::log('{user} confirmed {subject}\'s account', ['subject' => TextHelper::reprUser($user)]);
}
public function deleteAction($name)
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$user = UserModel::findByNameOrEmail($name);
Access::assert(
Privilege::ViewUser,
Access::getIdentity($user));
Access::assert(
Privilege::DeleteUser,
Access::getIdentity($user));
2013-11-18 10:30:43 +01:00
$this->loadUserView($user);
2014-04-29 21:35:29 +02:00
$context->transport->tab = 'delete';
2014-04-29 21:35:29 +02:00
$context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
$name = $user->name;
2014-05-01 16:12:37 +02:00
if (Auth::getCurrentUser()->id == $user->id)
{
2014-04-30 08:08:24 +02:00
$suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt);
if ($suppliedPasswordHash != $user->passHash)
throw new SimpleException('Must supply valid password');
}
2014-04-30 08:08:24 +02:00
$oldId = $user->id;
UserModel::remove($user);
2014-05-01 16:12:37 +02:00
if ($oldId == Auth::getCurrentUser()->id)
Auth::logOut();
2013-11-16 21:21:43 +01:00
2014-04-30 08:08:24 +02:00
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
LogHelper::log('{user} removed {subject}\'s account', ['subject' => TextHelper::reprUser($name)]);
}
2013-10-22 00:17:06 +02:00
public function settingsAction($name)
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$user = UserModel::findByNameOrEmail($name);
Access::assert(
Privilege::ViewUser,
Access::getIdentity($user));
Access::assert(
Privilege::ChangeUserSettings,
Access::getIdentity($user));
2013-10-22 00:17:06 +02:00
2013-11-18 10:30:43 +01:00
$this->loadUserView($user);
2014-04-29 21:35:29 +02:00
$context->transport->tab = 'settings';
2013-10-22 00:17:06 +02:00
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
$suppliedSafety = InputHelper::get('safety');
if (!is_array($suppliedSafety))
$suppliedSafety = [];
foreach (PostSafety::getAll() as $safety)
$user->enableSafety($safety, in_array($safety, $suppliedSafety));
$user->enableEndlessScrolling(InputHelper::get('endless-scrolling'));
$user->enablePostTagTitles(InputHelper::get('post-tag-titles'));
$user->enableHidingDislikedPosts(InputHelper::get('hide-disliked-posts'));
if ($user->accessRank != AccessRank::Anonymous)
UserModel::save($user);
2014-05-01 16:12:37 +02:00
if ($user->id == Auth::getCurrentUser()->id)
Auth::setCurrentUser($user);
Messenger::message('Browsing settings updated!');
2013-10-22 00:17:06 +02:00
}
public function editAction($name)
{
2014-04-29 21:35:29 +02:00
$context = getContext();
try
{
$user = UserModel::findByNameOrEmail($name);
Access::assert(
Privilege::ViewUser,
Access::getIdentity($user));
2013-11-18 10:30:43 +01:00
$this->loadUserView($user);
2014-04-29 21:35:29 +02:00
$context->transport->tab = 'edit';
$context->suppliedCurrentPassword = $suppliedCurrentPassword = InputHelper::get('current-password');
$context->suppliedName = $suppliedName = InputHelper::get('name');
$context->suppliedPassword1 = $suppliedPassword1 = InputHelper::get('password1');
$context->suppliedPassword2 = $suppliedPassword2 = InputHelper::get('password2');
$context->suppliedEmail = $suppliedEmail = InputHelper::get('email');
$context->suppliedAccessRank = $suppliedAccessRank = InputHelper::get('access-rank');
$currentPasswordHash = $user->passHash;
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
$confirmMail = false;
LogHelper::bufferChanges();
if ($suppliedName != '' and $suppliedName != $user->name)
{
2014-04-30 08:08:24 +02:00
Access::assert(
Privilege::ChangeUserName,
Access::getIdentity($user));
$suppliedName = UserModel::validateUserName($suppliedName);
$oldName = $user->name;
$user->name = $suppliedName;
LogHelper::log('{user} renamed {old} to {new}', [
'old' => TextHelper::reprUser($oldName),
'new' => TextHelper::reprUser($suppliedName)]);
}
2013-11-16 16:24:38 +01:00
2014-04-30 08:08:24 +02:00
if ($suppliedPassword1 != '')
{
Access::assert(
Privilege::ChangeUserPassword,
Access::getIdentity($user));
if ($suppliedPassword1 != $suppliedPassword2)
throw new SimpleException('Specified passwords must be the same');
$suppliedPassword = UserModel::validatePassword($suppliedPassword1);
$user->passHash = UserModel::hashPassword($suppliedPassword, $user->passSalt);
LogHelper::log('{user} changed {subject}\'s password', ['subject' => TextHelper::reprUser($user)]);
}
2014-04-30 08:08:24 +02:00
if ($suppliedEmail != '' and $suppliedEmail != $user->emailConfirmed)
{
Access::assert(
Privilege::ChangeUserEmail,
Access::getIdentity($user));
2013-10-21 23:50:30 +02:00
2014-04-30 08:08:24 +02:00
$suppliedEmail = UserModel::validateEmail($suppliedEmail);
2014-05-01 16:12:37 +02:00
if (Auth::getCurrentUser()->id == $user->id)
2013-10-16 18:07:23 +02:00
{
2014-04-30 08:08:24 +02:00
$user->emailUnconfirmed = $suppliedEmail;
if (!empty($user->emailUnconfirmed))
$confirmMail = true;
LogHelper::log('{user} changed e-mail to {mail}', ['mail' => $suppliedEmail]);
2013-10-16 18:07:23 +02:00
}
2014-04-30 08:08:24 +02:00
else
2013-10-21 23:50:30 +02:00
{
2014-04-30 08:08:24 +02:00
$user->emailUnconfirmed = null;
$user->emailConfirmed = $suppliedEmail;
LogHelper::log('{user} changed {subject}\'s e-mail to {mail}', [
'subject' => TextHelper::reprUser($user),
2014-04-30 08:08:24 +02:00
'mail' => $suppliedEmail]);
2013-10-21 23:50:30 +02:00
}
2014-04-30 08:08:24 +02:00
}
2014-04-30 08:08:24 +02:00
if ($suppliedAccessRank != '' and $suppliedAccessRank != $user->accessRank)
{
Access::assert(
Privilege::ChangeUserAccessRank,
Access::getIdentity($user));
$suppliedAccessRank = UserModel::validateAccessRank($suppliedAccessRank);
$user->accessRank = $suppliedAccessRank;
LogHelper::log('{user} changed {subject}\'s access rank to {rank}', [
'subject' => TextHelper::reprUser($user),
'rank' => AccessRank::toString($suppliedAccessRank)]);
}
2013-11-16 16:24:38 +01:00
2014-05-01 16:12:37 +02:00
if (Auth::getCurrentUser()->id == $user->id)
2014-04-30 08:08:24 +02:00
{
$suppliedPasswordHash = UserModel::hashPassword($suppliedCurrentPassword, $user->passSalt);
if ($suppliedPasswordHash != $currentPasswordHash)
throw new SimpleException('Must supply valid current password');
}
2014-04-30 08:08:24 +02:00
UserModel::save($user);
2014-05-01 16:12:37 +02:00
if (Auth::getCurrentUser()->id == $user->id)
Auth::setCurrentUser($user);
2014-04-30 08:08:24 +02:00
if ($confirmMail)
self::sendEmailChangeConfirmation($user);
LogHelper::flush();
$message = 'Account settings updated!';
if ($confirmMail)
$message .= ' You will be sent an e-mail address confirmation message soon.';
Messenger::message($message);
}
catch (Exception $e)
{
2014-04-29 21:35:29 +02:00
$context->transport->user = UserModel::findByNameOrEmail($name);
throw $e;
}
}
public function viewAction($name, $tab = 'favs', $page)
2013-10-05 19:24:08 +02:00
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$postsPerPage = intval(getConfig()->browsing->postsPerPage);
$user = UserModel::findByNameOrEmail($name);
2013-10-14 10:22:53 +02:00
if ($tab === null)
$tab = 'favs';
if ($page === null)
$page = 1;
Access::assert(
Privilege::ViewUser,
Access::getIdentity($user));
2013-11-18 10:30:43 +01:00
$this->loadUserView($user);
2013-10-28 11:19:15 +01:00
$query = '';
if ($tab == 'uploads')
$query = 'submit:' . $user->name;
elseif ($tab == 'favs')
$query = 'fav:' . $user->name;
else
throw new SimpleException('Wrong tab');
2013-10-14 10:22:53 +02:00
2013-11-30 13:59:29 +01:00
$page = max(1, $page);
$posts = PostSearchService::getEntities($query, $postsPerPage, $page);
$postCount = PostSearchService::getEntityCount($query, $postsPerPage, $page);
2013-10-14 10:22:53 +02:00
$pageCount = ceil($postCount / $postsPerPage);
PostModel::preloadTags($posts);
2013-10-14 10:22:53 +02:00
2014-04-29 21:35:29 +02:00
$context->transport->tab = $tab;
$context->transport->lastSearchQuery = $query;
$context->transport->paginator = new StdClass;
$context->transport->paginator->page = $page;
$context->transport->paginator->pageCount = $pageCount;
$context->transport->paginator->entityCount = $postCount;
$context->transport->paginator->entities = $posts;
$context->transport->posts = $posts;
2013-10-05 19:24:08 +02:00
}
2013-10-14 00:25:40 +02:00
public function toggleSafetyAction($safety)
{
2014-05-01 16:12:37 +02:00
$user = Auth::getCurrentUser();
Access::assert(
Privilege::ChangeUserSettings,
2014-05-01 16:12:37 +02:00
Access::getIdentity($user));
2013-10-14 00:25:40 +02:00
if (!in_array($safety, PostSafety::getAll()))
throw new SimpleExcetpion('Invalid safety');
2014-05-01 16:12:37 +02:00
$user->enableSafety($safety, !$user->hasEnabledSafety($safety));
2013-10-14 00:25:40 +02:00
2014-05-01 16:12:37 +02:00
if ($user->accessRank != AccessRank::Anonymous)
UserModel::save($user);
Auth::setCurrentUser($user);
2013-10-14 00:25:40 +02:00
}
2013-10-16 18:07:23 +02:00
public function registrationAction()
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$context->handleExceptions = true;
2013-10-16 18:07:23 +02:00
//check if already logged in
2014-05-01 16:12:37 +02:00
if (Auth::isLoggedIn())
2013-10-16 18:07:23 +02:00
{
2014-04-29 21:35:29 +02:00
\Chibi\Util\Url::forward(\Chibi\Router::linkTo(['IndexController', 'indexAction']));
2013-10-16 18:07:23 +02:00
return;
}
$suppliedName = InputHelper::get('name');
$suppliedPassword1 = InputHelper::get('password1');
$suppliedPassword2 = InputHelper::get('password2');
$suppliedEmail = InputHelper::get('email');
2014-04-29 21:35:29 +02:00
$context->suppliedName = $suppliedName;
$context->suppliedPassword1 = $suppliedPassword1;
$context->suppliedPassword2 = $suppliedPassword2;
$context->suppliedEmail = $suppliedEmail;
2013-10-16 18:07:23 +02:00
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
2013-10-16 18:07:23 +02:00
2014-04-30 08:08:24 +02:00
$suppliedName = UserModel::validateUserName($suppliedName);
2013-10-16 18:07:23 +02:00
2014-04-30 08:08:24 +02:00
if ($suppliedPassword1 != $suppliedPassword2)
throw new SimpleException('Specified passwords must be the same');
$suppliedPassword = UserModel::validatePassword($suppliedPassword1);
2013-10-16 18:07:23 +02:00
2014-04-30 08:08:24 +02:00
$suppliedEmail = UserModel::validateEmail($suppliedEmail);
if (empty($suppliedEmail) and getConfig()->registration->needEmailForRegistering)
throw new SimpleException('E-mail address is required - you will be sent confirmation e-mail.');
2013-10-16 18:07:23 +02:00
2014-04-30 08:08:24 +02:00
//register the user
$dbUser = UserModel::spawn();
$dbUser->name = $suppliedName;
$dbUser->passHash = UserModel::hashPassword($suppliedPassword, $dbUser->passSalt);
$dbUser->emailUnconfirmed = $suppliedEmail;
2013-10-16 18:07:23 +02:00
2014-04-30 08:08:24 +02:00
$dbUser->joinDate = time();
if (UserModel::getCount() == 0)
{
//very first user
$dbUser->accessRank = AccessRank::Admin;
$dbUser->staffConfirmed = true;
$dbUser->emailUnconfirmed = null;
$dbUser->emailConfirmed = $suppliedEmail;
}
else
{
$dbUser->accessRank = AccessRank::Registered;
$dbUser->staffConfirmed = false;
$dbUser->staffConfirmed = null;
}
2013-11-16 16:24:38 +01:00
2014-04-30 08:08:24 +02:00
//save the user to db if everything went okay
UserModel::save($dbUser);
2013-11-16 16:24:38 +01:00
2014-04-30 08:08:24 +02:00
if (!empty($dbUser->emailUnconfirmed))
self::sendEmailChangeConfirmation($dbUser);
2013-11-16 18:40:26 +01:00
2014-04-30 08:08:24 +02:00
$message = 'Congratulations, your account was created.';
if (!empty($context->mailSent))
{
$message .= ' Please wait for activation e-mail.';
if (getConfig()->registration->staffActivation)
$message .= ' After this, your registration must be confirmed by staff.';
}
elseif (getConfig()->registration->staffActivation)
$message .= ' Your registration must be now confirmed by staff.';
2013-10-16 18:07:23 +02:00
2014-04-30 08:08:24 +02:00
LogHelper::log('{subject} just signed up', ['subject' => TextHelper::reprUser($dbUser)]);
Messenger::message($message);
2014-04-30 08:08:24 +02:00
if (!getConfig()->registration->needEmailForRegistering and !getConfig()->registration->staffActivation)
{
2014-05-01 16:12:37 +02:00
Auth::setCurrentUser($dbUser);
2013-10-16 18:07:23 +02:00
}
}
public function activationAction($token)
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$context->viewName = 'message';
Assets::setSubTitle('account activation');
2013-10-16 18:07:23 +02:00
$dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken);
2013-11-16 16:24:38 +01:00
$dbUser = $dbToken->getUser();
$dbUser->emailConfirmed = $dbUser->emailUnconfirmed;
$dbUser->emailUnconfirmed = null;
2013-11-16 16:24:38 +01:00
$dbToken->used = true;
TokenModel::save($dbToken);
UserModel::save($dbUser);
2013-11-16 18:40:26 +01:00
LogHelper::log('{subject} just activated account', ['subject' => TextHelper::reprUser($dbUser)]);
2013-11-16 18:40:26 +01:00
$message = 'Activation completed successfully.';
2014-04-29 21:35:29 +02:00
if (getConfig()->registration->staffActivation)
2013-11-16 18:40:26 +01:00
$message .= ' However, your account still must be confirmed by staff.';
Messenger::message($message);
2013-10-16 18:07:23 +02:00
2014-04-29 21:35:29 +02:00
if (!getConfig()->registration->staffActivation)
2013-10-16 18:07:23 +02:00
{
2014-05-01 16:12:37 +02:00
Auth::setCurrentUser($dbUser);
2013-10-16 18:07:23 +02:00
}
}
2013-11-16 19:24:33 +01:00
public function passwordResetAction($token)
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$context->viewName = 'message';
Assets::setSubTitle('password reset');
2013-11-16 19:24:33 +01:00
$dbToken = TokenModel::findByToken($token);
TokenModel::checkValidity($dbToken);
2013-11-16 19:24:33 +01:00
$alphabet = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
$randomPassword = join('', array_map(function($x) use ($alphabet)
{
return $alphabet[$x];
}, array_rand($alphabet, 8)));
$dbUser = $dbToken->getUser();
$dbUser->passHash = UserModel::hashPassword($randomPassword, $dbUser->passSalt);
2013-11-16 19:24:33 +01:00
$dbToken->used = true;
TokenModel::save($dbToken);
UserModel::save($dbUser);
2013-11-16 19:24:33 +01:00
LogHelper::log('{subject} just reset password', ['subject' => TextHelper::reprUser($dbUser)]);
$message = 'Password reset successful. Your new password is **' . $randomPassword . '**.';
Messenger::message($message);
2014-05-01 16:12:37 +02:00
Auth::setCurrentUser($dbUser);
2013-11-16 19:24:33 +01:00
}
public function passwordResetProxyAction()
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$context->viewName = 'user-select';
Assets::setSubTitle('password reset');
2013-11-16 19:24:33 +01:00
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
2013-11-16 19:24:33 +01:00
2014-04-30 08:08:24 +02:00
$name = InputHelper::get('name');
$user = UserModel::findByNameOrEmail($name);
if (empty($user->emailConfirmed))
throw new SimpleException('This user has no e-mail confirmed; password reset cannot proceed');
self::sendPasswordResetConfirmation($user);
Messenger::message('E-mail sent. Follow instructions to reset password.');
2013-11-16 19:24:33 +01:00
}
public function activationProxyAction()
{
2014-04-29 21:35:29 +02:00
$context = getContext();
$context->viewName = 'user-select';
Assets::setSubTitle('account activation');
2013-11-16 19:24:33 +01:00
2014-04-30 08:08:24 +02:00
if (!InputHelper::get('submit'))
return;
$name = InputHelper::get('name');
$user = UserModel::findByNameOrEmail($name);
if (empty($user->emailUnconfirmed))
{
2014-04-30 08:08:24 +02:00
if (!empty($user->emailConfirmed))
throw new SimpleException('E-mail was already confirmed; activation skipped');
else
throw new SimpleException('This user has no e-mail specified; activation cannot proceed');
}
2014-04-30 08:08:24 +02:00
self::sendEmailChangeConfirmation($user);
Messenger::message('Activation e-mail resent.');
2014-04-30 08:08:24 +02:00
}
private function loadUserView($user)
{
$context = getContext();
$flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', []));
$context->flagged = $flagged;
$context->transport->user = $user;
$context->handleExceptions = true;
$context->viewName = 'user-view';
}
private static function sendTokenizedEmail(
$user,
$body,
$subject,
$senderName,
$senderEmail,
$recipientEmail,
$linkActionName)
{
//prepare unique user token
$token = TokenModel::spawn();
$token->setUser($user);
$token->token = TokenModel::forgeUnusedToken();
$token->used = false;
$token->expires = null;
TokenModel::save($token);
getContext()->mailSent = true;
$tokens = [];
$tokens['host'] = $_SERVER['HTTP_HOST'];
$tokens['token'] = $token->token; //gosh this code looks so silly
$tokens['nl'] = PHP_EOL;
if ($linkActionName !== null)
$tokens['link'] = \Chibi\Router::linkTo(['UserController', $linkActionName], ['token' => $token->token]);
$body = wordwrap(TextHelper::replaceTokens($body, $tokens), 70);
$subject = TextHelper::replaceTokens($subject, $tokens);
$senderName = TextHelper::replaceTokens($senderName, $tokens);
$senderEmail = TextHelper::replaceTokens($senderEmail, $tokens);
if (empty($recipientEmail))
throw new SimpleException('Destination e-mail address was not found');
$messageId = $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) . '@' . $_SERVER['HTTP_HOST'];
$headers = [];
$headers []= sprintf('MIME-Version: 1.0');
$headers []= sprintf('Content-Transfer-Encoding: 7bit');
$headers []= sprintf('Date: %s', date('r', $_SERVER['REQUEST_TIME']));
$headers []= sprintf('Message-ID: <%s>', $messageId);
$headers []= sprintf('From: %s <%s>', $senderName, $senderEmail);
$headers []= sprintf('Reply-To: %s', $senderEmail);
$headers []= sprintf('Return-Path: %s', $senderEmail);
$headers []= sprintf('Subject: %s', $subject);
$headers []= sprintf('Content-Type: text/plain; charset=utf-8', $subject);
$headers []= sprintf('X-Mailer: PHP/%s', phpversion());
$headers []= sprintf('X-Originating-IP: %s', $_SERVER['SERVER_ADDR']);
$encodedSubject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
mail($recipientEmail, $encodedSubject, $body, implode("\r\n", $headers), '-f' . $senderEmail);
LogHelper::log('Sending e-mail with subject "{subject}" to {mail}', [
'subject' => $subject,
'mail' => $recipientEmail]);
}
private static function sendEmailChangeConfirmation($user)
{
$regConfig = getConfig()->registration;
if (!$regConfig->confirmationEmailEnabled)
{
$user->emailConfirmed = $user->emailUnconfirmed;
$user->emailUnconfirmed = null;
return;
}
return self::sendTokenizedEmail(
$user,
$regConfig->confirmationEmailBody,
$regConfig->confirmationEmailSubject,
$regConfig->confirmationEmailSenderName,
$regConfig->confirmationEmailSenderEmail,
$user->emailUnconfirmed,
'activationAction');
}
private static function sendPasswordResetConfirmation($user)
{
$regConfig = getConfig()->registration;
return self::sendTokenizedEmail(
$user,
$regConfig->passwordResetEmailBody,
$regConfig->passwordResetEmailSubject,
$regConfig->passwordResetEmailSenderName,
$regConfig->passwordResetEmailSenderEmail,
$user->emailConfirmed,
'passwordResetAction');
}
2013-10-05 19:24:08 +02:00
}