Skip to content

Commit

Permalink
feature: Two factor authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Oct 16, 2023
1 parent f6ba894 commit d00a6ec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 91 deletions.
16 changes: 10 additions & 6 deletions app/Http/Controllers/API/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,27 @@ public function login(Request $request)
}

if (auth('api')->user()->otp_enabled) {
$tfa = new TwoFactorAuth(
"Liman", 6, 30, \RobThree\Auth\Algorithm::Sha1
);
$tfa = app('pragmarx.google2fa');


if (auth('api')->user()->google2fa_secret == null) {
$secret = $tfa->createSecret();
$secret = $tfa->generateSecretKey();
return response()->json([
'message' => 'İki faktörlü doğrulama için Google Authenticator uygulaması ile QR kodunu okutunuz.',
'secret' => $secret,
'image' => $secret,
'image' => $tfa->getQRCodeInline(
"Liman",
auth('api')->user()->email,
$secret,
400
),
], 402);
}

if (! $request->token) {
return response()->json(['message' => 'İki faktörlü doğrulama gerekmektedir.'], 406);
} else {
if (! $tfa->verifyCode(
if (! $tfa->verifyGoogle2FA(
auth('api')->user()->google2fa_secret,
$request->token
)) {
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/API/Settings/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class UserController extends Controller
*/
public function index()
{
return User::all();
return User::orderBy('last_login_at', 'desc')
->get();
}

/**
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"phpseclib/phpseclib": "~3.0",
"pragmarx/google2fa-laravel": "^2.0",
"pusher/pusher-php-server": "^7.0",
"robthree/twofactorauth": "^2.0",
"tymon/jwt-auth": "^2.0"
},
"require-dev": {
Expand Down
85 changes: 2 additions & 83 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d00a6ec

Please sign in to comment.