Php 使用电子邮件而不是用户名进行身份验证
我遵循了CakePHP的基本原理。如果我添加了一个用户,我就不能和他一起登录。具有输入的视图应该是正确的。 Background:用户拥有许多带有联接表的播客Php 使用电子邮件而不是用户名进行身份验证,php,cakephp,authentication,cakephp-2.0,has-and-belongs-to-many,Php,Cakephp,Authentication,Cakephp 2.0,Has And Belongs To Many,我遵循了CakePHP的基本原理。如果我添加了一个用户,我就不能和他一起登录。具有输入的视图应该是正确的。 Background:用户拥有许多带有联接表的播客 Controller/userscocontroller.php public function add() { if ($this->request->is('post')) { $this->User->create(); if ($this->User->
Controller/userscocontroller.php
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->saveAssociated($this->request->data)) { //saveAssociatied() is described below
$this->redirect(array('action' => 'index'));
}
}
$podcasts = $this->User->Podcast->find('list');
$this->set(compact('podcasts'));
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
}
}
}
public $hasAndBelongsToMany = array(
'Podcast' => array(
'className' => 'Podcast',
'joinTable' => 'podcasts_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'podcast_id',
'unique' => false,
)
);
//password encryption
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
Model/User.php
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->saveAssociated($this->request->data)) { //saveAssociatied() is described below
$this->redirect(array('action' => 'index'));
}
}
$podcasts = $this->User->Podcast->find('list');
$this->set(compact('podcasts'));
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
}
}
}
public $hasAndBelongsToMany = array(
'Podcast' => array(
'className' => 'Podcast',
'joinTable' => 'podcasts_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'podcast_id',
'unique' => false,
)
);
//password encryption
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
AppModel.php()
解决方案:我想通过电子邮件进行身份验证,我必须根据 因此,我的AppController.php如下所示:
public $components = array(
'Session',
'Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email')
)
),
'loginRedirect' => array('controller' => 'xxx', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
)
);
那么你到底想要什么?很显然,我想登录。