[ 'aakron_design_tool_user' ] ] );
if( !empty($aakronDesignToolUser) ){
$userDataObj = $aakronDesignToolUser[0]->data;
$userId = $userDataObj->ID;
$userInformation = get_userdata($userId);
//echo "
AAkron Personalization PlugIn Registration
add('field', 'Required form field is missing');
}
if ( !is_email( $userEmail ) )
{
$reg_errors->add( 'email_invalid', 'Email id is not valid!' );
}
if ( email_exists( $userEmail ) )
{
$reg_errors->add( 'email', 'Email Already exist!' );
}
if ( 5 > strlen( $password ) ) {
$reg_errors->add( 'password', 'Password length must be greater than 5!' );
}
if ( ! empty( $website ) ) {
if ( ! filter_var( $website, FILTER_VALIDATE_URL ) ) {
$reg_errors->add( 'website', 'Website is not a valid URL' );
}
}
if (is_wp_error( $reg_errors ))
{
foreach ( $reg_errors->get_error_messages() as $error )
{
//$signUpError='
ERROR: '.$error . '
';
$signUpError= $error ;
}
}
if ( 1 > count( $reg_errors->get_error_messages() ) )
{
$userdata = array(
'user_login' => $userName,
'user_email' => $userEmail,
'user_pass' => $password,
'user_url' => $website,
'first_name' => $firstName,
'last_name' => $lastName,
'billing_company' => $companyName,
'role' => 'aakron_design_tool_user'
);
// delete "is_design_tool_active" & "aakron_design_tool_access_toekn" if old user have in db
if ( get_option( 'is_design_tool_active' ) !== false && get_option( 'aakron_design_tool_access_toekn' ) !== false ) {
delete_option( 'is_design_tool_active' );
delete_option( 'aakron_design_tool_access_toekn' );
}
$user = wp_insert_user( $userdata );
add_user_meta( $user, 'billing_company', $companyName);
add_user_meta( $user, 'billing_country', $billingCountry );
add_user_meta( $user, 'billing_address_1', $billingAddressOne );
add_user_meta( $user, 'billing_address_2', $billingAddressTwo );
add_user_meta( $user, 'billing_city', $billingCity );
add_user_meta( $user, 'billing_state', $billingState );
add_user_meta( $user, 'billing_postcode', $billingPoNumber );
add_user_meta( $user, 'billing_phone', $billingPhone );
add_user_meta( $user, 'billing_account', $account);
$body = null;
if( !empty($user) ){
$body = [
'user_id' => '"'.$user.'"',
'firstName' => $firstName,
'lastName' => $lastName,
'company' => $companyName,
'account' => $account,
'email' => $userEmail,
'domain' => $website,
'accessToken' => 'aakron_design_token123',
'connector' => 'wordpress',
];
}
// Register's user in design tool
$body = wp_json_encode( $body );
$argsApi = [
'method' => 'POST',
'body' => $body,
'headers' => [
'Content-Type' => 'application/json',
],
'timeout' => 60,
'redirection' => 10,
'blocking' => true,
'httpversion' => '1.0',
'sslverify' => false,
'data_format' => 'body',
];
$requestApiUrl = $request_uri.'/api/registration/register';
$responseData = wp_remote_post( $requestApiUrl, $argsApi );
$responseUserReg = $responseData['body'];
$userRegArr = json_decode($responseUserReg, TRUE);
if( $userRegArr['status'] == 200 ){
if( !empty($user) ){
$user_name = $firstName.' '.$lastName;
$toEmail = $userEmail;
$subject = 'New User Registration';
$message_body = '';
$message_body .= $this->messageBodyHtml($user_name); // get message body html
// order email function with subject , message boy and headers
$userMail = wp_mail( $toEmail, $subject, $message_body);
echo '
User Registered Successfully. You will receive an Email regarding your approval status.
';
}
}else{
// delete user from WP if not created in design tool admin
wp_delete_user( $user, $reassign = null );
echo '
User not registered please check you have entered right information.
';
}
}
header("Refresh:3");
}
/**
* update existing user
*/
if (isset($_POST['user_update']))
{
global $reg_errors,$firstName, $lastName, $userEmail, $companyName, $website, $password, $companyName, $billingCountry, $billingAddressOne, $billingAddressTwo, $billingCity, $billingState, $billingPoNumber, $billingPhone, $account, $userName ;
$reg_errors = new WP_Error;
$firstName = sanitize_text_field( $_POST['fname'] );
$lastName = sanitize_text_field( $_POST['lname'] );
$userEmail = sanitize_email( $_POST['useremail'] );
$website = esc_url_raw( $_POST['website'] );
$password = md5( $_POST['password'] );
$companyName = sanitize_text_field( $_POST['company'] );
$user_id = sanitize_text_field( $_POST['user_id'] );
$billingCountry = sanitize_text_field( $_POST['billing_country'] );
$billingAddressOne = sanitize_text_field( $_POST['billing_address_1'] );
$billingAddressTwo = sanitize_text_field( $_POST['billing_address_2'] );
$billingCity = sanitize_text_field( $_POST['billing_city'] );
$billingState = sanitize_text_field( $_POST['billing_state'] );
$billingPoNumber = sanitize_text_field( $_POST['billing_postcode'] );
$billingPhone = sanitize_text_field( $_POST['billing_phone'] );
$account = sanitize_text_field( $_POST['account'] );
$userName = preg_replace('/([^@]*).*/', '$1', $userEmail);
if(empty($firstName) || empty($lastName) || empty($companyName) || empty($account) || empty( $billingCountry ) || empty( $billingAddressOne ) || empty( $billingAddressTwo ) || empty( $billingCity ) || empty( $billingState ) || empty( $billingPoNumber ) || empty( $billingPhone ) || empty( $userEmail ) || empty($website) || empty($password))
{
$reg_errors->add('field', 'Required form field is missing');
}
/*if ( !is_email( $userEmail ) )
{
$reg_errors->add( 'email_invalid', 'Email id is not valid!. Please Provide valid Email id.' );
}*/
if ( 5 > strlen( $password ) ) {
$reg_errors->add( 'password', 'Password length must be greater than 5!' );
}
if ( ! empty( $website ) ) {
if ( ! filter_var( $website, FILTER_VALIDATE_URL ) ) {
$reg_errors->add( 'website', 'Website is not a valid URL.' );
}
}
if (is_wp_error( $reg_errors ))
{
foreach ( $reg_errors->get_error_messages() as $error )
{
//$signUpError='
ERROR: '.$error . '
';
$signUpError= $error ;
}
}
if ( 1 > count( $reg_errors->get_error_messages() ) )
{
$user_data = wp_update_user(
array(
'ID' => $user_id,
'user_login' => $userName,
'user_email' => $userEmail,
'user_pass' => $password,
'user_url' => $website,
'first_name' => $firstName,
'last_name' => $lastName,
'role' => 'aakron_design_tool_user'
) );
update_user_meta( $user_id, 'billing_company', $companyName );
update_user_meta( $user_id, 'billing_country', $billingCountry );
update_user_meta( $user_id, 'billing_address_1', $billingAddressOne );
update_user_meta( $user_id, 'billing_address_2', $billingAddressTwo );
update_user_meta( $user_id, 'billing_city', $billingCity );
update_user_meta( $user_id, 'billing_state', $billingState );
update_user_meta( $user_id, 'billing_postcode', $billingPoNumber );
update_user_meta( $user_id, 'billing_phone', $billingPhone );
update_user_meta( $user_id, 'billing_account', $account );
// update user in design tool
$body = [
'user_id' => $user_id,
'firstName' => $firstName,
'lastName' => $lastName,
'company' => $companyName,
'account' => $account,
'email' => $userEmail,
'domain' => $website,
'accessToken' => 'token123',
'connector' => 'wordpress',
];
$body = wp_json_encode( $body );
$argsApi = [
'method' => 'POST',
'body' => $body,
'headers' => [
'Content-Type' => 'application/json',
],
'timeout' => 60,
'redirection' => 5,
'blocking' => true,
'httpversion' => '1.0',
'sslverify' => false,
'data_format' => 'body',
];
$requestApiUrl = $request_uri.'/api/registration/update';
$responseData = wp_remote_post( $requestApiUrl, $argsApi );
$responseUserReg = $responseData['body'];
$userUpdateArr = json_decode($responseUserReg, TRUE);
if( $userUpdateArr['status'] == 200 ){
if( !empty($user_data) ){
echo '
User Information Updated Successfully.
';
}
}else{
echo '
User not updated please check you have entered right information.
';
}
}
header("Refresh:3");
}
if(isset($signUpError)){
?>