CakePHP 2.x 首次使用散列密码登录 DB 中没有用户

CakePHP 2.x first login with hash password no users in DB

我已经检查过,当我创建用户和密码然后我尝试登录并成功时,但是如果例如我在其他设备上安装我的项目并设置我的数据库我进入我的系统我怎么能如果我没有创建用户,第一次访问?

1) 我试图在我的数据库上创建用户和密码,但由于散列方法,它无法识别密码。

如何才能首次访问,然后正常创建用户?

我的登录访问控制器:

    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');
}

然后创建一个用户,在浏览器中写入URLyour_project_path/users/add

添加第一个用户后,从 Auth 允许中删除添加。