I'm trying to do a relatively simple task by hooking into the Wordpress registration and adding the user that's being registered to a Salesforce db. When I run the Salesforce db code outside of Wordpress it works flawlessly, but when I test this by registering on my wordpress website, I get an error stating: INVALID_LOGIN: Invalid username, password, security token; or user locked out.
Additionally, I receive this error from Wordpress "Cannot modify header information - headers already sent" which doesn't allow me to view the entire object data that's being sent to Salesforce.
This is my code:
$SF_USERNAME = 'test';
$SF_PASSWORD = 'test';
define( 'CD_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceEnterpriseClient.php');
require_once (CD_PLUGIN_PATH . 'Toolkit/soapclient/SforceHeaderOptions.php');
function add_user_to_SF($user_id) {
$user = get_userdata($user_id);
try {
$mySforceConnection = new SforceEnterpriseClient();
$mySoapClient = $mySforceConnection->createConnection(CD_PLUGIN_PATH . 'Toolkit/soapclient/enterprise.wsdl.xml');
$mylogin = $mySforceConnection->login($SF_USERNAME, $SF_PASSWORD);
print '<pre>';
print_r($mylogin);
print '</pre>';
print '<br/><br/>';
$sObject = new stdclass();
$sObject->FirstName = $user->first_name;
$sObject->LastName = $user->last_name;
$sObject->Email = $user->user_email;
//echo "**** Creating the following:\r\n";
$createResponse = $mySforceConnection->create(array($sObject), 'Contact');
$ids = array();
foreach ($createResponse as $createResult) {
print_r($createResult);
array_push($ids, $createResult->id);
}
} catch (Exception $e) {
$errors->add( 'demo_error', __(print_r($_POST),'mydomain') );
$errors->add( 'demo_error', __($mySforceConnection->getLastRequest(),'mydomain') );
$errors->add( 'demo_error', __($e->faultstring,'mydomain') );
return $errors;
}
}
add_filter( 'registration_errors', 'add_user_to_SF', 10, 3 );
This is a php scope issue.
Adding:
global $SF_USERNAME;
global $SF_PASSWORD;
inside the function fixed the problem.
It looks like you might be missing the security token. It's appended to the end of the password.
This link explains how to generate the token
https://login.salesforce.com/help/doc/en/user_security_token.htm
You need to add your salesforce account security token with password
eg. Password - "testing"
Security Token - "2321njjn32j32"
You need to pass as - "testing2321njjn32j32"
This will work properly.
Related
I am using this plugin for Wordpress:
https://simplejwtlogin.com/docs/hooks/#1-simple_jwt_login_login_hook
When someone logs in on my external app through rest api, I want wordpress to send email by triggering the hook:
functions.php
add_action('simple_jwt_login_login_hook', 'my_test');
function my_test() {
$to = 'you#yourmail.com';
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "me#email.com";
$headers[] = 'Content-type: text/html; charset=utf-8';
$headers[] = "From:" . "me#email.com";
wp_mail($to,$subject,$message,$headers);
}
I also have "Easy SMTP" plugin installed and working properly (wp_mail() should go through my smtp mail)
I don't see any errors in error.log, nor anything in mail.log. Do you think the hook is getting triggered or not?
make sure you enable simple_jwt_login_login_hook
to test the hook, just throw an error in it and see if its captured on error log
like this
add_action('simple_jwt_login_login_hook', function( $user ) {
throw new Exception('I\'m here mortals');
}, 11 , 1);
or via init
add_action('init', function() {
add_action('simple_jwt_login_login_hook', function( $user ) {
throw new Exception('I\'m here mortals');
}, 11, 1);
}, 99)
I created a module and implemented my Telegram bot code in /src/Controller/BotController.php. Now I want to set a webhook and use https://api.telegram.org/bot<token>/setwebhook?url=https://<my-site>/<my-module-path-in-"name.routing.yml">.
The webhook is set, but my code doesn't work and gives me a 500 error.
How can I fix this?
EDIT:
My code:
<?php
namespace Drupal\telegram\Controller;
use Drupal\Core\Controller\ControllerBase;
class TelegramController extends ControllerBase {
public function telegram() {
$update = file_get_contents("php://input");
$update = json_decode($update, TRUE);
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
if (isset($chatId) and isset($message)) {
sendMessage($chatId, $message);
$url = "https://api.telegram.org/bot504387877:AAFHnQe-AdscpSZN42yY-JYem5jwdJc131Q/sendMessage?chat_id=" . $chatId . "&text=" . $message;
}
file_get_contents($url);
$build['#theme'] = 'new';
return $build;
}
}
I think it may cause by unescaped URL, but you need to provide error message to determine.
If you just want to make it done, you can use this Android application. For instance, use getWebhookInfo to obtain error reason.
first sorry for my english
i have a problem of redirect an user when he is connected , i make that on a custom login page (modal)
when i put to submit
i call this code in connexion.php
<?php
define('WP_USE_THEMES', false);
require_once('../../../../wp-load.php');
global $qode_options_theme16;
global $wp_query;
global $wpdb;
// using ldap bind
$ldaprdn = "cn=gazano,dc=cerpweb,dc=local"; // ldap rdn or dn
$ldappass = "test"; // associated password
// connect to ldap server
$ldapconn = ldap_connect("192.168.209.7","389")
or die("Could not connect to LDAP server.");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...";
$mdp = wp_hash_password('cerpcerp');
$wpdb->query("INSERT INTO wp_users (user_login,user_pass, user_nicename, user_email, user_url, user_activation_key, user_status,display_name) VALUES ('hjhjh', '$mdp','e51511','dsfdsf#live.be','15d15','ertre','0','jhjh')");
$user=wp_authenticate('hjhjh', 'cerpcerp');
$ie=wp_redirect(home_url());
my_login_redirect( $ie,' ', '1' );
} else {
echo "LDAP bind failed...";
}
}
?>
my Ldap works correctly , my insert Works as well and my wp_authenticate('hjhjh', 'cerpcerp'); works also,
but the problem is in my_login_redirect( $ie,' ', '1' )
the redirect in home works correctly but without connexion ...
and in my header.php a put this one
global $current_user;
$current_user = wp_get_current_user();
someone can help me
thank in advance
As far as I remember you need to exit() right after wp_redirect.
You have also some filter to do it
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
We are getting spammed from wordpress#domain.com going to jaqqscigs#gmail.com. Ive tried the MU plug (Wordpress and wamp sending "Delivery status notification Failure" to my inbox every 7 minutes) but I got a parse error. Is there any way to just disable mail being sent from wordpress all together? We have changed passwords, disabled password ect..
Thanks!
Travis
Try this (not tested). Depending on your use, you may NOT want to throw the phpmailerException....
class fakemailer {
public function Send() {
throw new phpmailerException( 'Cancelling mail' );
}
}
if ( ! class_exists( 'phpmailerException' ) ) :
class phpmailerException extends Exception {
public function errorMessage() {
$errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
return $errorMsg;
}
}
add_action( 'phpmailer_init', 'wpse_53612_fakemailer' );
function wpse_53612_fakemailer( $phpmailer ) {
if ( ! /* condition */ )
$phpmailer = new fakemailer();
}
https://wordpress.stackexchange.com/questions/53612/how-to-stop-the-wp-mail-function
I am using wp_signon() function to login the user. I am doing this like
$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
i want to send user to home page after login.
But i Am facing following error:
Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\wpmoodle\wp-content\themes\twentyten\header.php:12) in E:\xampp\htdocs\wpmoodle\wp-includes\pluggable.php on line 690.
Thanks in advance.
wp_signon() needs to run before you've sent any of your actual page to the browser.
This is because part of what wp_signon() does is to set your authentication cookies. It does this by outputting a "Set-Cookie: ..." header -- if you look at line 690 of pluggable.php, where your error comes from, you'll see that that line sets a cookie.
So, because wp_signon() outputs headers, you can't already have sent any content -- because headers must always be output before content.
However, the error indicates that you've already sent some output -- on line 12 of header.php, presumably some of the first HTML of the standard WordPress theme.
This basically indicates that you need to move your wp_signon() call to somewhere earlier in the WordPress processing, so it has a chance to output its headers before any page content is sent.
If someone needs it, here is my solution:
function custom_login() {
if (isset($_POST['submit'])) {
$login_data = array();
$login_data['user_login'] = sanitize_user($_POST['username']);
$login_data['user_password'] = esc_attr($_POST['password']);
$user = wp_signon( $login_data, false );
if ( is_wp_error($user) ) {
echo $user->get_error_message();
} else {
wp_clear_auth_cookie();
do_action('wp_login', $user->ID);
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID, true);
$redirect_to = $_SERVER['REQUEST_URI'];
wp_safe_redirect($redirect_to);
exit;
}
}
}
add_action( 'after_setup_theme', 'custom_login' );