File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+
3+ namespace Pdsinterop \Solid \Controller ;
4+
5+ use Psr \Http \Message \ResponseInterface ;
6+ use Psr \Http \Message \ServerRequestInterface ;
7+
8+ class LoginController extends AbstractController
9+ {
10+ final public function __invoke (ServerRequestInterface $ request , array $ args ): ResponseInterface
11+ {
12+ $ postBody = $ request ->getParsedBody ();
13+ $ response = $ this ->getResponse ();
14+ // var_dump($_SESSION);
15+ if (isset ($ _SESSION ["userid " ])) {
16+ $ user = $ _SESSION ["userid " ];
17+ $ response ->getBody ()->write ("<h1>Already logged in as $ user</h1> " );
18+ } else if ($ postBody ["user " ] == $ _ENV ["USER " ] && $ postBody ["password " ] == $ _ENV ["PASSWORD " ]) {
19+ $ user = $ postBody ["user " ];
20+ $ response ->getBody ()->write ("<h1>Welcome $ user</h1> \n" );
21+ $ _SESSION ["userid " ] = $ user ;
22+ print_r ("session started \n" );
23+ var_dump ($ _SESSION );
24+ } else {
25+ // var_dump($postBody);
26+ print_r ("cookie: \n" );
27+ var_dump ($ _COOKIE );
28+ print_r ("session: \n" );
29+ var_dump ($ _SESSION );
30+ $ response ->getBody ()->write ("<h1>No (try posting user=alice&password=alice123)</h1> \n" );
31+ }
32+ return $ response ;
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments