Skip to content

Commit b1dc0d4

Browse files
authored
Merge pull request #2 from thetheago/feature/create-jwt-auth-workflow
Feature/create jwt auth workflow
2 parents a7330f2 + 42d4c7c commit b1dc0d4

61 files changed

Lines changed: 4098 additions & 3055 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"command-runner.terminal.name": "runCommand",
3+
"command-runner.terminal.autoClear": true,
4+
"command-runner.terminal.autoFocus": true,
5+
"command-runner.commands": {
6+
"Run PhpStan": "docker compose exec flykit vendor/bin/phpstan analyse -l 2 app",
7+
"Run Phpcs": "docker compose exec flykit composer cs-fix",
8+
"Run Hyperf Unit Tests": "docker compose exec flykit composer test"
9+
}
10+
}

backend/.env.example

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ APP_NAME=skeleton
22
APP_ENV=dev
33

44
DB_DRIVER=mysql
5-
DB_HOST=localhost
5+
DB_HOST=flykit-db
66
DB_PORT=3306
7-
DB_DATABASE=hyperf
8-
DB_USERNAME=root
9-
DB_PASSWORD=
7+
DB_DATABASE=flykit
8+
DB_USERNAME=flykit
9+
DB_PASSWORD=flykit
1010
DB_CHARSET=utf8mb4
1111
DB_COLLATION=utf8mb4_unicode_ci
1212
DB_PREFIX=
1313

1414
REDIS_HOST=localhost
1515
REDIS_AUTH=(null)
1616
REDIS_PORT=6379
17-
REDIS_DB=0
17+
REDIS_DB=0
18+
19+
JWT_SECRET_KEY=flykitjwtsecretkeymuitodificil

backend/.php-cs-fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
'@PhpCsFixer' => true,
2828
'header_comment' => [
2929
'comment_type' => 'PHPDoc',
30-
'header' => $header,
30+
'header' => '',
3131
'separate' => 'none',
3232
'location' => 'after_declare_strict',
3333
],

backend/Dockerfile

Lines changed: 0 additions & 54 deletions
This file was deleted.

backend/app/Constants/ErrorCode.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
<?php
22

33
declare(strict_types=1);
4-
/**
5-
* This file is part of Hyperf.
6-
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact group@hyperf.io
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11-
*/
124

135
namespace App\Constants;
146

backend/app/Controller/AbstractController.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
<?php
22

33
declare(strict_types=1);
4-
/**
5-
* This file is part of Hyperf.
6-
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact group@hyperf.io
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11-
*/
124

135
namespace App\Controller;
146

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Controller;
6+
7+
use App\Exception\WrongAccessAttemptException;
8+
use App\Factory\LoginInputFactory;
9+
use App\Interfaces\UserRepositoryInterface;
10+
use App\Request\LoginRequest;
11+
use App\Usecase\LoginUseCase;
12+
use Hyperf\Di\Annotation\Inject;
13+
use Hyperf\HttpServer\Response;
14+
use Symfony\Component\HttpFoundation\Response as HttpResponse;
15+
16+
class AuthController
17+
{
18+
#[Inject]
19+
private UserRepositoryInterface $userRepository;
20+
21+
#[Inject]
22+
private LoginInputFactory $loginInputFactory;
23+
24+
public function login(LoginRequest $request)
25+
{
26+
try {
27+
$input = $this->loginInputFactory->createFromRequest($request);
28+
29+
$loginUsecase = new LoginUseCase($this->userRepository);
30+
$output = $loginUsecase->execute($input);
31+
32+
return (new Response())->json([
33+
'token' => $output->getToken(),
34+
])->withStatus(HttpResponse::HTTP_OK);
35+
} catch (WrongAccessAttemptException $e) {
36+
return (new Response())->json([
37+
'message' => $e->getMessage(),
38+
])->withStatus(HttpResponse::HTTP_UNAUTHORIZED);
39+
}
40+
}
41+
}

backend/app/Controller/IndexController.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
<?php
22

33
declare(strict_types=1);
4-
/**
5-
* This file is part of Hyperf.
6-
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact group@hyperf.io
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11-
*/
124

135
namespace App\Controller;
146

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Dto\Login;
6+
7+
class LoginInput
8+
{
9+
public function __construct(
10+
private string $email,
11+
private string $password,
12+
) {
13+
}
14+
15+
public function getEmail(): string
16+
{
17+
return $this->email;
18+
}
19+
20+
public function getPassword(): string
21+
{
22+
return $this->password;
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Dto\Login;
6+
7+
class LoginOutput
8+
{
9+
public function __construct(
10+
private string $token
11+
) {
12+
}
13+
14+
public function getToken(): string
15+
{
16+
return $this->token;
17+
}
18+
}

0 commit comments

Comments
 (0)