Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Actions/Oauth/Oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public function authenticateOrDie(OauthProvidersType $provider): bool
username: $user->getName() ?? $user->getEmail() ?? $user->getId(),
email: $user->getEmail(),
password: strtr(base64_encode(random_bytes(8)), '+/', '-_'),
may_upload: Configs::getValueAsBool('oauth_grant_new_user_upload_rights'),
may_edit_own_settings: Configs::getValueAsBool('oauth_grant_new_user_modification_rights'));
may_upload: Configs::getValueAsBool('grant_new_user_upload_rights'),
may_edit_own_settings: Configs::getValueAsBool('grant_new_user_modification_rights'));

Auth::login($new_user);

Expand Down
17 changes: 17 additions & 0 deletions app/Contracts/Http/Requests/HasEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

namespace App\Contracts\Http\Requests;

interface HasEmail
{
/**
* Get the email address.
*/
public function email(): string;
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,48 @@
namespace App\Http\Controllers;

use App\Actions\Profile\UpdateLogin;
use App\Actions\User\Create;
use App\Actions\User\TokenDisable;
use App\Actions\User\TokenReset;
use App\Enum\CacheTag;
use App\Events\TaggedRouteCacheUpdated;
use App\Exceptions\ModelDBException;
use App\Exceptions\UnauthenticatedException;
use App\Http\Requests\Profile\ChangeTokenRequest;
use App\Http\Requests\Profile\RegistrationRequest;
use App\Http\Requests\Profile\UpdateProfileRequest;
use App\Http\Resources\Models\UserResource;
use App\Http\Resources\Models\Utils\UserToken;
use App\Models\Configs;
use App\Models\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;

class ProfileController extends Controller
{
/**
* Allow the registration of a new user.
*
* @return JsonResponse
*/
public function register(RegistrationRequest $request, Create $create): JsonResponse
{
$user = $create->do(
username: $request->username(),
password: $request->password(),
email: $request->email(),
may_upload: Configs::getValueAsBool('grant_new_user_upload_rights'),
may_edit_own_settings: Configs::getValueAsBool('grant_new_user_modification_rights'),
quota_kb: 0,
);

// Log in the user directly after registration
Auth::login($user);

return response()->json(['message' => 'User registered successfully'], 201);
}

/**
* Update the Login information of the current user.
*/
Expand Down
58 changes: 58 additions & 0 deletions app/Http/Requests/Profile/RegistrationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

namespace App\Http\Requests\Profile;

use App\Contracts\Http\Requests\HasEmail;
use App\Contracts\Http\Requests\HasPassword;
use App\Contracts\Http\Requests\HasUsername;
use App\Contracts\Http\Requests\RequestAttribute;
use App\Http\Requests\BaseApiRequest;
use App\Http\Requests\Traits\HasEmailTrait;
use App\Http\Requests\Traits\HasPasswordTrait;
use App\Http\Requests\Traits\HasUsernameTrait;
use App\Models\Configs;
use App\Rules\PasswordRule;
use App\Rules\UsernameRule;

class RegistrationRequest extends BaseApiRequest implements HasUsername, HasPassword, HasEmail
{
use HasUsernameTrait;
use HasPasswordTrait;
use HasEmailTrait;

/**
* {@inheritDoc}
*/
public function authorize(): bool
{
return Configs::getValueAsBool('user_registration_enabled');
}

/**
* {@inheritDoc}
*/
public function rules(): array
{
return [
RequestAttribute::USERNAME_ATTRIBUTE => ['required', new UsernameRule()],
RequestAttribute::EMAIL_ATTRIBUTE => ['required', 'string', 'email', 'max:255', 'unique:users'],
RequestAttribute::PASSWORD_ATTRIBUTE => ['required', 'confirmed', new PasswordRule(true)],
];
}

/**
* {@inheritDoc}
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->username = $values[RequestAttribute::USERNAME_ATTRIBUTE];
$this->password = $values[RequestAttribute::PASSWORD_ATTRIBUTE];
$this->email = $values[RequestAttribute::EMAIL_ATTRIBUTE];
}
}
25 changes: 25 additions & 0 deletions app/Http/Requests/Traits/HasEmailTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

namespace App\Http\Requests\Traits;

trait HasEmailTrait
{
/**
* The email address.
*/
protected string $email;

/**
* Get the email address.
*/
public function email(): string
{
return $this->email;
}
}
6 changes: 6 additions & 0 deletions app/Http/Resources/GalleryConfigs/InitConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class InitConfig extends Data
// Live Metrics settings
public bool $is_live_metrics_enabled;

// User registration enabled
public bool $is_registration_enabled;

public function __construct()
{
// Debug mode
Expand Down Expand Up @@ -140,6 +143,9 @@ public function __construct()
$this->title = Configs::getValueAsString('site_title');
$this->dropbox_api_key = Auth::user()?->may_administrate === true ? Configs::getValueAsString('dropbox_key') : 'disabled';

// User registration enabled
$this->is_registration_enabled = Configs::getValueAsBool('user_registration_enabled');

$this->set_supporter_properties();
}

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

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

use App\Models\Extensions\BaseConfigMigration;

return new class() extends BaseConfigMigration {
public const CAT = 'Users Management';

public function getConfigs(): array
{
return [
[
'key' => 'user_registration_enabled',
'value' => '0',
'cat' => self::CAT,
'type_range' => self::BOOL,
'description' => 'Enable user registration.',
'details' => 'If disabled, new users cannot register themselves.',
'is_expert' => false,
'is_secret' => true,
'level' => 0,
'order' => 1,
],
];
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

use Illuminate\Database\Migrations\Migration;

return new class() extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
DB::table('configs')->where('key', 'default_user_quota')->update(['order' => 2]);
DB::table('configs')->where('key', 'oauth_grant_new_user_modification_rights')->update(['key' => 'grant_new_user_modification_rights']);
DB::table('configs')->where('key', 'oauth_grant_new_user_upload_rights')->update(['key' => 'grant_new_user_upload_rights']);
}

/**
* Reverse the migrations.
*/
public function down(): void
{
DB::table('configs')->where('key', 'grant_new_user_modification_rights')->update(['key' => 'oauth_grant_new_user_modification_rights']);
DB::table('configs')->where('key', 'grant_new_user_upload_rights')->update(['key' => 'oauth_grant_new_user_upload_rights']);
}
};
7 changes: 7 additions & 0 deletions lang/ar/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
'api_token' => 'رمز API …',
'missing_fields' => 'حقول مفقودة',
],
'register' => [
'username_exists' => 'اسم المستخدم موجود بالفعل.',
'password_mismatch' => 'كلمات المرور غير متطابقة.',
'signup' => 'إنشاء حساب',
'error' => 'حدث خطأ أثناء تسجيل حسابك.',
'success' => 'تم إنشاء حسابك بنجاح.',
],
'token' => [
'unavailable' => 'لقد قمت بعرض هذا الرمز مسبقًا.',
'no_data' => 'لم يتم إنشاء أي رموز API.',
Expand Down
7 changes: 7 additions & 0 deletions lang/cz/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

'missing_fields' => 'Missing fields',
],
'register' => [
'username_exists' => 'Username already exists.',
'password_mismatch' => 'The passwords do not match.',
'signup' => 'Sign Up',
'error' => 'An error occurred while registering your account.',
'success' => 'Your account has been successfully created.',
],

'token' => [
'unavailable' => 'You have already viewed this token.',
Expand Down
7 changes: 7 additions & 0 deletions lang/de/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
'api_token' => 'API Token …',
'missing_fields' => 'Fehlende Felder',
],
'register' => [
'username_exists' => 'Benutzername existiert bereits.',
'password_mismatch' => 'Die Passwörter stimmen nicht überein.',
'signup' => 'Registrieren',
'error' => 'Bei der Registrierung Ihres Kontos ist ein Fehler aufgetreten.',
'success' => 'Ihr Konto wurde erfolgreich erstellt.',
],
'token' => [
'unavailable' => 'Sie haben diesen Token bereits gesehen.',
'no_data' => 'Es wurde kein API-Token erzeugt.',
Expand Down
8 changes: 8 additions & 0 deletions lang/el/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
'missing_fields' => 'Missing fields',
],

'register' => [
'username_exists' => 'Username already exists.',
'password_mismatch' => 'The passwords do not match.',
'signup' => 'Sign Up',
'error' => 'An error occurred while registering your account.',
'success' => 'Your account has been successfully created.',
],

'token' => [
'unavailable' => 'You have already viewed this token.',
'no_data' => 'No token API have been generated.',
Expand Down
7 changes: 7 additions & 0 deletions lang/en/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
'api_token' => 'API Token …',
'missing_fields' => 'Missing fields',
],
'register' => [
'username_exists' => 'Username already exists.',
'password_mismatch' => 'The passwords do not match.',
'signup' => 'Sign Up',
'error' => 'An error occurred while registering your account.',
'success' => 'Your account has been successfully created.',
],
'token' => [
'unavailable' => 'You have already viewed this token.',
'no_data' => 'No token API have been generated.',
Expand Down
8 changes: 8 additions & 0 deletions lang/es/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
'missing_fields' => 'Missing fields',
],

'register' => [
'username_exists' => 'Username already exists.',
'password_mismatch' => 'The passwords do not match.',
'signup' => 'Sign Up',
'error' => 'An error occurred while registering your account.',
'success' => 'Your account has been successfully created.',
],

'token' => [
'unavailable' => 'You have already viewed this token.',
'no_data' => 'No token API have been generated.',
Expand Down
7 changes: 7 additions & 0 deletions lang/fr/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
'api_token' => 'Jeton API …',
'missing_fields' => 'Champs manquants',
],
'register' => [
'username_exists' => 'Le nom d’utilisateur existe déjà.',
'password_mismatch' => 'Les mots de passe ne correspondent pas.',
'signup' => 'S’inscrire',
'error' => 'Une erreur est survenue lors de l’enregistrement de votre compte.',
'success' => 'Votre compte a été créé avec succès.',
],
'token' => [
'unavailable' => 'Vous avez déjà visualisé ce jeton.',
'no_data' => 'Aucun jeton API n’a été généré.',
Expand Down
8 changes: 8 additions & 0 deletions lang/hu/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@
'credential_registred' => 'Registration successful!',
'5_chars' => 'At least 5 chars.',
],

'register' => [
'username_exists' => 'Username already exists.',
'password_mismatch' => 'The passwords do not match.',
'signup' => 'Sign Up',
'error' => 'An error occurred while registering your account.',
'success' => 'Your account has been successfully created.',
],
];
8 changes: 8 additions & 0 deletions lang/it/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
'missing_fields' => 'Missing fields',
],

'register' => [
'username_exists' => 'Username already exists.',
'password_mismatch' => 'The passwords do not match.',
'signup' => 'Sign Up',
'error' => 'An error occurred while registering your account.',
'success' => 'Your account has been successfully created.',
],

'token' => [
'unavailable' => 'You have already viewed this token.',
'no_data' => 'No token API have been generated.',
Expand Down
8 changes: 8 additions & 0 deletions lang/ja/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
'missing_fields' => 'Missing fields',
],

'register' => [
'username_exists' => 'Username already exists.',
'password_mismatch' => 'The passwords do not match.',
'signup' => 'Sign Up',
'error' => 'An error occurred while registering your account.',
'success' => 'Your account has been successfully created.',
],

'token' => [
'unavailable' => 'You have already viewed this token.',
'no_data' => 'No token API have been generated.',
Expand Down
Loading