CakePHP 2.x首次使用哈希密码登录数据库中无用户
我已经检查过,当我创建用户和密码,然后我尝试登录并成功,但是,如果我在其他设备上安装我的项目并设置我的数据库,我将进入我的系统,如果我没有创建用户,我如何第一次访问 1) 我试图在我的数据库上创建用户和密码,但由于散列方法,它无法识别密码 我如何才能第一次访问,然后像平常一样创建用户 我的登录访问控制器:CakePHP 2.x首次使用哈希密码登录数据库中无用户,php,database,cakephp,model,cakephp-2.3,Php,Database,Cakephp,Model,Cakephp 2.3,我已经检查过,当我创建用户和密码,然后我尝试登录并成功,但是,如果我在其他设备上安装我的项目并设置我的数据库,我将进入我的系统,如果我没有创建用户,我如何第一次访问 1) 我试图在我的数据库上创建用户和密码,但由于散列方法,它无法识别密码 我如何才能第一次访问,然后像平常一样创建用户 我的登录访问控制器: public function login() { //if already logged-in, redirect if($this->Session->
public function login() {
//if already logged-in, redirect
if($this->Session->check('Auth.User')){
$this->redirect(array('action' => 'index'));
}
// if we get the post information, try to authenticate
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->Session->setFlash(__('Bienvenido, '. $this->Auth->user('username')));
$this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Usuario o password invalidos'));
}
}
$this->layout = 'login';
}
class AppController extends Controller {
//public $components = array('DebugKit.Toolbar');
public $components = array(
//'DebugKit.Toolbar',
'Session',
'Auth' => array(
'authorize' => 'Controller',
'actionPath' => 'controllers/',
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authError' => 'You must be logged in to view this page.',
'loginError' => 'Invalid Username or Password entered, please try again.'
),
);
// only allow the login controllers only
public function beforeFilter() {
$this->Auth->allow('login','view','index','logout','getData');
}
public function isAuthorized($user) {
// Here is where we should verify the role and give access based on role
if (isset($user['role']) && $user['role'] === 'adm') {
return true;
}
if (in_array($this->action, array('add','getData','getDataArticulos','addDetFac','descargar','getNit'))) {
if (isset($user['role']) && $user['role'] === 'vend')
return true;
else
return $this->Session->setFlash(__('Acceso denegado.'), 'error');
}
return $this->Session->setFlash(__('Acceso denegado.'), 'error');
}
appcontroller:
public function login() {
//if already logged-in, redirect
if($this->Session->check('Auth.User')){
$this->redirect(array('action' => 'index'));
}
// if we get the post information, try to authenticate
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->Session->setFlash(__('Bienvenido, '. $this->Auth->user('username')));
$this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Usuario o password invalidos'));
}
}
$this->layout = 'login';
}
class AppController extends Controller {
//public $components = array('DebugKit.Toolbar');
public $components = array(
//'DebugKit.Toolbar',
'Session',
'Auth' => array(
'authorize' => 'Controller',
'actionPath' => 'controllers/',
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authError' => 'You must be logged in to view this page.',
'loginError' => 'Invalid Username or Password entered, please try again.'
),
);
// only allow the login controllers only
public function beforeFilter() {
$this->Auth->allow('login','view','index','logout','getData');
}
public function isAuthorized($user) {
// Here is where we should verify the role and give access based on role
if (isset($user['role']) && $user['role'] === 'adm') {
return true;
}
if (in_array($this->action, array('add','getData','getDataArticulos','addDetFac','descargar','getNit'))) {
if (isset($user['role']) && $user['role'] === 'vend')
return true;
else
return $this->Session->setFlash(__('Acceso denegado.'), 'error');
}
return $this->Session->setFlash(__('Acceso denegado.'), 'error');
}
}首先允许添加方法
public function beforeFilter() {
$this->Auth->allow('login','view','index','logout','getData','add');
}
然后创建一个用户,在浏览器URL中写入项目路径/users/add
添加第一个用户后,从Auth allow中删除add。所有这些都只是为了在应用程序的新实例中创建一个新的默认用户吗?