update folder location
This commit is contained in:
50
src/User/Strategy/DefaultEmailChangeStrategy.php
Normal file
50
src/User/Strategy/DefaultEmailChangeStrategy.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Strategy;
|
||||
|
||||
use Da\User\Contracts\MailChangeStrategyInterface;
|
||||
use Da\User\Factory\MailFactory;
|
||||
use Da\User\Factory\TokenFactory;
|
||||
use Da\User\Form\SettingsForm;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Yii;
|
||||
|
||||
class DefaultEmailChangeStrategy implements MailChangeStrategyInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
protected $form;
|
||||
|
||||
public function __construct(SettingsForm $form)
|
||||
{
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->form->getUser()->unconfirmed_email = $this->form->email;
|
||||
|
||||
$token = TokenFactory::makeConfirmNewMailToken($this->form->getUser()->id);
|
||||
|
||||
$mailService = MailFactory::makeReconfirmationMailerService($this->form->getUser(), $token);
|
||||
|
||||
if ($mailService->run()) {
|
||||
Yii::$app
|
||||
->session
|
||||
->setFlash('info', Yii::t('usuario', 'A confirmation message has been sent to your new email address'));
|
||||
|
||||
return $this->form->getUser()->save();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
32
src/User/Strategy/InsecureEmailChangeStrategy.php
Normal file
32
src/User/Strategy/InsecureEmailChangeStrategy.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Strategy;
|
||||
|
||||
use Da\User\Contracts\MailChangeStrategyInterface;
|
||||
use Da\User\Form\SettingsForm;
|
||||
|
||||
class InsecureEmailChangeStrategy implements MailChangeStrategyInterface
|
||||
{
|
||||
protected $form;
|
||||
|
||||
public function __construct(SettingsForm $form)
|
||||
{
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$this->form->getUser()->email = $this->form->email;
|
||||
|
||||
return $this->form->getUser()->save();
|
||||
}
|
||||
}
|
||||
62
src/User/Strategy/SecureEmailChangeStrategy.php
Normal file
62
src/User/Strategy/SecureEmailChangeStrategy.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Da\User\Strategy;
|
||||
|
||||
use Da\User\Contracts\MailChangeStrategyInterface;
|
||||
use Da\User\Factory\MailFactory;
|
||||
use Da\User\Factory\TokenFactory;
|
||||
use Da\User\Form\SettingsForm;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Yii;
|
||||
|
||||
class SecureEmailChangeStrategy implements MailChangeStrategyInterface
|
||||
{
|
||||
use ContainerAwareTrait;
|
||||
|
||||
protected $form;
|
||||
|
||||
public function __construct(SettingsForm $form)
|
||||
{
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
if ($this->make(DefaultEmailChangeStrategy::class, [$this->form])->run()) {
|
||||
$token = TokenFactory::makeConfirmOldMailToken($this->form->getUser()->id);
|
||||
$mailService = MailFactory::makeReconfirmationMailerService($this->form->getUser(), $token);
|
||||
|
||||
if ($mailService->run()) {
|
||||
// unset flags if they exist
|
||||
$this->form->getUser()->flags &= ~User::NEW_EMAIL_CONFIRMED;
|
||||
$this->form->getUser()->flags &= ~User::OLD_EMAIL_CONFIRMED;
|
||||
if ($this->form->getUser()->save(false)) {
|
||||
Yii::$app
|
||||
->session
|
||||
->setFlash(
|
||||
'info',
|
||||
Yii::t(
|
||||
'usuario',
|
||||
'We have sent confirmation links to both old and new email addresses. '.
|
||||
'You must click both links to complete your request.'
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user