Skip to content

Commit

Permalink
feature: Added login branding support on tweaks and authentication page
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed May 20, 2024
1 parent f08333d commit 9968ef9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
14 changes: 13 additions & 1 deletion app/Http/Controllers/API/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Classes\Authentication\LDAPAuthenticator;
use App\Classes\Authentication\LimanAuthenticator;
use App\Http\Controllers\Controller;
use App\Models\SystemSettings;
use App\User;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Http\JsonResponse;
Expand Down Expand Up @@ -34,7 +35,8 @@ public function __construct()
'forceChangePassword',
'setupTwoFactorAuthentication',
'sendPasswordResetLink',
'resetPassword'
'resetPassword',
'loginBranding'
]
]
);
Expand All @@ -58,6 +60,16 @@ public function activeAuthTypes()
return $types;
}

/**
* Return login screen branding
*/
public function loginBranding()
{
return response()->json([
'image' => SystemSettings::where('key', 'LOGIN_IMAGE')->first()?->data ?? '',
]);
}

/**
* Get a JWT via given credentials.
*
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/API/Settings/CertificateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public function index()
// Certificate is not valid
// Remove certificate from system
$certificate->removeFromSystem();
}

$certificate->valid_to =
$certinfo['validTo_time_t'] * 1000;
} else {
$certificate->valid_to =
$certinfo['validTo_time_t'] * 1000;

$certificate->valid_from =
$certinfo['validFrom_time_t'];
$certificate->valid_from =
$certinfo['validFrom_time_t'];
}
});

return $certificates;
Expand Down
14 changes: 14 additions & 0 deletions app/Http/Controllers/API/Settings/TweaksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use App\Models\AuditLog;
use App\Models\SystemSettings;
use App\System\Command;
use Illuminate\Http\Request;

Expand All @@ -25,6 +26,7 @@ public function getConfiguration()
'EXTENSION_DEVELOPER_MODE' => (bool) env('EXTENSION_DEVELOPER_MODE', 'false'),
'NEW_LOG_LEVEL' => env('NEW_LOG_LEVEL'),
'LDAP_IGNORE_CERT' => (bool) env('LDAP_IGNORE_CERT', 'false'),
'LOGIN_IMAGE' => SystemSettings::where('key', 'LOGIN_IMAGE')->first()?->data ?? '',
]);
}

Expand Down Expand Up @@ -58,6 +60,18 @@ public function saveConfiguration(Request $request)
'LDAP_IGNORE_CERT' => (bool) $request->LDAP_IGNORE_CERT,
]);

if ($request->has('LOGIN_IMAGE') && $request->LOGIN_IMAGE != '')
// Control if LOGIN_IMAGE is bigger than 1mb
if (strlen($request->LOGIN_IMAGE) > 1048576) {
return response()->json([
'LOGIN_IMAGE' => 'Giriş arka planı resmi 1MB\'dan büyük olamaz.',
], 422);
}
SystemSettings::updateOrCreate(
['key' => 'LOGIN_IMAGE'],
['data' => $request->get('LOGIN_IMAGE')]
);

AuditLog::write(
'tweak',
'edit',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('system_settings', function (Blueprint $table) {
$table->longText('data')->change();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('system_settings', function (Blueprint $table) {

});
}
};
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'prefix' => 'auth'
], function () {
Route::get('/types', [AuthController::class, 'activeAuthTypes']);
Route::get('/branding', [AuthController::class, 'loginBranding']);
Route::post('/login', [AuthController::class, 'login'])
->middleware('throttle:login');
Route::post('/setup_mfa', [AuthController::class, 'setupTwoFactorAuthentication']);
Expand Down

0 comments on commit 9968ef9

Please sign in to comment.