zend framework3-登录问题-会话数据

时间:2019-11-12 18:52:15

标签: php zend-framework3

我正在开发一个基本网站,只有一名管理员具有基本登录名。但是输入用户名和密码后无法识别管理员。 而且我不知道问题出在“会话”上还是在向其添加登录状态数据之前,因为$ AdminAuthForm-> getData()似乎为NULL。我真的不知道该如何解决它,如果有人可以帮助我,我将不胜感激。 这是adminauthAction:

public function adminauthAction()
{
    $AdminAuthForm = new LoginForm();
    $request = $this->getRequest();

    if(!$request->isPost()){
        return new ViewModel(['AdminAuthForm' => $AdminAuthForm]);
    }

    $userInfo = new userInfo();
    $AdminAuthForm->setData($request->getPost());
    if(!$AdminAuthForm->isValid()){
        exit('Form is not valid.');
    }


    if($userInfo->Authentic($AdminAuthForm->getData())){

        $config = new StandardConfig();
        $config->setOptions(array(
            'remember_me_seconds' => 1800,
        ));
        $manager = new SessionManager($config);
        $user_session = new Container('Post');
        $user_session->append(['loginStatus' => true]);


        return [$this->redirect()->toRoute('home', [
            'controller' => 'home',
            'action' => 'adminauth',
            'user_session' => $user_session,
            'loginArray' => $AdminAuthForm->getData(),
        ])];
    }
    else{
        return [$this->redirect()->toRoute('home', [
            'controller' => 'home',
            'action' => 'adminauth',
            'loginArray' => $AdminAuthForm->getData(),
            'message' => 'User Info Is Not Correct. Please Try Again.',
        ])];
    }
}

然后在我的index.phtml文件中,编写波纹管并获取第一个和第三个的Null值:

var_dump($this->loginArray);
echo '<br/>';
var_dump($this->user_session);
echo '<br/>';
var_dump($this->user_session->loginStatus);?>

这是两个类的定义:

class LoginForm extends Form
{
    function __construct($name = null, $options = [])
    {
        parent::__construct($name = 'post', $options = []);
        $this->setAttribute('method', 'POST');

        $this->add([
            'name' => 'username',
            'type' => 'email',
            'options' => [
                'label' => 'username',
            ],
        ]);
        $this->add([
            'name' => 'password',
            'type' => 'password',
            'options' => [
                'label' => 'password',
            ],
        ]);
        $this->add([
            'name' => 'submit',
            'type' => 'submit',
            'attributes' => [
                'value' => 'Login',
                'id' => '?',
            ]
        ]);
    }
}


class userInfo
{

    public function Authentic($LoginArray)
    {
        if (trim($LoginArray['username']) == 'SomeOne@gmail.com' && 
trim($LoginArray['password']) == '1234'){
            return true;
        }else{
            return false;
        }
    }
}

0 个答案:

没有答案
相关问题