Skip to content

Commit

Permalink
feat: Add user session time preference
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Jan 30, 2025
1 parent 4a13dbc commit 9ab6e47
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/Classes/Authentication/KeycloakAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public function authenticate($credentials, $request): JsonResponse
Log::warning('Failed to fetch realm roles from Keycloak. '.$e->getMessage());
}

// Set user preference of session time
auth('api')->factory()->setTTL($user->session_time);

return Authenticator::createNewToken(
auth('api')->login($user),
$request
Expand Down
3 changes: 3 additions & 0 deletions app/Classes/Authentication/LDAPAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ public function authenticate($credentials, $request): JsonResponse
]);
}

// Set user preference of session time
auth('api')->factory()->setTTL($user->session_time);

return Authenticator::createNewToken(
auth('api')->login($user),
$request
Expand Down
3 changes: 3 additions & 0 deletions app/Classes/Authentication/LimanAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function authenticate($credentials, $request): JsonResponse
if (! $user) {
return response()->json(['message' => 'Kullanıcı adı veya şifreniz yanlış.'], 401);
}

// Set user preference of session time
auth('api')->factory()->setTTL($user->session_time);

$credentials["email"] = $user->email;

Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/API/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function setInformation(Request $request)
'name' => $request->name,
'email' => $request->email,
'otp_enabled' => (bool) $request->otp_enabled,
'session_time' => $request->session_time,
]);

if (! (bool) $request->otp_enabled) {
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/API/Settings/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ public function update(Request $request)
Rule::unique('users')->ignore($user->id),
],
'password' => ['nullable', 'string', 'min:8'],
'session_time' => ['required', 'integer', 'min:15', 'max:999999'],
]);

$data = [
'name' => $request->name,
'status' => $request->status,
'session_time' => $request->session_time,
];

if ($user->auth_type !== 'ldap') {
Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class User extends Authenticatable implements JWTSubject
'last_login_ip',
'locale',
'google2fa_secret',
'otp_enabled'
'otp_enabled',
'session_time'
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->bigInteger('session_time')->default(120);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('session_time');
});
}
};

0 comments on commit 9ab6e47

Please sign in to comment.