Jump to content

AutoAuth with WP


7seas

Recommended Posts

Hi,

 

Well I tryed to use the autoauth for login customers.

 

I use this code :

<?php

Define WHMCS URL & AutoAuth Key
$whmcsurl = "https://www.domain.com/clients/dologin.php";
$autoauthkey = "abcXYZ123";

$timestamp = time(); # Get current timestamp
$email = "demo@123.com"; # Clients Email Address to Login
$goto = "clientarea.php?action=products";

$hash = sha1($email.$timestamp.$autoauthkey); # Generate Hash

Generate AutoAuth URL & Redirect
$url = $whmcsurl."?email=$email&timestamp=$timestamp&hash=$hash&goto=".urlencode($goto);
header("Location: $url");
exit;

?>

 

I use WordPress to do this and the code is in a file at the root of Wordpress. I call the file with a link .

It could work perfect! but what should I write to replace the email address "demo@123.com"

 

I think it's story of variable but I don't know anymore .

 

Can you please advise me?

 

Thank :)

Link to comment
Share on other sites

I found this code to insert in functions.php file of Worpress:

function callwhmcsapi($action,$params){  
   $whmcsapiurl = "http://yourwhmcsurl.com/includes/api.php";
   $whmcsusername = "adminuser"; // User with API privileges
   $whmcspassword = "adminpassword";
   $params['username'] = $whmcsusername;
   $params['password'] = md5($whmcspassword);
   $params['action'] = $action;
   $params['responsetype'] = "json";
   $query_string = "";
   foreach ($params AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $whmcsapiurl);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_TIMEOUT, 30);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   $jsondata = curl_exec($ch);
   if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
   curl_close($ch);
   $result = json_decode($jsondata,true);
   return $result;
}

function addwhmcsclient($name,$email){  
   $params["firstname"] = $name[0];
   $params["lastname"] = $name[1];
   $params["email"] = $email;
   $params["address1"] = "1301 College Avenue"; // We use the school's address for all users in the system
   $params["city"] = "Fredericksburg";
   $params["state"] = "Virginia";
   $params["postcode"] = "22401";
   $params["country"] = "US";
   $params["phonenumber"] = "5406541000";
   $params["password2"] = "";
   $result = callwhmcsapi("addclient",$params);
   return $result;
}

 

And my code to call :

function wp_get_current_user() {
   global $current_user;



   return $current_user;
}

function checkwhmcsclient() {
   global $clientsuccess;



   return $clientsuccess;
}


$current_user = wp_get_current_user();
$email = $current_user->user_email;
$name = array();
$name[0] = $current_user->user_firstname;
$name[1] = $current_user->user_lastname;
$clientsuccess = checkwhmcsclient($email);






$whmcsurl = "https://mydomain/whmcs/dologin.php";
$autoauthkey = "abcXYZ123";
$timestamp = time(); # Get current timestamp
$email = $clientsuccess['email']; # Clients Email Address to Login
$goto = "clientarea.php?action=products";

$hash = sha1($email.$timestamp.$autoauthkey); # Generate Hash

# Generate AutoAuth URL & Redirect
$url = $whmcsurl."?email=$email&timestamp=$timestamp&hash=$hash&goto=".urlencode($goto); ?>
<script> window.location.href="<?php echo $url; ?>";</script>

<?php get_footer(); ?>  

 

 

But it doesn't make the job. I think I am on the good wat.

 

Can anyone helps me ?

Pleeease :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated