Created
February 12, 2017 13:47
-
-
Save woganmay/5b839d4c54252dc85392981f51fff624 to your computer and use it in GitHub Desktop.
Activate an existing Flarum user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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