Skip to content

Instantly share code, notes, and snippets.

@woganmay
Created February 12, 2017 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woganmay/5b839d4c54252dc85392981f51fff624 to your computer and use it in GitHub Desktop.
Save woganmay/5b839d4c54252dc85392981f51fff624 to your computer and use it in GitHub Desktop.
Activate an existing Flarum user
<?php
$api_url = "https://my.flarum.url/api/users/" . $userid; // See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$token = $session->token; // See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
// This must be a token for a user with Administrator access
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Token ' . $token
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'data' => [
'attributes' => [
"isActivated" => true
]
]
]));
$result = curl_exec($ch);
$user = json_decode($result);
$user; // Will be a large JSON object containing the user's details:
/* SAMPLE
{
"data":
"type": "users",
"id": "1",
"attributes": {
"username": "johnsmith",
"joinTime": "2017-02-11T16:34:40+00:00",
"isActivated": true,
"email": "john.smith@example.org",
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment