Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @var \Fusio\Engine\ConnectorInterface $connector
  4.  * @var \Fusio\Engine\ContextInterface $context
  5.  * @var \Fusio\Engine\RequestInterface $request
  6.  * @var \Fusio\Engine\Response\FactoryInterface $response
  7.  * @var \Fusio\Engine\ProcessorInterface $processor
  8.  * @var \Psr\Log\LoggerInterface $logger
  9.  * @var \Psr\SimpleCache\CacheInterface $cache
  10.  */
  11.  
  12. use PSX\Http\Exception as StatusCode;
  13.  
  14. /** @var \Doctrine\DBAL\Connection $connection */
  15. $connection = $connector->getConnection('Database-Connection');
  16.  
  17. //mendapatkan apa yang disubmit melalui POST
  18. $body = $request->getBody();
  19.  
  20. if (empty($body->username) || empty($body->password)) {
  21.     throw new StatusCode\BadRequestException('Username dan Password diperlukan');
  22. }
  23.  
  24. //query untuk login
  25. $todo = $connection->fetchAssoc('SELECT * FROM users WHERE username = :username AND password = :password', [
  26.     'username' => $body->username,
  27.     'password' => $body->password,
  28. ]);
  29. //jika ok, return successful
  30. if(!empty($todo)) {
  31.   return $response->build(201, [], [
  32.       'success' => true,
  33.       'message' => 'Login successful',
  34.   ]);
  35. } else {
  36.      throw new StatusCode\NotFoundException('Login tidak berjaya');
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement