Customize New User WP Notification Email to Admin - notifications

I want to customize the new user wp-notification email sent to admin each time a new user register on my website. I tried but I had only partial success, I like to send the user full name, email, new user number, and total users. I will appreciate any help. Thanks. Below is my code:
` $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
$message = sprintf( __( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
$message .= sprintf( __( 'Name: %s'), $user->first_name ) . "\r\n\r\n";
$message .= sprintf( __( 'E-mail: %s'), $user->user_email ) . "\r\n";
$message .= sprintf( __( 'New user registration on %s.", $user->user_login, $blogname ). "\n\n\r";
$message .= sprintf( __( 'Catapult now has a total of %d. users!", $user_count['count_users']);
return $wp_new_user_notification_email;
#wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] New User Registration' ), $blogname ), $message);
}`

Related

How I can give regex pattern in yii1 when creating any user?

I want to give a pattern for password. The password must be at least 8 characters long and should contain one uppercase letter, one lowercase letter and one number. I am new in yii1. Please help me.
Try this way:
public function rules() {
return array(
array('username, password', 'required'),
array(
'password',
'match', 'pattern' => '/^[\*a-zA-Z0-9]{6,14}$/',
'message' => 'Invalid characters in password.',
),
array('password', 'length', 'min'=>8),
);
}
You can add any type of Pattern in above code.
It seems you can refer some PHP password validation code as follow,
<?php
$pwd = $_POST['pwd'];
if( strlen($pwd) < 8 ) {
$error .= "Password too short!
";
}
if( strlen($pwd) > 20 ) {
$error .= "Password too long!
";
}
if( strlen($pwd) < 8 ) {
$error .= "Password too short!
";
}
if( !preg_match("#[0-9]+#", $pwd) ) {
$error .= "Password must include at least one number!
";
}
if( !preg_match("#[a-z]+#", $pwd) ) {
$error .= "Password must include at least one letter!
";
}
if( !preg_match("#[A-Z]+#", $pwd) ) {
$error .= "Password must include at least one CAPS!
";
}
if( !preg_match("#\W+#", $pwd) ) {
$error .= "Password must include at least one symbol!
";
}
if($error){
echo "Password validation failure(your choise is weak): $error";
} else {
echo "Your password is strong.";
}
For more detail please refer this post
It can be done by Yii custom validation.
Try below this one. i hope the custom validation may useful to your criteria
public function rules()
{
return array(
array('username, password', 'required'),
array('password', 'length', 'min'=>8, 'max'=>16),
// custom validation
array('password', 'checkStrength', 'password'),
);
}
public function checkStrength($attr)
{
$policy1 = preg_match('/[A-Z]/', $this->$attr) ? 1 : 0 ;
$policy2 = preg_match('/[a-z]/', $this->$attr) ? 1 : 0 ;
$policy3 = preg_match('/[0-9]/', $this->$attr) ? 1 : 0 ;
$policy4 = preg_match('/[\'\/~`\!##\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:\<\>,\.\?]/', $this->$attr) ? 1 : 0 ;
if(!$policy1)
$this->addError('password', $this->getAttributeLabel($attr) . ' must contains atleast one upper case character.');
if(!$policy2)
$this->addError('password', $this->getAttributeLabel($attr) . ' must contains atleast one lower case character.');
if(!$policy3)
$this->addError('password', $this->getAttributeLabel($attr) . ' must contains atleast one number.');
if(!$policy4)
$this->addError('password', $this->getAttributeLabel($attr) . ' must contains atleast one special character (/~`!##$%^&*()_-+={}[]|;:<>,.?)');
}

response from google "Oauth 2.0 for login" missing email after authorization

I am attempting implement Oauth 2.0 for login, but the following code isn't producing a consistent response. why? Email is present "sometimes" but I cannot find anything here that would explain the varied response. The goal here is that I could use the email to locate users in my system.
<?php
// http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06
require_once 'sites/all/modules/schoology_core/s_support/JWT.php';
// app info (see google api console for creds)
$google_client_id = '';
$google_secret = '';
$google_redirect_uri = '';
$google_is_auth_response = (isset($_GET['code']) || isset($_GET['error']));
// construct auth url used to redirect user to google login form
$auth_url = 'https://accounts.google.com/o/oauth2/auth?';
$auth_url .= 'client_id=' . $google_client_id . '&';
$auth_url .= 'response_type=code&';
$auth_url .= 'scope=openid%20email&';
$auth_url .= 'redirect_uri=' . $google_redirect_uri . '&';
$auth_url .= 'state=' . uniqid();
$auth_link = '<br>'. $auth_url .'';
// send user to google login form
if(!$google_is_auth_response) {
print $auth_link;
exit;
}
// handle response
if($_GET['error']) {
print 'Oauth2 response error=' . $_GET['error'];
}
else {
// exchange one-time authorization code for access token and ID token
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://accounts.google.com/o/oauth2/token',
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => array(
'code' => $_GET['code'],
'client_id' => $google_client_id,
'client_secret' => $google_secret,
'redirect_uri' => $google_redirect_uri,
'grant_type' => 'authorization_code',
)
));
$response = curl_exec($curl);
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
// decode response and id token to retrieve user's email
$response = json_decode($response);
$jwt_id_token = JWT::decode($response->id_token, NULL, FALSE);
$response_info = print_r(array(
'auth_code' => $_GET['code'],
'response_code' => $responseCode,
'response_decoded' => $response,
'id_token' => $jwt_id_token,
'email_is_not_preset' => $jwt_id_token->email ? 'Y' : 'N'
), TRUE);
print '<pre>' . $response_info . '</pre>';
}

How can I login with facebook via quickblox (PHP)

I read this section http://quickblox.com/developers/Social_Networks_Integration_Manual
But I don't know what to do.If somebody know please help me :)
I was tried with hybridauth I have connection with facebook (my API) hybridauth return to me user information.I create user in quickblox with random password and facebook email and simulate login but this is bad because quickblox in this way don't return to me token and if I want to edit profil I can't....
if( isset( $_GET["login"] ) ){
try{
$hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "facebook" );
$user_profile = $adapter->getUserProfile();
}
catch( Exception $e ){
die( "<b>got an error!</b> " . $e->getMessage() );
}
$token = $adapter->getAccessToken();
//$token['access_token'];
$nonce = rand();
$timestamp = time();
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."&timestamp=".$timestamp;
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body
//$post_body = "application_id=" . APPLICATION_ID . "&auth_key=".AUTH_KEY."&timestamp=".$timestamp."&nonce=".$nonce."&signature=".$signature."&user[email]=" . $user_profile->email . "&provider=facebook&scope=friends_status,read_mailbox,photo_upload&keys[token]=".$token['access_token'];
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature
));
$post_body = "application_id=" . APPLICATION_ID . "&auth_key=" . AUTH_KEY . "&timestamp=" . $timestamp . "&nonce=" . $nonce . "&signature=" . $signature."&user[login]=&user[email]=&user[password]=&provider=facebook&scope=friends_status,read_mailbox,photo_upload&keys[token]=".$token['access_token']."&keys[secret]=";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT . '/' . QB_PATH_SESSION); // Full path is - https://api.quickblox.com/session.json
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
$response = curl_exec($curl);
dump($response);
if ($response) {
return $response . "\n";
} else {
$error = curl_error($curl). '(' .curl_errno($curl). ')';
return $error . "\n";
}
This don't work...this is shity they don't have examples :O
You should add 'provider=facebook' to your post_body and signature_string
After this - QuickBlox will return HTML page with Facebook login dialog, which you should render to your end users

This script make the ftp account but what ever is the php file define?

Please help me out anyone I beg you I have been searching for a month every day trying different things nothing is working.
This below script will make the ftp account but what it define in the line as "add ftp account" as test directory , How can I connect this script to html form so this script can work through that html form to create a ftp account. thank You
<?php
$conn = array ( 'host' => 'Domain Name'
, 'port' => '2083'
, 'user' => 'Not Avi'
, 'pass' => 'Not Avi'
) ;
function cpanel_api ( $conn , $type , $user , $pass , $domain )
{
if ( $conn [ 'port' ] == '2087' || $conn [ 'port' ] == '2083' || $conn [ 'port' ] == '443' )
{
$site = 'https://' . $conn [ 'host' ] . ':' . $conn [ 'port' ] ;
} else {
$site = 'http://' . $conn [ 'host' ] . ':' . $conn [ 'port' ] ;
}
switch ( $type )
{
case 'add_ftp' :
$xmlin = '<cpanelaction><module>Ftp</module><func>addftp</func><apiversion>1</apiversion><args>' . $user . '</args><args>' . $pass . '</args><args>/' . $user . '</args><args>20</args></cpanelaction>' ;
break ;
case 'del_ftp' :
$xmlin = '<cpanelaction><module>Ftp</module><func>delftp</func><apiversion>1</apiversion><args>' . $user . '</args><args>1</args></cpanelaction>' ;
break ;
case 'add_subdomain' :
$xmlin = '<cpanelaction><module>SubDomain</module><func>addsubdomain</func><apiversion>1</apiversion><args>' . $user . '</args><args>' . $domain . '</args><args>0</args><args>0</args><args>/' . $user . '</args></cpanelaction>' ;
break ;
case 'del_subdomain' :
$xmlin = '<cpanelaction><module>SubDomain</module><func>delsubdomain</func><apiversion>2</apiversion><args><domain>' . $user . $domain . '</domain></args></cpanelaction>' ;
break ;
default :
echo 'Type error' ;
}
if ( $type == 'add_ftp' || $type == 'del_ftp' || $type == 'add_subdomain' || $type == 'del_subdomain' )
{
$query = '/xml-api/cpanel?user=' . $conn [ 'user' ] . '&xmlin=' . $xmlin ;
$curl = curl_init ( ) ;
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER , 0 ) ;
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER , 1 ) ;
curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST , 0 ) ;
curl_setopt ( $curl, CURLOPT_USERPWD , $conn [ 'user' ] . ':' . $conn [ 'pass' ] ) ;
curl_setopt ( $curl, CURLOPT_HEADER , 0 ) ;
curl_setopt ( $curl, CURLOPT_URL , $site . $query ) ;
$result = curl_exec ( $curl ) ;
curl_close ( $curl ) ;
}
}
/***** ADD Subdomain and FTP Account *****/
cpanel_api ( $conn , 'add_subdomain' , 'test' , '0123456789' , '.domain.com' ) ;
cpanel_api ( $conn , 'add_ftp' , 'test' , '0123456789' , '.domain.com' ) ;
/***** DEL Subdomain and FTP Account *****/
//cpanel_api ( $conn , 'del_subdomain' , 'test' , '0123456789' , '.domain.com' ) ;
//cpanel_api ( $conn , 'del_ftp' , 'test' , '0123456789' , '.domain.com' ) ;
?>
how to create ftp account in cpanel :
<?
$user = $cpenal_user; // the cpenal root username
$pass = $cpenal_pass; // the cpanel root password
$domain = $site_domain; // the cpanel root domain
$fquota = $drive_space; // ftp disc space mb (for new ftp account)
$skin = 'x3'; // cpnel version
$fuser = //the username for the new FTP account
$fpass = //default password for new ftp account
$uri = '/directiry/'; // the internal URL to the FTP home folder /directiry/
if (mkdir($uri, 0777)) { //make the tmp directory
$fDirectory = '/directiry/';
//$fuser = $feedUser;
$fhomedir = '/public_html/' . $fDirectory;
$url = "https://$user:$pass#$domain:2083/frontend/$skin/ftp/doaddftp.html?";
$url = $url . "login=$fuser&password=$fpass&homedir=$fhomedir&quota=$fquota";
$result = #file_get_contents($url);
if (preg_match('/(Account created successfully)/', $result)) {
//ftp created with new directory
}} ?>

How to generate QuickBlox authentication signature in PHP?

I want to access the APIs in QuickBlox, but before that we need to authenticate our apps and get a session token, and using session token we can access the other APIs.
But the problem is, when I send the authentication request using the required specification given on the QuickBloxwebsite, I am getting the error message:
{"errors":{"base":["Unexpected signature"]}}
The parameters to generate the signature is:
application_id=22&auth_key=wJHd4cQSxpQGWx5&nonce=33432&timestamp=1326966962
And then we convert it in HMAC-SHA format:
hash_hmac( 'sha1', $signatureStr , $authSecret);
Please help me to resolve this problem.
I wrote code snippet on php, it generates signature. It works good
this is my test application's credentials:
$application_id = 92;
$auth_key = "wJHdOcQSxXQGWx5";
$authSecret = "BTFsj7Rtt27DAmT";
$nonce = rand();
echo "<br>nonce: " . $nonce;
$timestamp = time();
echo "<br>timestamp: " . $timestamp ."<br>";
$stringForSignature = "application_id=".$application_id."&auth_key=".$auth_key."&nonce=".$nonce."&timestamp=".$timestamp;
echo $stringForSignature."<br>";
$signature = hash_hmac( 'sha1', $stringForSignature , $authSecret);
echo $signature;
hope this help
Problem solved
There was a problem in my request parameters.
$params = "application_id=$application_id&auth_key=$auth_key&timestamp=$timestamp&nonce=$nonce&signature=$signature&**auth_secret=$authSecret**";
In this parameter I was passing an extra parameter, my auth secret key which should not be there. I removed this parameter and now its working.
Here is full example how to create QuickBlox session:
<?php
// Application credentials
DEFINE('APPLICATION_ID', 92);
DEFINE('AUTH_KEY', "wJHdOcQSxXQGWx5");
DEFINE('AUTH_SECRET', "BTFsj7Rtt27DAmT");
// User credentials
DEFINE('USER_LOGIN', "emma");
DEFINE('USER_PASSWORD', "emma");
// Quickblox endpoints
DEFINE('QB_API_ENDPOINT', "https://api.quickblox.com");
DEFINE('QB_PATH_SESSION', "session.json");
// Generate signature
$nonce = rand();
$timestamp = time(); // time() method must return current timestamp in UTC but seems like hi is return timestamp in current time zone
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."&timestamp=".$timestamp."&user[login]=".USER_LOGIN."&user[password]=".USER_PASSWORD;
echo "stringForSignature: " . $signature_string . "<br><br>";
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature,
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD
));
// $post_body = "application_id=" . APPLICATION_ID . "&auth_key=" . AUTH_KEY . "&timestamp=" . $timestamp . "&nonce=" . $nonce . "&signature=" . $signature . "&user[login]=" . USER_LOGIN . "&user[password]=" . USER_PASSWORD;
echo "postBody: " . $post_body . "<br><br>";
// Configure cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT . '/' . QB_PATH_SESSION); // Full path is - https://api.quickblox.com/session.json
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
// Execute request and read responce
$responce = curl_exec($curl);
// Check errors
if ($responce) {
echo $responce . "\n";
} else {
$error = curl_error($curl). '(' .curl_errno($curl). ')';
echo $error . "\n";
}
// Close connection
curl_close($curl);
?>
You have to use your own application parameters:
application_id
auth_key
and random 'nonce' and current timestamp (not from example, you can get current timestamp on this site http://www.unixtimestamp.com/index.php)
Your code is right, but you must set proper parameters
1) You should send request to correct url.
to
https://api.quickblox.com/auth.json
instead
https://api.quickblox.com/session.json
2) You should fix SSL problem using this.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false)
We use php, and next code works well for us:
<?php
$userLogin = '{YOUR_QB_USER}';
$userPassword = '{YOUR_QB_PASSWORD}';
$body = [
'application_id' => '{YOUR_QB_APPLICATION_ID}',
'auth_key' => '{YOUR_QB_AUTH_KEY}',
'nonce' => time(),
'timestamp' => time(),
'user' => ['login' => $userLogin, 'password' => $userPassword]
];
$built_query = urldecode(http_build_query($body));
$signature = hash_hmac('sha1', $built_query , '{YOUR_QB_APP_SECRET}');
$body['signature'] = $signature;
$post_body = http_build_query($body);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://{YOUR_QB_HOST}/session.json');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$token = json_decode($response, true)['session']['token'];
printf('Your token is: %s %s', $token, PHP_EOL);