0

I'm using Zend Expresive 3. I have two handles, one is for rendering login page:

public function handle(ServerRequestInterface $request) : ResponseInterface
{
    return new HtmlResponse($this->renderer->render('web::login-page'));
}

Second is for checking login credentials:

public function handle(ServerRequestInterface $request): ResponseInterface
{
    $params = $request->getParsedBody();
    $isPasswordCorrect = $this->authenticationAPI->checkLogin($params);

    if ($isPasswordCorrect) {
        return new RedirectResponse($this->router->generateUri('user-logged'));
    }

    return new RedirectResponse($this->router->generateUri('login-page'));
}

In case when user pass wrong password I redirect him back to login page. I would like to add extra parameters between this two handlers like used username or error message. What is best way to do it? Can I generate request object with attributes and send its to user (How to do it in Zend Expresive 3)? Or use headers or session? - But I'm think it's not goo idea.

Robin71
  • 383
  • 5
  • 26
  • Why not use the same handler ? I have been using the same handler so we can get the errors and pass back the errors. Eg : https://github.com/harikt/web.expressive/blob/d92582c5169aa4d915c6b9c5c2328b9b148630ab/src/Http/Handler/Auth/LoginHandler.php#L75 – Hari K T Jul 18 '18 at 10:35
  • 1
    for error message you can use `Zend\Expressive\Flash\FlashMessageMiddleware` and to store user data you have to use `Zend\Expressive\Session\Ext\PhpSessionPersistence`. https://docs.zendframework.com/zend-expressive-session-ext/intro/ and https://docs.zendframework.com/zend-expressive-flash/middleware/ try it, if you have any problem I will give you and example. – rafaelphp Jul 18 '18 at 20:53

0 Answers0