Zend 1.12登录无法正常工作

时间:2015-10-25 07:33:26

标签: zend-framework

我使用盐和密码两列创建登录系统,但它没有使用我的行为准则

public function indexAction() {
    $form = new Admin_Form_Login();
    $request = $this->getRequest();
    if ($request->isPost()) {
        if ($form->isValid($request->getPost())) {
            if ($this->_process($form->getValues())) {
                // We're authenticated! Redirect to the home page
                $this->_helper->redirector('', 'dashboard');
            }  else {
                echo 'Password is wrong';
            }
        }
    }
    $this->view->form = $form;
}

protected function _process($values) {
    // Get our authentication adapter and check credentials
    $adapter = $this->_getAuthAdapter();
    $adapter->setIdentity($values['email']);
    $adapter->setCredential($values['password']);

    $auth = Zend_Auth::getInstance();
    $result = $auth->authenticate($adapter);
    if ($result->isValid()) {
        $user = $adapter->getResultRowObject();
        $auth->getStorage()->write($user);
        return true;
    }
    return false;
}

protected function _getAuthAdapter() {
    $dbAdapter = Zend_Db_Table::getDefaultAdapter();
    $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);

    $authAdapter->setTableName('eg_user_login')
            ->setIdentityColumn('email')
            ->setCredentialColumn('password')
            ->setCredentialTreatment("MD5(CONCAT(? , salt))");

    return $authAdapter;
}

和注册行动代码是

 $regForm = new Admin_Form_Register();
    $this->view->form = $regForm;
    if ($this->getRequest()->isPost()) {
        if ($regForm->isValid($this->_request->getPost())) {
            $values = $regForm->getValues($this->_request->getPost());
            $pass = $values['pass1'];
            $salt = sha1($pass);
            $password = MD5($salt . $pass);
            $data = array(
                'f_name' => $values['fname'],
                'l_name' => $values['lname'],
                'gender' => $values['gender'],
                'email' => $values['email'],
                'contact' => $values['contact'],
                'password' => $password,
                'salt' => $salt,
                'created_on' => date("d-m-y"),
                'user_role' => $values['userrole'],
                'status' => 0
            );
            $db = new Admin_Model_Userreg();
            $db->insert($data);
        }
    }

它显示任何错误,我认为密码中的加密和解密问题。 登录页面没有重定向到仪表板而没有存储用户实例....请帮帮我。谢谢。

0 个答案:

没有答案