MyBB Community Forums

Full Version: How to enable users to cancel account via link
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys

I created my second Mybb Forum, which was created from my first one, which has already 12 thousand members.

So all of those members were registered automatically on this second one.

I wanted to give them a very easy way to cancel their account, even if they don't remember their password anymore. So I thought in sending them a link to a page (through a mass email) to enable them to cancel their account if they want to, in which they would confirm their email and have their account deleted (without deleting their threads and posts).

What would be the easiest way to do that? I don't want them to log into the forum to do that, as many wouldn't remember their passwords anymore.

I thought in creating a php page, they would open it already with their id hidden on it, and would have a field to confirm their email, and would post to another php which would effectively delete their account.

Is there already some api call to do that? Is there some example to start from?

Thanks a lot for the help
Eco
Check out this plugin: http://community.mybb.com/thread-115714.html
The users that don't remember their password can use the "Forgot my password" link to reset it, then delete their account.
thanks for the suggestion @MyBB Monster

But I want to make it easier for people to delete their account after receiving my email.

Many people have problem in restoring their password, and as I added them without their permission to another site, it has to be very easy for them to delete their account from it.


I think my question would be something a bit more technical, like what libs from mybb to use to remove an user.
(02-21-2014, 06:27 AM)blogantinom Wrote: [ -> ]thanks for the suggestion @MyBB Monster

But I want to make it easier for people to delete their account after receiving my email.

Many people have problem in restoring their password, and as I added them without their permission to another site, it has to be very easy for them to delete their account from it.


I think my question would be something a bit more technical, like what libs from mybb to use to remove an user.

So you want them to request to you that they wana delete their account even if they are offline from the board right. Then you go and send them a link to their email to remove their account ?
(02-21-2014, 06:41 AM)KLOX94 Wrote: [ -> ]So you want them to request to you that they wana delete their account even if they are offline from the board right. Then you go and send them a link to their email to remove their account ?

Almost that, let me describe it more precisely:

1) Send email with link: A mass email is sent, it will contain a link to a php page on the forum domain. This link will carry the user id

2) User clicks the link and opens the page: The user doesn't want to be a user on this forum, and then clicks on the link.

3) User fills the form with his email: The php page is opened, it informs that we are sorry he wants to unregister, but he can carry on removing the user filling a form so that he can put the email. This is to avoid people other than the user himself to remove other accounts which is not himself/herself.

4) Page processes the filled email and removes the user: The target of that form will be itself or another php page, which will take the user id, fetch the usermail and compare it with what the user filled on the form. If it matches it removes the user (that's what I don't know how to do) and sends to a page saying the removal has been done. It it doesn't match, it send it back to the form showing an error message.

Actually I'm not very good with PHP, but I think I can do everything but:

1) How to send a link with the user ID on a mass email? I see that I can use a few variables, such as user login or user email ("{email}"). But at the moment there is no way to include the user id. Is there some workaround to enable to use the ID as a variable on the mass email? Thinking again, I could use the user login instead of the id.

2) How to remove the user based on the user login?. I will need this on step 4, so that if the email of the user fetched from DB matches the email informed by the user I would then remove the user, without removing his posts.

I noticed on the code of the admin CP that on the delete user option I have:

Quote:index.php?module=user-users&action=delete&uid=48&my_post_key=...

and looking at the delete action inside the module/user/users.php we have a routine, which I modified a bit and came up with the following:

still missing changing the query to use the username
Quote:

$query = $db->simple_select("users", "*", "uid='".intval($mybb->input['uid'])."'");
$user = $db->fetch_array($query);

// Does the user not exist?
if(!$user['uid'])
{
echo('error: no user');
return;
}

// Delete the user
$db->delete_query("userfields", "ufid='{$user['uid']}'");
$db->delete_query("privatemessages", "uid='{$user['uid']}'");
$db->delete_query("events", "uid='{$user['uid']}'");
$db->delete_query("forumsubscriptions", "uid='{$user['uid']}'");
$db->delete_query("threadsubscriptions", "uid='{$user['uid']}'");
$db->delete_query("sessions", "uid='{$user['uid']}'");
$db->delete_query("banned", "uid='{$user['uid']}'");
$db->delete_query("threadratings", "uid='{$user['uid']}'");
$db->delete_query("users", "uid='{$user['uid']}'");
$db->delete_query("joinrequests", "uid='{$user['uid']}'");
$db->delete_query("warnings", "uid='{$user['uid']}'");
$db->delete_query("reputation", "uid='{$user['uid']}' OR adduid='{$user['uid']}'");
$db->delete_query("awaitingactivation", "uid='{$user['uid']}'");
//$db->delete_query("posts", "uid = '{$user['uid']}' AND visible = '-2'");
//$db->delete_query("threads", "uid = '{$user['uid']}' AND visible = '-2'");

// Update forum stats
update_stats(array('numusers' => '-1'));

// Update forums & threads if user is the lastposter
$db->update_query("posts", array('uid' => 0), "uid='{$user['uid']}'");
$db->update_query("forums", array("lastposteruid" => 0), "lastposteruid = '{$user['uid']}'");
$db->update_query("threads", array("lastposteruid" => 0), "lastposteruid = '{$user['uid']}'");

// Did this user have an uploaded avatar?
if($user['avatartype'] == "upload")
{
// Removes the ./ at the beginning the timestamp on the end...
@unlink("../".substr($user['avatar'], 2, -20));
}

// Was this user a moderator?
if(is_moderator($user['uid']))
{
$db->delete_query("moderators", "id='{$user['uid']}' AND isgroup = '0'");
$cache->update_moderators();
}


flash_message($lang->success_user_deleted, 'success');

Is this feasible to do?
It can be done, with a plugin. However I am not a Plugin developer and don't have the know-how to do so, however I'm sure it wouldn't be too hard to code such a thing. If you are willing to pay, I recomend contacting @effone over at http://demonate.com/

However the closest I can find is: http://community.mybb.com/thread-115714.html
I don't think it would have to be a plugin, a php page inside mybb would do it.