static function forgotPassword($input) { $username = Helpers::getUsernameByInput($input["username"]); $user = get_user_by_username($username); if ($user) { $result = send_new_password_request($user->guid); if (!$result) { throw new Exception("unknown_error"); } } else { // on purpose, do not give any feedback when user is not found } return ["status" => "ok"]; }
<?php $email = get_input('email'); $user = get_user_by_email($email); if (is_array($user)) { $user = $user[0]; } if ($user) { if ($user->validated) { if (send_new_password_request($user->guid)) { system_message(elgg_echo('user:password:resetreq:success')); } else { register_error(elgg_echo('user:password:resetreq:fail')); } } else { if (!trigger_plugin_hook('unvalidated_requestnewpassword', 'user', array('entity' => $user))) { // if plugins have not registered an action, the default action is to // trigger the validation event again and assume that the validation // event will display an appropriate message trigger_elgg_event('validate', 'user', $user); } } } else { register_error(sprintf(elgg_echo('user:email:notfound'), $email)); } forward();
*/ $username = get_input('username'); // allow email addresses if (strpos($username, '@') !== false && ($users = get_user_by_email($username))) { $username = $users[0]->username; } $user = get_user_by_username($username); if ($user) { // cyu - 04/01/2016: use the hook to manage notification (if plugin is activated) / do we need to change core? if (elgg_is_active_plugin('cp_notifications')) { $message = array('cp_msg_type' => 'cp_forgot_password', 'cp_user_pass_req_guid' => $user->guid); $result = elgg_trigger_plugin_hook('cp_overwrite_notification', 'all', $message); $result = true; // what does elgg_trigger_plugin_hook return? } else { $result = send_new_password_request($user->guid); } //if (send_new_password_request($user->guid)) { if ($result) { system_message(elgg_echo('user:password:changereq:success')); forward('/login'); } else { register_error(elgg_echo('user:password:changereq:fail')); forward('/forgotpassword'); } } else { register_error(elgg_echo('user:username:notfound', array($username))); forward('/forgotpassword'); } //forward(current_page_url()); forward('/login');