Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @var \Fusio\Engine\ConnectorInterface $connector
- * @var \Fusio\Engine\ContextInterface $context
- * @var \Fusio\Engine\RequestInterface $request
- * @var \Fusio\Engine\Response\FactoryInterface $response
- * @var \Fusio\Engine\ProcessorInterface $processor
- * @var \Psr\Log\LoggerInterface $logger
- * @var \Psr\SimpleCache\CacheInterface $cache
- */
- use PSX\Http\Exception as StatusCode;
- /** @var \Doctrine\DBAL\Connection $connection */
- $connection = $connector->getConnection('Database-Connection');
- //mendapatkan apa yang disubmit melalui POST
- $body = $request->getBody();
- if (empty($body->username) || empty($body->password)) {
- throw new StatusCode\BadRequestException('Username dan Password diperlukan');
- }
- //query untuk login
- $todo = $connection->fetchAssoc('SELECT * FROM users WHERE username = :username AND password = :password', [
- 'username' => $body->username,
- 'password' => $body->password,
- ]);
- //jika ok, return successful
- if(!empty($todo)) {
- return $response->build(201, [], [
- 'success' => true,
- 'message' => 'Login successful',
- ]);
- } else {
- throw new StatusCode\NotFoundException('Login tidak berjaya');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement