morning, my name is Aris,. I’m newbie and interest to developed website system used cakephp framework.
Now I’m try authenticate users in a few step
-
inside AppController
src\Conroller\AppController
<?php
namespace App\Controller;
use Cake\Controller\Controller;
use Cake\Event\Event;
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
//panggil theme
$this->viewBuilder()->theme('Kucing');
$this->loadComponent('RequestHandler', [
'enableBeforeRedirect' => false,
]);
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'Email',
'password' => 'Sandi'
]
]
],
'loginRedirect' => [
'controller' => 'Signs',
'action' => 'Index'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login'
]
]);
//allow display page 'view'
// continues to work
$this->Auth->allow(['view']);
}
}
-
inside controller
src\Controller\UsersController
<?php
namespace App\Controller;
use App\Controller\AppController;
Class UsersControllers extends AppController
{
//fungsi authenticate
public function login()
{
if($this->request->is('post')) {
$user = $this->Auth->identify();
if($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Wrong email and password');
}
}
-
inside template
src\Template\Users\login.ctp
<table id="tableadd" align="center">
<tr>
<td>
<?= $this->Flash->render('Auth') ?>
<?= $this->Form->create() ?>
<div class="form-agileinfo">
<?php
echo $this->Form->control('Email', array('style' => 'width:200px;'));
echo $this->Form->control('Sandi', array('style' => 'width:200px;', 'maxlength' => '8'));
echo $this->Form->submit('LOGIN');
?>
</div>
<div class="clearfix"></div>
<?php
echo $this->Form->end();
?>
</td>
</tr>
</table>
4 inside table Users on MySql
NO Email Nama Sandi
1 zidan1@gmail.com Zidan mubarok
the error messages view while processing authenticate is Wrong email and password
.
I was trying hard and I’m feel so tired to fix the error. I hopefull that someone knowing trouble sam as to me, could be way to fix, thanx