1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the 2amigos/yii2-usuario project. |
5
|
|
|
* |
6
|
|
|
* (c) 2amigOS! <http://2amigos.us/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view |
9
|
|
|
* the LICENSE file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Da\User\Command; |
13
|
|
|
|
14
|
|
|
use Da\User\Model\User; |
15
|
|
|
use Da\User\Query\UserQuery; |
16
|
|
|
use Da\User\Service\ResetPasswordService; |
17
|
|
|
use Da\User\Traits\ContainerAwareTrait; |
18
|
|
|
use Yii; |
19
|
|
|
use yii\base\InvalidConfigException; |
20
|
|
|
use yii\base\Module; |
21
|
|
|
use yii\console\Controller; |
22
|
|
|
use yii\helpers\Console; |
23
|
|
|
|
24
|
|
|
class PasswordController extends Controller |
25
|
|
|
{ |
26
|
|
|
use ContainerAwareTrait; |
27
|
|
|
|
28
|
|
|
protected $userQuery; |
29
|
|
|
|
30
|
|
|
public function __construct($id, Module $module, UserQuery $userQuery, array $config = []) |
31
|
|
|
{ |
32
|
|
|
$this->userQuery = $userQuery; |
33
|
|
|
parent::__construct($id, $module, $config); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* This command updates the user's password. |
38
|
|
|
* |
39
|
|
|
* @param string $usernameOrEmail Username or email of the user who's password needs to be updated |
40
|
|
|
* @param string $password The new password |
41
|
|
|
* |
42
|
|
|
* @throws InvalidConfigException |
43
|
|
|
*/ |
44
|
|
|
public function actionIndex($usernameOrEmail, $password) |
45
|
|
|
{ |
46
|
|
|
/** @var User $user */ |
47
|
|
|
$user = $this->userQuery->whereUsernameOrEmail($usernameOrEmail)->one(); |
48
|
|
|
|
49
|
|
|
if ($user === null) { |
50
|
|
|
$this->stdout(Yii::t('usuario', 'User is not found') . "\n", Console::FG_RED); |
51
|
|
|
} else { |
52
|
|
|
if ($this->make(ResetPasswordService::class, [$password, $user])->run()) { |
53
|
|
|
$this->stdout(Yii::t('usuario', 'Password has been changed') . "\n", Console::FG_GREEN); |
54
|
|
|
} else { |
55
|
|
|
$this->stdout(Yii::t('usuario', 'Error occurred while changing password') . "\n", Console::FG_RED); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|