Hi i am trying to send mail in cakephp but getting below error message:
stream_socket_client(): SSL operation failed with code 1. OpenSSL
Error messages: error:140770FC:SSL
routines:SSL23_GET_SERVER_HELLO:unknown protocol
stream_socket_client(): Failed to enable crypto
stream_socket_client(): unable to connect to ssl://smtp.gmail.com:25
(Unknown error)
And here is my controller code:-
public function contact(){
//$this->loadModel('Contact');
if($this->request->is(array('put','post'))){
$this->set('data', $this->request->data);
$this->Email->from = $this->data['Page']['email'];
$this->Email->to = 'staff#mailinator.com';
$this->Email->subject = 'Contact';
$this->Email->template = 'contact';
$this->Email->sendAs = 'html';
$this->Email->smtpOptions = array(
'post'=>465,
'host'=>'ssl://smtp.gmail.com',
'username'=>'staff#gmail.com',
'password'=>'123456',
'client'=>'gmail.com');
$this->Email->delivery = 'smtp';
//$this->Email->send();
if($this->Email->send()) {
$this->redirect(array('controller'=>'pages','action'=>'index'));
}
else{
CakeLog::write('debug', $this->Email->smtpError);
}
}
}
there should be 'port'=>465 not 'post'=>465 . please correct
Related
I am using Magento 1.9.2.4 version. I am using SMS module for receiving SMS after placing the order .While selecting option as "Pay Using Credit Card / Debit Card / Net Banking" it is redirecting to payUmoney money page and amount deducting but order placing time error getting like this
Fatal error: Call to a member function getTelephone() on a non-object in model/Observer.php on line 125
My observer code:
public function salesOrderPlace(Varien_Event_Observer $observer)
{
try{
Mage::log("New Order Placed");
$order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastOrderId();
Mage::log("Order ID:".$incrementId);
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
if ($order instanceof Mage_Sales_Model_Order)
{
if($this->getHelper()->issalesOrderPlace())
{
$mobilenumbers = $order->getBillingAddress()->getTelephone();
$message = $this->getHelper()->getOrderMessage($order); //enter Your Message
$customerName = $order->getCustomerName();
//curlApicall : this method will return tru or fale.
$retunValue = $this->getHelper()->curlApiCall($message,$mobilenumbers,$customerName,"New Order");
}
if($this->getHelper()->issalesOrderPlaceForAdmin())
{
$mobilenumbers = $this->getHelper()->getAdminMobileNumber();
$message = $this->getHelper()->getOrderMessageForAdmin($order); //enter Your Message
$customerName = $order->getCustomerName();
//curlApicall : this method will return tru or fale.
$retunValue = $this->getHelper()->curlApiCall($message,$mobilenumbers,$customerName,"New Order");
}
}
//return false;
}catch(Exception $e) {
Mage::log($e->getMessage());
}
}
the problem is here
$order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastOrderId();
Mage::log("Order ID:".$incrementId);
$order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
increment Id is not the same as order id
use this fix:
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
What I'm pretending to do is to include the LDAP for internal users in a Guard Authentication System configured by ddbb.
I already have build my Guard Authentication System and works really nice thanks to https://knpuniversity.com/screencast/symfony-security.
But I need also to try to log in previously via LDAP mode. More precisely, the functionality must be like this:
The user try to log in on the Guard System Authentication configured with a database from MySQL and:
1- Check if exist the user in the table User from MySQL. If exist, we go to step 2. If not exist return false to the authentication with the error message.
2-Check if the user exist in the LDAP mode. If exist go to the step 3. If not exist go to the step 4.
3-Try to log in via LDAP with the username and password. If the authentication is ok, it's logged in. If can't match the password via LDAP, return false to the authentication with the error message.
4-After checking the LDAP option, we will just try to log in via Guard Authentication System. If the authentication it's ok, the user is logged in. If can't match the password via Guard with the MySQL users table, return false to the authentication with the error message.
In the LoginFormAuthenticator file I finally could manage this behavior I want as shows the next code.
<?php
namespace AppBundle\Security;
use ...
use Zend\Ldap\Ldap;
use Zend\Ldap\Exception\LdapException;
class LoginFormAuthenticator extends AbstractFormLoginAuthenticator
{
use TargetPathTrait;
private $em;
private $router;
private $passwordEncoder;
private $csrfTokenManager;
public function __construct(...
}
public function getCredentials(Request $request)
{
...
}
public function getUser($credentials, UserProviderInterface $userProvider)
{
$username = $credentials['username'];
$ldapPassword = $credentials['password'];
$ldaphost = 'ldap.example.com'; // your ldap servers
$baseDn = 'dc=example,dc=es';
$options = [
'host' => $ldaphost,
'username' => $username,
'password' => $ldapPassword,
'bindRequiresDn' => false,
'accountDomainName' => 'example.es',
'baseDn' => $baseDn,
];
$userInterface = $this->em->getRepository('AppBundle:User')
->findOneBy(['email' => $username]);
$ldap = new Ldap($options);
try {
$ldap->bind();
$userInterface->setIsAuthenticationLDAP(true);
} catch (LdapException $zle){
$userInterface->setIsAuthenticationLDAP(false);
}
return $userInterface;
}
public function checkCredentials($credentials, UserInterface $user)
{
$password = $credentials['password'];
if($user->isAuthenticationLDAP()){
$user->setLoginAttempts(0);
$this->em->persist($user);
$this->em->flush();
return true;
} else {
if($this->passwordEncoder->isPasswordValid($user, $password)) {
$user->setLoginAttempts(0);
$this->em->persist($user);
$this->em->flush();
return true;
} else {
if($user->getLoginAttempts() == '0') $user->setFirstLoginAttempt(new \DateTime('now'));
$user->setLoginAttempts($user->getLoginAttempts() + 1);
if($user->getLoginAttempts() >= 5) {
$user->setLockedDateTime(new \DateTime('now'));
$user->setLoginAttempts(0);
}
$this->em->persist($user);
$this->em->flush();
}
}
return false;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
....
}
protected function getLoginUrl()
{
return $this->router->generate('fos_user_security_login');
}
}
I hope anyone can enjoy this answer.
I am trying to download pdf file from server using http client using ntlm Auth Scheme.
but I am getting below error when. The file is getting downloaded when I used wget with username and password as parameters but if I use same username and password it fails with 401 using java code. I am using httpclient 4.2.2
Authentication error: No valid credentials provided (Mechanism level: No valid credentials provided
(Mechanism level: Failed to find any Kerberos tgt))
Below is my code to download pdf using auth.
public ByteArrayOutputStream getFile1(String resourceURL) throws CRMBusinessException {
DefaultHttpClient httpclient = new DefaultHttpClient();
ByteArrayOutputStream tmpOut = null;
try {
ICRMConfigCache cache = CacheUtil.getCRMConfigCache();
String host = cache.getConfigValue(ConfigEnum.DOCUMENT_SOURCE_HOST_NAME.toString());
String user = cache.getConfigValue(ConfigEnum.HTTP_USER_NAME.toString());
String password = cache.getConfigValue(ConfigEnum.HTTP_PASSWORD.toString());
String workstation = cache.getConfigValue(ConfigEnum.CLIENT_HOST_NAME.toString());
// Prerequisites
PreCondition.checkEmptyString(resourceURL, "'resourceURL' cannot be empty or null");
PreCondition.checkEmptyString(host, ConfigEnum.DOCUMENT_SOURCE_HOST_NAME + " property is not set in database");
PreCondition.checkEmptyString(user, ConfigEnum.HTTP_USER_NAME + " property is not set in database");
PreCondition.checkEmptyString(password, ConfigEnum.HTTP_PASSWORD + " property is not set in database");
PreCondition.checkEmptyString(workstation, ConfigEnum.CLIENT_HOST_NAME + " property is not set in database");
// NTLM authentication across all hosts and ports
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_HOST),
new NTCredentials(user, password, workstation, MY_DOMAIN));
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
// Execute the GET request
HttpGet httpget = new HttpGet(resourceURL);
HttpResponse httpresponse = httpclient.execute(httpget);
if (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
tmpOut = new ByteArrayOutputStream();
InputStream in = httpresponse.getEntity().getContent();
byte[] buf = new byte[1024];
int len;
while (true) {
len = in.read(buf);
if (len == -1) {
break;
}
tmpOut.write(buf, 0, len);
}
tmpOut.close();
}
aLog.debug( "IntranetFileDownloaderImpl - getFile - End - " + resourceURL);
return tmpOut;
} catch (Exception e) {
aLog.error("IntranetFileDownloaderImpl - getFile - Error while downloading " + resourceURL + "[" + e.getMessage() + "]", e);
throw new CRMBusinessException(e);
} finally {
httpclient.getConnectionManager().shutdown();
}
}
Has anyone faced this kind of issue before while using httpclient?
What does "Failed to find any Kerberos tgt" mean?
Anybody has any clue on it?
Using kotlin and httpclient version 4.5.8:
val credentialsProvider = BasicCredentialsProvider().apply {
setCredentials(
AuthScope(AuthScope.ANY),
NTCredentials(user, password, null, domain))
}
val requestConfig = RequestConfig.custom().setTargetPreferredAuthSchemes(listOf(AuthSchemes.NTLM)).build()
return HttpClients.custom()
.setDefaultCredentialsProvider(credentialsProvider)
.setDefaultRequestConfig(requestConfig)
.build()
Below code worked for me with http client version 4.2.2.
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpget = new HttpGet("url");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("username", "pwd", "", "domain"));
List<String> authtypes = new ArrayList<String>();
authtypes.add(AuthPolicy.NTLM);
httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,authtypes);
localContext.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
HttpResponse response = httpclient.execute(httpget, localContext);
HttpEntity entity=response.getEntity();
I want to list all the files from my Google drive using my "DriveFiles.php" file where I can display the files and its details.
I am a beginner so a complete code will be helpful.
Thanks.
My code:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
require_once 'google-api-php-client/src/io/Google_HttpRequest.php';
require_once 'google-api-php-client/src/contrib/Google_Oauth2Service.php';
// initialize a client with application credentials and required scopes.
$client = new Google_Client();
$client->setClientId('CLIENT_ID');
$client->setClientSecret('CLIENT_SECRET');
$client->setRedirectUri('REDIRECT_URI');
$client->setScopes(array(
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'));
$client->setUseObjects(true);
if (isset($_GET['code'])) {
session_start();
print_r($_SESSION);
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$client->setAccessToken($_SESSION['token']);
// initialize the drive service with the client.
$services = new Google_DriveService($client);
retrieveAllFiles($services);
}
if(!$client->getAccessToken()){
$authUrl = $client->createAuthUrl();
echo '<a class="login" href="'.$authUrl.'">Login</a>';
}
function retrieveAllFiles($service) {
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$result = array_merge($result, $files->getItems());
$pageToken = $files->getNextPageToken();
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
return $result;
}
?>
When i execute i get an error :
Fatal error: Uncaught exception 'Google_Exception' with message 'Cant add services after having authenticated' in D:\GT_local\Public\google-api-php-client\src\Google_Client.php:115 Stack trace: #0 D:\GT_local\Public\google-api-php-client\src\contrib\Google_DriveService.php(1258): Google_Client->addService('drive', 'v2') #1 D:\GT_local\Public\quickstart.php(55): Google_DriveService->__construct(Object(Google_Client)) #2 {main} thrown in "FILE_LOCATION(C://google-api-php-client\src\Google_Client.php on line 115)"
WHAT SHOULD I DO?
files.list docs contain a working sample with pagination: You can use DrEdit as a boilerplate project.
Ok I am having real difficulty solving this. I'm trying to connect to a mysql database from a zend application and i receive the following error:
Message: No database adapter present
I have checked and double checked the connection credentials and they should be fine. The code should be fine too as it works ok in the development environment. If I deliberately change the password to be incorrect in the development environment, I get exactly the same error, which leads me to believe that maybe this is the case, despite my checking!
Any thoughts would be very welcome. If there's nothing obviously wrong here then maybe I need to look at the server/db/php settings?
Thanks!
Bootstrap code:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initPlaceholders(){
Zend_Session::start();
$this->bootstrap('View');
$view = $this->getResource('View');
$view->doctype('XHTML1_STRICT');
// Set the initial stylesheet:
$view->headLink()->appendStylesheet('/css/global.css');
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Pog_');
Zend_Controller_Action_HelperBroker::addPath(
APPLICATION_PATH . '/controllers/helpers',
'Application_Controller_Action_Helper_');
}
}
Config file:
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.view[] =
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view.helperPath.View_Helper = APPLICATION_PATH "/views/helpers"
database.adapter = pdo_mysql
database.params.host = localhost
database.params.username = user
database.params.password = password
database.params.dbname = test
DB connection helper:
/**
* Constructor: initialize plugin loader
*
* #return void
*/
public function __construct()
{
try{
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'production');
$dbAdapter = Zend_Db::factory($config->database);
$dbAdapter->getConnection();
$this->connection = $dbAdapter;
} catch (Zend_Db_Adapter_Exception $e) {
echo 'perhaps a failed login credential, or perhaps the RDBMS is not running';
} catch (Zend_Exception $e) {
echo 'perhaps factory() failed to load the specified Adapter class';
}
}
public function getDbConnection(){
return $this->connection;
}
}
Index:
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
Define your database as a resource
resources.db.adapter = pdo_mysql
resources.db.params.host = localhost
resources.db.params.username = user
resources.db.params.password = password
resources.db.params.dbname = test
In your main files you then need to do nothing but initiate a query without having to worry about assigning the database fvrom your config - its done in the inside, the DB resource is always chosen as the default adapter for your database transactions