1 | <?php |
||
2 | /** |
||
3 | * Reset a user's password. |
||
4 | * |
||
5 | * This is an admin action that generates a new salt and password |
||
6 | * for a user, then emails the password to the user's registered |
||
7 | * email address. |
||
8 | * |
||
9 | * NOTE: This is different to the "reset password" link users |
||
10 | * can use in that it does not first email the user asking if |
||
11 | * they want to have their password reset. |
||
12 | */ |
||
13 | |||
14 | $guid = (int) get_input('guid'); |
||
15 | $user = get_user($guid); |
||
16 | |||
17 | if (!$user || !$user->canEdit()) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
18 | return elgg_error_response(elgg_echo('admin:user:resetpassword:no')); |
||
19 | } |
||
20 | |||
21 | $password = generate_random_cleartext_password(); |
||
22 | |||
23 | if (!force_user_password_reset($user->guid, $password)) { |
||
24 | return elgg_error_response(elgg_echo('admin:user:resetpassword:no')); |
||
25 | } |
||
26 | |||
27 | notify_user($user->guid, |
||
28 | elgg_get_site_entity()->guid, |
||
29 | elgg_echo('email:resetpassword:subject', [], $user->language), |
||
30 | elgg_echo('email:resetpassword:body', [$user->username, $password], $user->language), |
||
31 | [ |
||
32 | 'object' => $user, |
||
33 | 'action' => 'resetpassword', |
||
34 | 'password' => $password, |
||
35 | ], |
||
36 | 'email'); |
||
37 | |||
38 | return elgg_ok_response('', elgg_echo('admin:user:resetpassword:yes')); |
||
39 |