Auth login not working cakephp 2.5.7 in Server - mysql

Hi, Everyone cakephp login works in my localhost, but it doesn't works in
web server.
My localhost server php version 5.5 and mysql server 5.6.
My web server version 5.2.17 and mysql server 5.1.61-rel13.2-log
Below is my controller code.
UsersController.php
public function login(){
$this->layout='userlogin';
if ($this->request->is('post'))
{
if ($this->Auth->login())
{
return $this->redirect($this->Auth->redirect());
}else{
$this->request->data=array();
return $this->Session->setFlash('Invalid username or password, try again','default',array('class'=>'alert alert-danger'),'logerr');
}
}
}
AppController.php
public $components = array(
'RequestHandler','Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'Users', 'action' => 'UserDashboard'),
'logoutRedirect' => array('controller' => 'Users', 'action' => 'login'),
'authError' => 'Did you really think you are allowed to see that?',
'authorize' => array('Controller'),
)
);
Thanks in Advance

Related

CakePHP 3 - View class "CsvView.csv" is missing issue

I'm trying to include a csv exporter in my application, And i used https://github.com/FriendsOfCake/cakephp-csvview.
It works fine on my local machine but for some reason it doesn't work on my server. It throws me View class "CsvView.csv" is missing. error. Is there a way to fix this issue?
Here's my controller for reference
public function export() {
$this->response->download('export.csv');
// $opts1['order'] = array('Blogs.created' => 'desc');
// $blogsinfos = $this->Blogs->find('all',$opts1);
$opts1['order'] = array('Incomes.title' => 'desc');
$data = $this->Incomes->find('all',$opts1)->toArray();
$_serialize = 'data';
// Give the needed the colums to extract
$_extract = ['id', 'title' ,'description' , 'created' , 'amount'];
//headings for the CSV
$_header = ['ID', 'Title' ,'Description' , 'Created' , 'Amount'];
$this->set(compact('data', '_serialize', '_header', '_extract'));
$this->viewBuilder()->className('CsvView.csv');
return;
}
Code to create the downloadable link.
<?= $this->Html->link('Monthly Report', [
'controller' => 'incomes',
'action' => 'export',
'_ext' => 'csv'
],
['class' => 'btn btn-success'])
?>
I'm using CakePHP 3.4.7.

Could not send email: unknown Cake\Network\Exception\SocketException in cakephp3

Okay I have been to almost all threads but I couldn't find the answer what I want.
Controller: RegistersController
namespace App\Controller;
use App\Controller\AppController;
use Cake\Auth\DefaultPasswordHasher;
use Cake\Event\Event;
use Cake\Mailer\Email;
use Cake\Routing\Router;
class RegistersController extends AppController
{
public function add()
{
$this->loadModel('Tbusers');
$tbusers = $this->Tbusers->newEntity();
if ($this->request->is('post'))
{
$tbusers = $this->Tbusers->patchEntity($tbusers, $this->request->data);
if ($this->Tbusers->save($tbusers)) {
$this->Flash->success(__('Yayie! You have been registered.'));
$baseurl = Router::url('/', true);
$email = base64_encode($this->request->data['email']);
$first_name = $this->request->data['fname'];
$last_name = $this->request->data['lname'];
$username = $first_name.' '.$last_name;
//$confirmation_link = $baseurl.'users/confirm/'.$email;
$email = new Email();
$email->template('email')
->subject('Student Portal - Signup')
->emailFormat('html')
->to($this->request->data['email'])
//->viewVars(['confirmation_link' => $confirmation_link,'username'=>$username])
->viewVars(['username'=>$username])
->from('dotnetdev555#gmail.com')
->send();
if ($email->send())
{
// Success
echo "mail sent";
}
else
{
echo "Mail not sent";
// Failure
}
return $this->redirect(['action' => 'add']);
}
}
Inside Template->Email->html I have file called
email.ctp
Hello <?php echo $username; ?>,<br/>
Thanks,<br/>
Jaymin Sejpal Founder at Student Portal
app.php
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'smtp.elasticemail.com',
'port' => 2525,
'timeout' => 30,
'username' => 'dotnetdev555#gmail.com',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],
I don't know what I am missing to it. I am refferring this
http://book.cakephp.org/3.0/en/core-libraries/email.html for now.
The email host that you are using might be using smtp protocol , so in your app.php . Try editing you className parameter to 'Smtp'
'EmailTransport' => [
'default' => [
'className' => 'Smtp',
// The following keys are used in SMTP transports
'host' => 'smtp.elasticemail.com',
'port' => 2525,
'timeout' => 30,
'username' => 'dotnetdev555#gmail.com',
'password' => 'secret',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
],

Cakephp goes to wrong path

I am working on Cakephp. In default.ctp i give a link like
<li><?= $this->Html->link('List',['controller' => 'Products', 'action' => 'index']) ?></li>
I also have a ProductsController.php .
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
class ProductsController extends AppController {
public function initialize(){
parent::initialize();
$this->loadcomponent('Flash');
}
public function index(){
$products = $this->Products->find('all');
$this->set(compact('products'));
}
But when i click on that link it give the error like
Error: WebrootController could not be found.
Error: Create the class WebrootController below in file: src/Controller/WebrootController.php
When click on toggle arguments it shows
object(Cake\Network\Request) {
params => [
'plugin' => null,
'controller' => 'Webroot',
'action' => 'products',
'_ext' => null,
'pass' => [],
'_matchedRoute' => '/:controller/:action/*',
'isAjax' => false
]
data => []
query => []
cookies => [
'__atuvc' => '1|21'
]
url => 'webroot/products/'
base => '/cakephp'
webroot => '/cakephp/'
here => '/cakephp/webroot/products/'
trustProxy => false
Please help me to solve this error.
Check if you have two .htaccess files present in your application root folder and in the webroot folder.
And make sure that an .htaccess override is allowed and that AllowOverride is set to All for the correct DocumentRoot
http://book.cakephp.org/3.0/en/installation.html#url-rewriting

Authentication Component

I am using CakePHP for the first time. So, please, be patient with me:
I have a table called admin_users, when i try to add the Auth component in my AppController.php.
While executing, I always receive an error telling me that: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_test.users' doesn't exist.
My table is called admin_users, so the error could be because the table should be always called "users" to work properly?
Here is my implementation in AppController.php:
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth',[
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'AdminUsers',
'action' => 'login'
]
]);
$this->Auth->allow(['display']);
}
and in AdminUsersController, the login function:
public function login()
{
if ($this->request->is('post')){
$adminUser = $this->Auth->identify();
if ($adminUser){
$this->Auth->setAdminUser($adminUser);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Your username or password is incorrect.');
}
}
Thank you.
Try this
In AppController.php:
function beforeFilter() {
$this->Auth->userModel = 'admin_users';
}

Symfony2 doctrine connect to database via SSL

Trying to connect to my MySQL database via SSL, I have successfully established the connection from my webserver via ssh with the following command line:
mysql -h my.host.here --port=5454 -v --ssl-ca=/etc/apache2/ssl/mysql/ca-cert.pem --ssl-cert=/etc/apache2/ssl/mysql/client-cert.pem --ssl-key=/etc/apache2/ssl/mysql/client-key.pem -u user -p
However, trying to set up the same connection in symfony2 and doctrine, all I keep getting is an "SSL error"
$params = array(
'driver' => 'pdo_mysql',
'user' => 'user',
'password' => 'pass',
'host' => 'my.host.here',
'dbname' => 'media',
'port' => '5454',
);
if($this->container->hasParameter('media_ca') && $this->container->hasParameter('media_cert') && $this->container->hasParameter('media_key')) {
$params['driverOptions'] = array(
PDO::MYSQL_ATTR_SSL_CA => $this->container->hasParameter('media_ca'),
PDO::MYSQL_ATTR_SSL_CERT => $this->container->hasParameter('media_cert'),
PDO::MYSQL_ATTR_SSL_KEY => $this->container->hasParameter('media_key'),
);
}
/* Using this instead with only the ca_cert gives me the same error
if($this->container->hasParameter('media_ca')) {
$params['driverOptions'] = array(
PDO::MYSQL_ATTR_SSL_CA => $this->container->hasParameter('media_ca'),
);
}
*/
$connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
$conn = $connectionFactory->createConnection($params);
return $conn;
In my log:
[2013-10-01 15:23:30] request.CRITICAL: Uncaught PHP Exception PDOException: "SQLSTATE[HY000] [2026] SSL connection error" at /var/www/mysite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 36 {"exception":"[object] (PDOException: SQLSTATE[HY000] [2026] SSL connection error at /var/www/mysite/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:36)"} []
I have doublechecked that the webserver user (www-data) has access to the certificate files, and that the path to those cert files are correct (defined in the symfony2 parameters).
I can not think of anything else that is different between my command line connection and the one I have specified with doctrine/symfony2.
You are wrong with retrieving parameters. You need getParameter($param) method instead of hasParameter($param). These lines are correct.
PDO::MYSQL_ATTR_SSL_CA => $this->container->getParameter('media_ca'),
PDO::MYSQL_ATTR_SSL_CERT => $this->container->getParameter('media_cert'),
PDO::MYSQL_ATTR_SSL_KEY => $this->container->getParameter('media_key'),
Just to record the full example how I ended up solving the issue:
//Create a connection to another public database.
private function videoDatabase() {
//Create a connection to pub-DB.
$params = array(
'driver' => $this->container->getParameter('media_database_driver'),
'user' => $this->container->getParameter('media_database_user'),
'password' => $this->container->getParameter('media_database_password'),
'host' => $this->container->getParameter('media_database_host'),
'dbname' => $this->container->getParameter('media_database_name'),
'port' => $this->container->getParameter('media_database_port')
);
if($this->container->hasParameter('media_ca') && $this->container->hasParameter('media_cert') && $this->container->hasParameter('media_key')) {
$params['driverOptions'] = array(
PDO::MYSQL_ATTR_SSL_CA => $this->container->getParameter('media_ca'),
PDO::MYSQL_ATTR_SSL_CERT => $this->container->getParameter('media_cert'),
PDO::MYSQL_ATTR_SSL_KEY => $this->container->getParameter('media_key'),
);
}
$connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
$conn = $connectionFactory->createConnection($params);
return $conn;
}