一个表单接受电子邮件和密码。
电子邮件地址存储为用户ID,密码存储在密码表中。 地址是电子邮件表中存储实际电子邮件地址的属性。 密码存储在pw中的位置。
认证组件接收地址作为参数。
我认为,我们可以比较电子邮件地址,或者直接让表单查看相关类的“地址”属性。那么如何将身份验证指向另一个表中的属性呢?
谢谢。
<?= $this->Form->create() ?>
<?= $this->Form->control('email') ?>
<?= $this->Form->control('password') ?>
<?= $this->Form->button('Login') ?>
<?= $this->Form->end() ?>
电子邮件地址存储为用户ID,密码存储在密码表中。 地址是电子邮件表中存储实际电子邮件地址的属性。 密码存储在pw中的位置。
认证组件接收地址作为参数。
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
//here we define what is compared to be authenticated
'username' => 'address',
'password' => 'password'
]
]...
登录功能与普通相同:
public function login()
{
if ($this->request->is('post')) {
//PUT IN STUFF HERE
$user = $this->Auth->identify();
if ($user) {
$user->last_login = Time::now();//dont put this above uif statement, will automatically create a default object
$this->Auth->setUser($user);
$this->Flash->success('You have been successfully logged in.');
$this->log("Login success", 'debug');
//redirect after login
return $this->redirect($this->Auth->redirectUrl('/users/index'));
}
$this->Flash->error('Your username or password is incorrect.');
$this->log("Login FAILURE", 'debug');
}
}`
我认为,我们可以比较电子邮件地址,或者直接让表单查看相关类的“地址”属性。那么如何将身份验证指向另一个表中的属性呢?
谢谢。