Skip to content

Commit eff1941

Browse files
committed
Squash
1 parent 80b9ad0 commit eff1941

38 files changed

Lines changed: 629 additions & 11 deletions

app/Actions/Oauth/Oauth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ public function authenticateOrDie(OauthProvidersType $provider): bool
8585
username: $user->getName() ?? $user->getEmail() ?? $user->getId(),
8686
email: $user->getEmail(),
8787
password: strtr(base64_encode(random_bytes(8)), '+/', '-_'),
88-
may_upload: Configs::getValueAsBool('oauth_grant_new_user_upload_rights'),
89-
may_edit_own_settings: Configs::getValueAsBool('oauth_grant_new_user_modification_rights'));
88+
may_upload: Configs::getValueAsBool('grant_new_user_upload_rights'),
89+
may_edit_own_settings: Configs::getValueAsBool('grant_new_user_modification_rights'));
9090

9191
Auth::login($new_user);
9292

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
namespace App\Contracts\Http\Requests;
10+
11+
interface HasEmail
12+
{
13+
/**
14+
* Get the email address.
15+
*/
16+
public function email(): string;
17+
}

app/Http/Controllers/ProfileController.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,48 @@
99
namespace App\Http\Controllers;
1010

1111
use App\Actions\Profile\UpdateLogin;
12+
use App\Actions\User\Create;
1213
use App\Actions\User\TokenDisable;
1314
use App\Actions\User\TokenReset;
1415
use App\Enum\CacheTag;
1516
use App\Events\TaggedRouteCacheUpdated;
1617
use App\Exceptions\ModelDBException;
1718
use App\Exceptions\UnauthenticatedException;
1819
use App\Http\Requests\Profile\ChangeTokenRequest;
20+
use App\Http\Requests\Profile\RegistrationRequest;
1921
use App\Http\Requests\Profile\UpdateProfileRequest;
2022
use App\Http\Resources\Models\UserResource;
2123
use App\Http\Resources\Models\Utils\UserToken;
2224
use App\Models\Configs;
2325
use App\Models\User;
26+
use Illuminate\Http\JsonResponse;
2427
use Illuminate\Routing\Controller;
2528
use Illuminate\Support\Facades\Auth;
2629

2730
class ProfileController extends Controller
2831
{
32+
/**
33+
* Allow the registration of a new user.
34+
*
35+
* @return JsonResponse
36+
*/
37+
public function register(RegistrationRequest $request, Create $create): JsonResponse
38+
{
39+
$user = $create->do(
40+
username: $request->username(),
41+
password: $request->password(),
42+
email: $request->email(),
43+
may_upload: Configs::getValueAsBool('grant_new_user_upload_rights'),
44+
may_edit_own_settings: Configs::getValueAsBool('grant_new_user_modification_rights'),
45+
quota_kb: 0,
46+
);
47+
48+
// Log in the user directly after registration
49+
Auth::login($user);
50+
51+
return response()->json(['message' => 'User registered successfully'], 201);
52+
}
53+
2954
/**
3055
* Update the Login information of the current user.
3156
*/
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
namespace App\Http\Requests\Profile;
10+
11+
use App\Contracts\Http\Requests\HasEmail;
12+
use App\Contracts\Http\Requests\HasPassword;
13+
use App\Contracts\Http\Requests\HasUsername;
14+
use App\Contracts\Http\Requests\RequestAttribute;
15+
use App\Http\Requests\BaseApiRequest;
16+
use App\Http\Requests\Traits\HasEmailTrait;
17+
use App\Http\Requests\Traits\HasPasswordTrait;
18+
use App\Http\Requests\Traits\HasUsernameTrait;
19+
use App\Models\Configs;
20+
use App\Rules\PasswordRule;
21+
use App\Rules\UsernameRule;
22+
23+
class RegistrationRequest extends BaseApiRequest implements HasUsername, HasPassword, HasEmail
24+
{
25+
use HasUsernameTrait;
26+
use HasPasswordTrait;
27+
use HasEmailTrait;
28+
29+
/**
30+
* {@inheritDoc}
31+
*/
32+
public function authorize(): bool
33+
{
34+
return Configs::getValueAsBool('user_registration_enabled');
35+
}
36+
37+
/**
38+
* {@inheritDoc}
39+
*/
40+
public function rules(): array
41+
{
42+
return [
43+
RequestAttribute::USERNAME_ATTRIBUTE => ['required', new UsernameRule()],
44+
RequestAttribute::EMAIL_ATTRIBUTE => ['required', 'string', 'email', 'max:255', 'unique:users'],
45+
RequestAttribute::PASSWORD_ATTRIBUTE => ['required', 'confirmed', new PasswordRule(true)],
46+
];
47+
}
48+
49+
/**
50+
* {@inheritDoc}
51+
*/
52+
protected function processValidatedValues(array $values, array $files): void
53+
{
54+
$this->username = $values[RequestAttribute::USERNAME_ATTRIBUTE];
55+
$this->password = $values[RequestAttribute::PASSWORD_ATTRIBUTE];
56+
$this->email = $values[RequestAttribute::EMAIL_ATTRIBUTE];
57+
}
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
namespace App\Http\Requests\Traits;
10+
11+
trait HasEmailTrait
12+
{
13+
/**
14+
* The email address.
15+
*/
16+
protected string $email;
17+
18+
/**
19+
* Get the email address.
20+
*/
21+
public function email(): string
22+
{
23+
return $this->email;
24+
}
25+
}

app/Http/Resources/GalleryConfigs/InitConfig.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class InitConfig extends Data
8888
// Live Metrics settings
8989
public bool $is_live_metrics_enabled;
9090

91+
// User registration enabled
92+
public bool $is_registration_enabled;
93+
9194
public function __construct()
9295
{
9396
// Debug mode
@@ -140,6 +143,9 @@ public function __construct()
140143
$this->title = Configs::getValueAsString('site_title');
141144
$this->dropbox_api_key = Auth::user()?->may_administrate === true ? Configs::getValueAsString('dropbox_key') : 'disabled';
142145

146+
// User registration enabled
147+
$this->is_registration_enabled = Configs::getValueAsBool('user_registration_enabled');
148+
143149
$this->set_supporter_properties();
144150
}
145151

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use App\Models\Extensions\BaseConfigMigration;
10+
11+
return new class() extends BaseConfigMigration {
12+
public const CAT = 'Users Management';
13+
14+
public function getConfigs(): array
15+
{
16+
return [
17+
[
18+
'key' => 'user_registration_enabled',
19+
'value' => '0',
20+
'cat' => self::CAT,
21+
'type_range' => self::BOOL,
22+
'description' => 'Enable user registration.',
23+
'details' => 'If disabled, new users cannot register themselves.',
24+
'is_expert' => false,
25+
'is_secret' => true,
26+
'level' => 0,
27+
'order' => 1,
28+
],
29+
];
30+
}
31+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2025 LycheeOrg.
7+
*/
8+
9+
use Illuminate\Database\Migrations\Migration;
10+
11+
return new class() extends Migration {
12+
/**
13+
* Run the migrations.
14+
*/
15+
public function up(): void
16+
{
17+
DB::table('configs')->where('key', 'default_user_quota')->update(['order' => 2]);
18+
DB::table('configs')->where('key', 'oauth_grant_new_user_modification_rights')->update(['key' => 'grant_new_user_modification_rights']);
19+
DB::table('configs')->where('key', 'oauth_grant_new_user_upload_rights')->update(['key' => 'grant_new_user_upload_rights']);
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*/
25+
public function down(): void
26+
{
27+
DB::table('configs')->where('key', 'grant_new_user_modification_rights')->update(['key' => 'oauth_grant_new_user_modification_rights']);
28+
DB::table('configs')->where('key', 'grant_new_user_upload_rights')->update(['key' => 'oauth_grant_new_user_upload_rights']);
29+
}
30+
};

lang/ar/profile.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
'api_token' => 'رمز API …',
2222
'missing_fields' => 'حقول مفقودة',
2323
],
24+
'register' => [
25+
'username_exists' => 'اسم المستخدم موجود بالفعل.',
26+
'password_mismatch' => 'كلمات المرور غير متطابقة.',
27+
'signup' => 'إنشاء حساب',
28+
'error' => 'حدث خطأ أثناء تسجيل حسابك.',
29+
'success' => 'تم إنشاء حسابك بنجاح.',
30+
],
2431
'token' => [
2532
'unavailable' => 'لقد قمت بعرض هذا الرمز مسبقًا.',
2633
'no_data' => 'لم يتم إنشاء أي رموز API.',

lang/cz/profile.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323

2424
'missing_fields' => 'Missing fields',
2525
],
26+
'register' => [
27+
'username_exists' => 'Username already exists.',
28+
'password_mismatch' => 'The passwords do not match.',
29+
'signup' => 'Sign Up',
30+
'error' => 'An error occurred while registering your account.',
31+
'success' => 'Your account has been successfully created.',
32+
],
2633

2734
'token' => [
2835
'unavailable' => 'You have already viewed this token.',

0 commit comments

Comments
 (0)