@@ 19-77 (lines=59) @@ | ||
16 | * @since 1.8.0 |
|
17 | * @access private |
|
18 | */ |
|
19 | function _elgg_set_user_password() { |
|
20 | $current_password = get_input('current_password', null, false); |
|
21 | $password = get_input('password', null, false); |
|
22 | $password2 = get_input('password2', null, false); |
|
23 | $user_guid = get_input('guid'); |
|
24 | ||
25 | if ($user_guid) { |
|
26 | $user = get_user($user_guid); |
|
27 | } else { |
|
28 | $user = elgg_get_logged_in_user_entity(); |
|
29 | } |
|
30 | ||
31 | if ($user && $password) { |
|
32 | // let admin user change anyone's password without knowing it except his own. |
|
33 | if (!elgg_is_admin_logged_in() || elgg_is_admin_logged_in() && $user->guid == elgg_get_logged_in_user_guid()) { |
|
34 | $credentials = array( |
|
35 | 'username' => $user->username, |
|
36 | 'password' => $current_password |
|
37 | ); |
|
38 | ||
39 | try { |
|
40 | pam_auth_userpass($credentials); |
|
41 | } catch (LoginException $e) { |
|
42 | register_error(elgg_echo('LoginException:ChangePasswordFailure')); |
|
43 | return false; |
|
44 | } |
|
45 | } |
|
46 | ||
47 | try { |
|
48 | $result = validate_password($password); |
|
49 | } catch (RegistrationException $e) { |
|
50 | register_error($e->getMessage()); |
|
51 | return false; |
|
52 | } |
|
53 | ||
54 | if ($result) { |
|
55 | if ($password == $password2) { |
|
56 | $user->setPassword($password); |
|
57 | _elgg_services()->persistentLogin->handlePasswordChange($user, elgg_get_logged_in_user_entity()); |
|
58 | ||
59 | if ($user->save()) { |
|
60 | system_message(elgg_echo('user:password:success')); |
|
61 | return true; |
|
62 | } else { |
|
63 | register_error(elgg_echo('user:password:fail')); |
|
64 | } |
|
65 | } else { |
|
66 | register_error(elgg_echo('user:password:fail:notsame')); |
|
67 | } |
|
68 | } else { |
|
69 | register_error(elgg_echo('user:password:fail:tooshort')); |
|
70 | } |
|
71 | } else { |
|
72 | // no change |
|
73 | return; |
|
74 | } |
|
75 | ||
76 | return false; |
|
77 | } |
|
78 | ||
79 | /** |
|
80 | * Set a user's display name |
@@ 17-75 (lines=59) @@ | ||
14 | * @since 1.8.0 |
|
15 | * @access private |
|
16 | */ |
|
17 | function _elgg_set_user_password() { |
|
18 | $current_password = get_input('current_password', null, false); |
|
19 | $password = get_input('password', null, false); |
|
20 | $password2 = get_input('password2', null, false); |
|
21 | $user_guid = get_input('guid'); |
|
22 | ||
23 | if ($user_guid) { |
|
24 | $user = get_user($user_guid); |
|
25 | } else { |
|
26 | $user = elgg_get_logged_in_user_entity(); |
|
27 | } |
|
28 | ||
29 | if ($user && $password) { |
|
30 | // let admin user change anyone's password without knowing it except his own. |
|
31 | if (!elgg_is_admin_logged_in() || elgg_is_admin_logged_in() && $user->guid == elgg_get_logged_in_user_guid()) { |
|
32 | $credentials = array( |
|
33 | 'username' => $user->username, |
|
34 | 'password' => $current_password |
|
35 | ); |
|
36 | ||
37 | try { |
|
38 | pam_auth_userpass($credentials); |
|
39 | } catch (LoginException $e) { |
|
40 | register_error(elgg_echo('LoginException:ChangePasswordFailure')); |
|
41 | return false; |
|
42 | } |
|
43 | } |
|
44 | ||
45 | try { |
|
46 | $result = validate_password($password); |
|
47 | } catch (RegistrationException $e) { |
|
48 | register_error($e->getMessage()); |
|
49 | return false; |
|
50 | } |
|
51 | ||
52 | if ($result) { |
|
53 | if ($password == $password2) { |
|
54 | $user->setPassword($password); |
|
55 | _elgg_services()->persistentLogin->handlePasswordChange($user, elgg_get_logged_in_user_entity()); |
|
56 | ||
57 | if ($user->save()) { |
|
58 | system_message(elgg_echo('user:password:success')); |
|
59 | return true; |
|
60 | } else { |
|
61 | register_error(elgg_echo('user:password:fail')); |
|
62 | } |
|
63 | } else { |
|
64 | register_error(elgg_echo('user:password:fail:notsame')); |
|
65 | } |
|
66 | } else { |
|
67 | register_error(elgg_echo('user:password:fail:tooshort')); |
|
68 | } |
|
69 | } else { |
|
70 | // no change |
|
71 | return null; |
|
72 | } |
|
73 | ||
74 | return false; |
|
75 | } |
|
76 | ||
77 | /** |
|
78 | * Set a user's display name |