Scripta koja radi update usera preko cURL-a i REST-a u Drupal 7

Pozdrav,

Prije svega da Vas zamolim da izbjegnete komentare kako je ovo pogresan pristup, lud, kako ne bi trebalo ovako to uraditi itd :).

Splet okolnosti i prethodnih dogadjaja je doveo do ovoga.

Naime, ja na stranici imam jednu custom formu preko koje se korisnici registruju na stranicu (baziranu na Drupalu). I to mi radi perfektno. Kad korisnik popuni sve fieldove, submita formu u tom slucaju pozovem php scriptu:

    <?php
/*
 * Server REST - user.register
 */
$domain_name = htmlspecialchars($_POST['domain-name']);
echo $domain_name . PHP_EOL;
$domain = htmlspecialchars($_POST['domain']);
echo $domain . PHP_EOL;
$domain_ext = htmlspecialchars($_POST['domain-ext']);
echo $domain_ext . PHP_EOL;
$domain_choice = htmlspecialchars($_POST['domain-choice']);
echo $domain_choice . PHP_EOL;
$package_type = htmlspecialchars($_POST['package-type']);
echo $package_type . PHP_EOL;
$billing_cycle = htmlspecialchars($_POST['billing-cycle']);
echo $billing_cycle . PHP_EOL;
$username = htmlspecialchars($_POST['username']);
echo $username . PHP_EOL;
$security_pin = htmlspecialchars($_POST['security-pin']);
echo $security_pin . PHP_EOL;
$email = htmlspecialchars($_POST['email']);
echo $email . PHP_EOL;
$first_name = htmlspecialchars($_POST['first-name']);
echo $first_name . PHP_EOL;
$last_name = htmlspecialchars($_POST['last-name']);
echo $last_name . PHP_EOL;
$company = htmlspecialchars($_POST['company']);
echo $company . PHP_EOL;
$telephone = htmlspecialchars($_POST['telephone']);
echo $telephone . PHP_EOL;
$address = htmlspecialchars($_POST['address']);
echo $address . PHP_EOL;
$address2 = htmlspecialchars($_POST['address2']);
echo $address2 . PHP_EOL;
$city = htmlspecialchars($_POST['city']);
echo $city . PHP_EOL;
$state = htmlspecialchars($_POST['state']);
echo $state . PHP_EOL;
$zip = htmlspecialchars($_POST['zip']);
echo $zip . PHP_EOL;
$country = htmlspecialchars($_POST['country']);
echo $country . PHP_EOL;




// User data
$user_data = array();

$user_data['name'] = $username;
$user_data['mail'] = $email;
$user_data['pass'] = $security_pin;
$user_data['pass1'] = $security_pin;
$user_data['field_first_name[und][0][value]'] = $first_name;
$user_data['field_last_name[und][0][value]'] = $last_name;
$user_data['field_telephone[und][0][value]'] = $telephone;
$user_data['field_adress[und][0][value]'] = $address;
$user_data['field_adress2[und][0][value]'] = $address2;
$user_data['field_city[und][0][value]'] = $city;
$user_data['field_state[und][0][value]'] = $state;
$user_data['field_zip_code[und][0][value]'] = $zip;
$user_data['field_country[und][0][value]'] = $country;
$user_data['status'] = 1;
// cURL code
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://will.sx/rests/user/register");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $user_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($http_code == 200) {
    print 'user registered';
}
else {
    print 'user not registered';
}
?>

Ono sto sam ja pokusavao u par navrata je da modificiram ovu scriptu da pomocu nje radim update profila. Naime, imam jos jednu custom stranicu u kojoj dohvatim sve korisnicke informacije, username, e-mail odnosno sve ove fieldove koji su iznad navedeni i koje korisnik popuni pri registraciji. Dakle sto se tice samog Drupala tu nema nikakvih problema i tu mogu uraditi sta god treba, ali imam problema sa modifikacijom ove scripte da pomocu nje mogu umjesto POST raditi PUT.

Znaci bilo kakva pomoc bi mi dobrodosla. Nisam imao dovoljno slobodnog vremena da se duze vremena pozabavim ovim, ali posto se blizi vrijeme da se ovo zavrsi morat cu :).

Unaprijed hvala


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Profit Monkey