function set_new_password($data) { global $mensaje; $userId = ""; $token = ""; $newPassword = ""; $repeatPassword = ""; parse_str($data); $user = get_user_by("id", $userId); if (!$user) { $mensaje->add_error("Usuario no valido."); return; } if ($newPassword == "") { $mensaje->add_error("Debes especificar una contraseña."); return; } if ($newPassword != $repeatPassword) { $mensaje->add_error("Las contraseñas no coinciden."); return; } $recovery = PassRecoveryWp::GetByUserId($userId); if (DESARROLLO) { $mensaje->add_data_named("passChange", $recovery); } if (!$recovery || $recovery->IsExpired() || !$recovery->IsValidToken($token)) { $mensaje->add_error("Enlace expirado."); return; } // Do the actual password change here. wp_update_user(array('ID' => $recovery->UserId(), 'user_pass' => $newPassword)); $recovery->SetExpired(); //TODO; mail_password_reset(get_user_by("id", $userId), $newPassword); // Loguear al usuario $creds = array(); $creds['user_login'] = $user->user_login; $creds['user_password'] = $newPassword; $creds['remember'] = false; $user = wp_signon($creds, false); $mensaje->add_data_named("redirect", get_permalink(PERFIL)); $mensaje->add_mensaje("¡Contraseña cambiada correctamente!, estamos recargando la página para que puedas acceder..."); }
/** * Inserts a new pass-recovery entry in the db, and returns an object representing that newly created entry. * * The created entry will contain a valid and unique token. * * @param $email * @return null|PassRecoveryWp */ public static function CreateNewValidEntry($email) { $userId = email_exists($email); if ($userId === false) { return null; } $entry = new PassRecoveryWp(); $entry->userId = $userId; $entry->timestamp = time(); $entry->expired = false; $entry->token = PassRecoveryWp::RandString(); update_user_meta($userId, PassRecoveryWp::PassRecoveryMetaKey, $entry); return get_user_meta($userId, PassRecoveryWp::PassRecoveryMetaKey, true); }