%PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
| Server IP : 14.207.165.8 / Your IP : 216.73.216.26 Web Server : Apache/2.4.18 (Ubuntu) System : Linux 246 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : root ( 0) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,pcntl_exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/thread-self/root/var/www/html/ppaobm/vendor/dektrium/yii2-user/ |
Upload File : |
<?php
/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace dektrium\user;
use dektrium\user\models\Token;
use dektrium\user\models\User;
use Yii;
use yii\base\Component;
/**
* Mailer.
*
* @author Dmitry Erofeev <dmeroff@gmail.com>
*/
class Mailer extends Component
{
/** @var string */
public $viewPath = '@dektrium/user/views/mail';
/** @var string|array Default: `Yii::$app->params['adminEmail']` OR `no-reply@example.com` */
public $sender;
/** @var \yii\mail\BaseMailer Default: `Yii::$app->mailer` */
public $mailerComponent;
/** @var string */
protected $welcomeSubject;
/** @var string */
protected $newPasswordSubject;
/** @var string */
protected $confirmationSubject;
/** @var string */
protected $reconfirmationSubject;
/** @var string */
protected $recoverySubject;
/** @var \dektrium\user\Module */
protected $module;
/**
* @return string
*/
public function getWelcomeSubject()
{
if ($this->welcomeSubject == null) {
$this->setWelcomeSubject(Yii::t('user', 'Welcome to {0}', Yii::$app->name));
}
return $this->welcomeSubject;
}
/**
* @param string $welcomeSubject
*/
public function setWelcomeSubject($welcomeSubject)
{
$this->welcomeSubject = $welcomeSubject;
}
/**
* @return string
*/
public function getNewPasswordSubject()
{
if ($this->newPasswordSubject == null) {
$this->setNewPasswordSubject(Yii::t('user', 'Your password on {0} has been changed', Yii::$app->name));
}
return $this->newPasswordSubject;
}
/**
* @param string $newPasswordSubject
*/
public function setNewPasswordSubject($newPasswordSubject)
{
$this->newPasswordSubject = $newPasswordSubject;
}
/**
* @return string
*/
public function getConfirmationSubject()
{
if ($this->confirmationSubject == null) {
$this->setConfirmationSubject(Yii::t('user', 'Confirm account on {0}', Yii::$app->name));
}
return $this->confirmationSubject;
}
/**
* @param string $confirmationSubject
*/
public function setConfirmationSubject($confirmationSubject)
{
$this->confirmationSubject = $confirmationSubject;
}
/**
* @return string
*/
public function getReconfirmationSubject()
{
if ($this->reconfirmationSubject == null) {
$this->setReconfirmationSubject(Yii::t('user', 'Confirm email change on {0}', Yii::$app->name));
}
return $this->reconfirmationSubject;
}
/**
* @param string $reconfirmationSubject
*/
public function setReconfirmationSubject($reconfirmationSubject)
{
$this->reconfirmationSubject = $reconfirmationSubject;
}
/**
* @return string
*/
public function getRecoverySubject()
{
if ($this->recoverySubject == null) {
$this->setRecoverySubject(Yii::t('user', 'Complete password reset on {0}', Yii::$app->name));
}
return $this->recoverySubject;
}
/**
* @param string $recoverySubject
*/
public function setRecoverySubject($recoverySubject)
{
$this->recoverySubject = $recoverySubject;
}
/** @inheritdoc */
public function init()
{
$this->module = Yii::$app->getModule('user');
parent::init();
}
/**
* Sends an email to a user after registration.
*
* @param User $user
* @param Token $token
* @param bool $showPassword
*
* @return bool
*/
public function sendWelcomeMessage(User $user, Token $token = null, $showPassword = false)
{
return $this->sendMessage(
$user->email,
$this->getWelcomeSubject(),
'welcome',
['user' => $user, 'token' => $token, 'module' => $this->module, 'showPassword' => $showPassword]
);
}
/**
* Sends a new generated password to a user.
*
* @param User $user
* @param Password $password
*
* @return bool
*/
public function sendGeneratedPassword(User $user, $password)
{
return $this->sendMessage(
$user->email,
$this->getNewPasswordSubject(),
'new_password',
['user' => $user, 'password' => $password, 'module' => $this->module]
);
}
/**
* Sends an email to a user with confirmation link.
*
* @param User $user
* @param Token $token
*
* @return bool
*/
public function sendConfirmationMessage(User $user, Token $token)
{
return $this->sendMessage(
$user->email,
$this->getConfirmationSubject(),
'confirmation',
['user' => $user, 'token' => $token]
);
}
/**
* Sends an email to a user with reconfirmation link.
*
* @param User $user
* @param Token $token
*
* @return bool
*/
public function sendReconfirmationMessage(User $user, Token $token)
{
if ($token->type == Token::TYPE_CONFIRM_NEW_EMAIL) {
$email = $user->unconfirmed_email;
} else {
$email = $user->email;
}
return $this->sendMessage(
$email,
$this->getReconfirmationSubject(),
'reconfirmation',
['user' => $user, 'token' => $token]
);
}
/**
* Sends an email to a user with recovery link.
*
* @param User $user
* @param Token $token
*
* @return bool
*/
public function sendRecoveryMessage(User $user, Token $token)
{
return $this->sendMessage(
$user->email,
$this->getRecoverySubject(),
'recovery',
['user' => $user, 'token' => $token]
);
}
/**
* @param string $to
* @param string $subject
* @param string $view
* @param array $params
*
* @return bool
*/
protected function sendMessage($to, $subject, $view, $params = [])
{
$mailer = $this->mailerComponent === null ? Yii::$app->mailer : Yii::$app->get($this->mailerComponent);
$mailer->viewPath = $this->viewPath;
$mailer->getView()->theme = Yii::$app->view->theme;
if ($this->sender === null) {
$this->sender = isset(Yii::$app->params['adminEmail']) ?
Yii::$app->params['adminEmail']
: 'no-reply@example.com';
}
return $mailer->compose(['html' => $view, 'text' => 'text/' . $view], $params)
->setTo($to)
->setFrom($this->sender)
->setSubject($subject)
->send();
}
}