Quote from: sinbad at May 18, 2008, 11:20 PM
did anyone figured how to make a page ’private’ until client receive it from paypal PDT?
I’m trying to setup a registration page with webloginPE but want that page accessible only when Paypal directs there after successful payment.
is this doable or I’m asking too much?
I had written a plugin that fired "OnPDTSuccess". It created a username and randomly generated password. It used the transaction id as the username.
F*** it, I’ll post it here. This checks to see if "Treasure Chest License" was in the "item_name" string. This prevents the plugin for generating a username and password with access to the download page for *ANY* purchase, only for Treasure Chest License purchases.
Modify this as you see fit.
//<?php
$e = &$modx->Event;
switch ($e->name)
{
case "OnPDTSuccess":
function GeneratePassword($length = 10)
{
$allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$ps_len = strlen($allowable_characters);
mt_srand((double)microtime()*1000000);
$pass = "";
for($i = 0; $i < $length; $i++) {
$pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
}
return $pass;
}
$newPW = GeneratePassword(10);
$params = &$e->params;
$isTC = false;
foreach ($params as $key => $value)
{
$check = strpos($key, ’item_name’);
if ($check === false)
{
// Skip it.
}
else
{
if (strcmp ($value, "Treasure Chest License") == 0)
{
$isTC = true;
}
}
}
if (!$isTC) return;
$txn_id = $params[’txn_id’];
$web_users = $modx->getFullTableName(’web_users’);
$web_user_attributes = $modx->getFullTableName(’web_user_attributes’);
$web_groups = $modx->getFullTableName(’web_groups’);
$checkUID = $modx->db->query("SELECT * FROM ".$web_users." WHERE `username` = ’".$txn_id."’");
$count = $modx->db->getRecordCount($checkUID);
if ($count == 0)
{
$new_user = $modx->db->query("INSERT INTO ".$web_users." (`username`, `password`, `cachepwd`) VALUES (’".$txn_id."’,’".md5($newPW)."’,’".$newPW."’)");
$checkUID = $modx->db->query("SELECT * FROM ".$web_users." WHERE `username` = ’".$txn_id."’");
$user = $modx->db->getRow($checkUID);
$id = $user[’id’];
$attributes = $modx->db->query("INSERT INTO ".$web_user_attributes." (`internalKey`,`fullname`,`email`) VALUES (’".$id."’,’".time()."’,’".$params[’payer_email’]."’)");
$cachepwd = $modx->db->query("UPDATE ".$web_users." SET `cachepwd`=’".$newPW."’ WHERE `username`=’".$txn_id."’");
$webgroup = $modx->db->query("REPLACE INTO ".$web_groups." (`webgroup`, `webuser`) VALUES (’1’, ’".$id."’)");
$email_message = ’<h3>Thank you for your purchase</h3>
<p>Your license is active for the URL ’.$params[’option_selection1_1’].’</p>
<p>To download TreasureChest, log into the <a href="http://treasurechest.scottydelicious.com/download.html">download page</a> with the User ID "<strong>’.$txn_id.’</strong>" and the Password "<strong>’.$newPW.’</strong>"</p>
<p>This User ID and Password will be deleted in 72 hours. Please download TreasureChest before then.</p>
<p>Thanks,</p><p>-sD-
Dr. Scotty Delicious, DFPA.</p> <p><a href="mailto:[email protected]">[email protected]</a> </p>’;
$headers = ’From: [email protected]’ . "\r\n" .
’Reply-To: [email protected]’ . "\r\n" .
’Content-type: text/html’ . "\r\n" .
’X-Mailer: PHP/’ . phpversion();
mail($params[’payer_email’],’Thank you for purchasing a license for TreasureChest’,$email_message,$headers);
}
else
{
$user = $modx->db->getRow($checkUID);
$newPW = $user[’cachepwd’];
}
$msg = ’<p class="user-info">Your User ID is: <span>’.$txn_id.’</span></p><p class="user-info">Your Password is: <span>’.$newPW.’</span></p><p>Please use these credentials when you <a href="[~15~]" onclick="document.tclogin.submit();return false;">Login</a> <span class="tips">(Your User ID and Password will be entered automatically)</span> to Download TreasureChest.</p><p>Your account will be active for the next 72 hours. Be sure to login and download within that time frame.</p><p>If you used a PayPal account to purchase, this information has also been sent to your PayPal email address.</p><form name="tclogin" action="[~15~]" method="post"><input type="hidden" name="username" value="’.$txn_id.’" /><input type="hidden" name="password" value="’.$newPW.’" /></form>’;
$modx->setPlaceholder(’treasure.login’, $msg);
break;
default :
return; // stop here - this is very important.
break;
}
//?>
-sD-
Dr. Scotty Delicious, DFPA.