[英]cakephp Auth login not working
我有表用户,他的模型是
class User extends AppModel {
public $useTable = 'user';
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;
}
在我的Userscontroller中
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__("Nom d'user ou mot de passe invalide, réessayer"));
}
}
}
在我看来,login.ctp
<?php
echo $this->Session->flash(); ?>
<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User');?>
<fieldset>
<legend><?php echo __('Merci de rentrer votre nom d\'utilisateur et mot de passe'); ?></legend>
<?php echo $this->Form->input('email');
echo $this->Form->input('password');
?>
<?php echo $this->Form->end(__('Connexion'));?>
<a style="color: #616060;font-size: 15px;font-weight: bold;float: right;" href="<?php
echo $this->Html->url(array('controller'=>'users','action'=>'forgotten')); ?>" >
Mot de passe oublié</a>
</fieldset>
<p style="font-size:22px;"><b>N.B :</b> Veuillez Vous inscrire d’abord au niveau de Myblan application mobile !!</p>
</div>
<?php echo $this->element('sql_dump'); ?>
我的桌子用户
CREATE TABLE `user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`id_mobile` VARCHAR(225) NOT NULL DEFAULT '',
`password` VARCHAR(45) NULL DEFAULT NULL,
`nom_complet` VARCHAR(225) NULL DEFAULT NULL,
`sexe` VARCHAR(225) NULL DEFAULT NULL,
`age` VARCHAR(225) NULL DEFAULT NULL,
`adresse` VARCHAR(225) NULL DEFAULT NULL,
`tel` VARCHAR(45) NULL DEFAULT NULL,
`email` VARCHAR(225) NULL DEFAULT NULL,
`created` DATETIME NULL DEFAULT NULL,
`point` INT(11) NULL DEFAULT '0',
`role_user` VARCHAR(45) NULL DEFAULT NULL,
`code_password` VARCHAR(30) NULL DEFAULT NULL,
`active` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`, `id_mobile`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;
在AppController中
class AppController extends Controller {
public $components = array('Session',
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email'),
'password' => 'password',
'scope' => array('User.active' => 1)
)
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index')
)
);
public function beforeFilter() {
parent::beforeFilter();
}
public function isAuthorized($user) {
return true;
}
}
但是当我想使用我的登录名和密码进行连接时,没有任何显示或错误代码,或者将我重定向到我的帐户
在您的模型中
public function beforeSave($options = array()) {
// hash our password
if (!$this->id) {
$passwordHasher = new SimplePasswordHasher();
$this->data['User']['password'] = $passwordHasher->hash($this->data['User']['password']);
}
return true;
}
在您的应用程序控制器中
public $components = array('Session',
'Auth' => array(
'authorize' => array('Controller'),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email',
'password' => 'password'),
'scope' => array('User.active' => 1)
)
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index')
)
);
public function beforeFilter() {
Security::setHash('sha1');
$this->Auth->allow('login','add', 'index');
}
在您的数据库密码中只有VARCHAR(30)
在您的UserController中是这样的:
public function beforeFilter() {
parent::beforeFilter();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.