starting with password recovery procedures
This commit is contained in:
@ -38,6 +38,19 @@ class MailService implements ServiceInterface
|
||||
$this->mailer->getView()->theme = Yii::$app->view->theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setViewParam($name, $value)
|
||||
{
|
||||
$this->params[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
@ -1,15 +1,63 @@
|
||||
<?php
|
||||
namespace Da\User\Service;
|
||||
|
||||
/**
|
||||
*
|
||||
* PasswordRecoveryService.php
|
||||
*
|
||||
* Date: 5/12/16
|
||||
* Time: 14:18
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class PasswordRecoveryService
|
||||
use Da\User\Contracts\ServiceInterface;
|
||||
use Da\User\Model\Token;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Query\UserQuery;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\log\Logger;
|
||||
|
||||
class PasswordRecoveryService implements ServiceInterface
|
||||
{
|
||||
protected $query;
|
||||
|
||||
protected $email;
|
||||
protected $mailService;
|
||||
protected $securityHelper;
|
||||
protected $logger;
|
||||
|
||||
public function __construct($email, MailService $mailService, UserQuery $query, Logger $logger)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->mailService = $mailService;
|
||||
$this->query = $query;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
/** @var User $user */
|
||||
$user = $this->query->whereEmail($this->email)->one();
|
||||
/** @var Token $token */
|
||||
$token = Yii::createObject(
|
||||
[
|
||||
'class' => Token::class,
|
||||
'user_id' => $user->id,
|
||||
'type' => Token::TYPE_RECOVERY
|
||||
]
|
||||
);
|
||||
|
||||
if (!$token->save(false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->mailService->setViewParam('user', $user);
|
||||
$this->mailService->setViewParam('token', $token);
|
||||
|
||||
if (!$this->mailService->run()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,15 +1,31 @@
|
||||
<?php
|
||||
namespace Da\User\Service;
|
||||
|
||||
/**
|
||||
*
|
||||
* ResetPasswordService.php
|
||||
*
|
||||
* Date: 5/12/16
|
||||
* Time: 14:17
|
||||
* @author Antonio Ramirez <hola@2amigos.us>
|
||||
*/
|
||||
class ResetPasswordService
|
||||
|
||||
use Da\User\Contracts\ServiceInterface;
|
||||
use Da\User\Helper\SecurityHelper;
|
||||
use Da\User\Model\User;
|
||||
|
||||
class ResetPasswordService implements ServiceInterface
|
||||
{
|
||||
protected $password;
|
||||
protected $model;
|
||||
protected $securityHelper;
|
||||
|
||||
public function __construct($password, User $model, SecurityHelper $securityHelper)
|
||||
{
|
||||
$this->password;
|
||||
$this->model = $model;
|
||||
$this->securityHelper = $securityHelper;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
return (bool)$this->model->updateAttributes(
|
||||
[
|
||||
'password_hash' => $this->securityHelper->generatePasswordHash($this->password)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ class UserCreateService implements ServiceInterface
|
||||
|
||||
} catch (Exception $e) {
|
||||
$transaction->rollBack();
|
||||
$this->logger->log($e->getMessage(), Logger::LEVEL_WARNING);
|
||||
$this->logger->log($e->getMessage(), Logger::LEVEL_ERROR);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user