I am trying to suspend a user in Moodle by using Moodle's Web service API functions in PHP.
I can change user fields like firstname, but I am not capable to suspend the user.
It always returns "null".
Here is my code:
<?php
$serverurl = "http://localhost/web/moodle/webservice/rest/server.php?wstoken=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&wsfunction=core_user_update_users&moodlewsrestformat=json";
$params = "users[0][id]=4&users[0][preferences][0][type]=suspended&users[0][preferences][0][value]=true";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $serverurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
print_r($response);
curl_close($ch);
?>
Suspending a user was added to the Web Services in MDL-31465 which made it into version 3.2. If you're on an older version and don't want to upgrade, you can use the core_user_update_users function and set auth to nologin.
The API returning null does not indicate an error - if something goes wrong, you'll get a more verbose error.
with moodle 3.7 should work, but not using"preferences" as in above example but
using following template:
wsfunction=core_user_update_users&users[0][id]=1234&users[0][suspended]=1
Related
I am trying to access API data from CraftingStore Public API.
When I am trying it on localhost, everything works like it should (1st pic, also printing results for to show).
However, when I am trying to view it on the actual website (2nd pic), it is not working but instead saying to enable cookies and to complete captcha.
When on localhost:
When on website:
Also code for accessing the API:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.craftingstore.net/v7/payments?page=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'token:'.$cs_token
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
$dononame = $obj->data[0]->inGameName;
$donobuy = $obj->data[0]->packageName;
What can I do?
This is quite usual for API's with Cloudflare. You'll need to make a page rule for the API domain/URI to disable the Browser Integrity Check.
Source: https://support.cloudflare.com/hc/en-us/articles/200504045-Using-Cloudflare-with-your-API
Seems like a simple task but despite having read their docs I can't figure it out. I've gotten a Storefront Access Token, as per https://help.shopify.com/en/api/storefront-api/getting-started. Then I've used it in the CURL request below. However this just returns: {"errors":"[API] Invalid API key or access token (unrecognized login or wrong password)"}
I found their documentation a bit confusing as they have quite a few different APIs, and whilst it seems that this Storefront Access Token should work for this particular API, perhaps it doesn't?
$url = "https://mysite.myshopify.com/admin/api/2019-07/products/count.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$headers = array(
'X-Shopify-Storefront-Access-Token: 2400d...........a999'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r( $result);
curl_close($ch);
If you are using the Stronfront API your request should point to
https://mysite.myshopify.com/api/2019-07/products/count.json
and not to
https://mysite.myshopify.com/admin/api/2019-07/products/count.json
In addition Storefront Api request are different from the standard ones, have that in mind.
My aim is really simple, but I tried to search all the documents online and I have no valid result.
I am still quite new to Symfony, so I probably would need more explanations.
So I followed all the instructions in this page: https://symfony.com/doc/current/security/custom_provider.html
However, I am stuck on this example code here, which I don't know what to implement.
// make a call to your webservice here
$userData = ...
// pretend it returns an array on success, false if there is no user
if ($userData) {
$password = '...';
// ...
I would like to use my own function to login a third party website. As due to it is an unofficial login (Regardless the security), I will be using Curl and check the Set-Cookie header inside it.
Here is an example that I will use without symfony:
function checkLogin($username, $password) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://example.com/login");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$username&password=$password");
$header = curl_exec($ch);
curl_close ($ch);
return (bool)preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $header);
} //Return true = username and password is correct, hence I can follow up on my own site.
Any help would be appreciated. Thanks!
You should create Token, Listener that will create Token from your user's request and AuthenticationProvider implementing Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface.
Here is example implementation: http://symfony.com/doc/current/security/custom_authentication_provider.html
Don't hesitate to ask questions about it and check if their cross-origin policy allows requests from your host.
I am trying to authenticate using REST APIs, on my PHP backend. However, I am unable to obtain the auth code or access token.
I've registered my application on https://dev.powerbi.com/apps as a server side web-app, and have selected "Read and Write Datasets" permission on the
This is my code :
$url = "https://login.windows.net/common/oauth2/authorize"."?response_type=code"."&client_id=<my_client_id>"."&resource=https://analysis.windows.net/powerbi/api"."&redirect_uri=<my_redirect_url>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
curl_close($ch);
When I run this code, literally nothing happens. It doesn't redirect to my redirect URI.
I have a review board running on different server . I am using review board as a normal user of it and can comment on the reviews create it but i am not the admin f it. In order to view the review request or comment on it, i need to authenticate with it with my username and password. This is the access given to me. Review Board is an open source tool which is used by many organisations.
Here are the WEB API of it:- (authenticating link) http://www.reviewboard.org/docs/manual/1.5/webapi/2.0/authenticating/#logging-in
Now i am using wamp as server on my local system . I am using php as server side language. I want to use the Review Board API for fetching the data with my credientals. I am using php curl and written this code for authenticating:-
<?php
$ch = curl_init('http://SERVERIP');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic realm="Web API"'));
$output = curl_exec($ch);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic md5encryptedusernamepassword'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
var_dump($info);
curl_close($ch);
var_dump($output);
?>
This code is not authenticating. Please have a look. Any kind of guideline will be helpful. I have spent much time understanding it. Please help.
You should set headers with key:"Authorization",value:" Basic #{Base64.encode64("username:password")}"。
Then you can access the api which is need authentication.