1
|
|
|
<?php namespace Anomaly\UsersModule\User\Password; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Message\MessageBag; |
4
|
|
|
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface; |
5
|
|
|
use Anomaly\UsersModule\User\UserPassword; |
6
|
|
|
use Illuminate\Contracts\Config\Repository; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ResetPasswordFormHandler |
10
|
|
|
* |
11
|
|
|
* @link http://pyrocms.com/ |
12
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
13
|
|
|
* @author Ryan Thompson <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class ResetPasswordFormHandler |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Handle the form. |
20
|
|
|
* |
21
|
|
|
* @param UserRepositoryInterface $users |
22
|
|
|
* @param ResetPasswordFormBuilder $builder |
23
|
|
|
* @param MessageBag $messages |
24
|
|
|
* @param UserPassword $password |
25
|
|
|
*/ |
26
|
|
|
public function handle( |
27
|
|
|
UserRepositoryInterface $users, |
28
|
|
|
ResetPasswordFormBuilder $builder, |
29
|
|
|
MessageBag $messages, |
30
|
|
|
UserPassword $password |
31
|
|
|
) { |
32
|
|
|
$user = $users->findByEmail($builder->getEmail()); |
33
|
|
|
|
34
|
|
|
/* |
35
|
|
|
* If we can't find the user by the email |
36
|
|
|
* provided then head back to the form. |
37
|
|
|
*/ |
38
|
|
|
if (!$user) { |
39
|
|
|
|
40
|
|
|
$messages->error(trans('anomaly.module.users::error.reset_password')); |
41
|
|
|
|
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/* |
46
|
|
|
* If we can't successfully reset the |
47
|
|
|
* provided user then back back to the form. |
48
|
|
|
*/ |
49
|
|
|
if (!$password->reset($user, $builder->getCode(), $builder->getFormValue('password'))) { |
50
|
|
|
|
51
|
|
|
$messages->error(trans('anomaly.module.users::error.reset_password')); |
52
|
|
|
|
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$messages->success(trans('anomaly.module.users::success.reset_password')); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|