MyBB Community Forums

Full Version: [SOLVED] Activate User - API Request or similar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good Day!

I wanted to ask, whether there is something like an API for activating user accounts? 

If I have to make changes to the database manually, that would be fine too. 
I'm just not too sure to which tables. 

What I've tried so far:

- Delete the record of the user in the "mybb_awaitingactivation" table
- Change the usergroup to "Registered" in the "mybb_users" table

So far so good. This appears to work. However if I login as Administrator, mybb still notifies me with:

"There is 1 account awaiting activation. Please go to your ACP to activate the user. Go to the ACP."

So I guess it hasn't completely activated the account. 

What I want to do in detail:

Basically I want to handle user Activations headless. 
I've set up an external API server and changed the Mail Template accordingly. 

I'm using mybb's generated code for my API. 

$l['email_activateaccount'] = "Click to activate: https://api.myserver.com?token={5}";

Which then results in something like:

https://api.myserver.com?token=V7F1vMpG

Now my question is, how do I activate the account based on this "token"? 
Is there an internal API for that? Or do I have to manipulate the Database manually?

If so, which tables?

Best Regards
Update: More or less solved. 

I found a code snippet from a plugin and adapted it a bit. 

function activateUsers($profile){
    global $db, $cache;
    $user_ids = implode(", ", $profile);
    if (empty($user_ids)) die("No user selcted");
    $query = $db->simple_select("users", "uid, username, email, usergroup, coppauser", "uid IN ({$user_ids})");
    while ($user = $db->fetch_array($query)){
        if($user['coppauser']) $updated_user = array("coppauser" => 0);
        else $db->delete_query("awaitingactivation", "uid='{$user['uid']}'");
        if ($user['usergroup'] == 5) $updated_user['usergroup'] = 2;
        $db->update_query("users", $updated_user, "uid='{$user['uid']}'");
    }
    $cache->update_awaitingactivation();
}

//activateUsers(["1", "2"]);

I implemented this as a plugin in MyBB. Now I just need to adapt it for external calls.

I already tested the script and it works like a charm.
There is no "n accounts awaiting activation." message anymore either.

Just wanted to leave this here in case anyone who stumbles upon this needed the same. 

Full code for my plugin implementation: https://github.com/EpticMC/MyBB-Activator