mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-27 18:40:39 +00:00
Disable account registering from disabled email provider
This commit is contained in:
@@ -17,7 +17,7 @@ class CheckStorageCapacityAction
|
||||
$user_storage_used = user_storage_percentage($user_id, $file_size);
|
||||
|
||||
// Check if user can upload
|
||||
if (get_setting('storage_limitation') && $user_storage_used >= 100) {
|
||||
if (get_settings('storage_limitation') && $user_storage_used >= 100) {
|
||||
// Delete file
|
||||
Storage::disk('local')
|
||||
->delete("chunks/$temp_filename");
|
||||
|
||||
@@ -2,76 +2,63 @@
|
||||
namespace App\Users\Actions;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Users\Requests\RegisterUserRequest;
|
||||
use App\Users\Models\UserSettings;
|
||||
use Domain\Settings\Models\Setting;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class CreateNewUserAction extends Controller
|
||||
{
|
||||
use PasswordValidationRules;
|
||||
|
||||
public function __construct(
|
||||
protected StatefulGuard $guard
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Validate and create a new user.
|
||||
*/
|
||||
public function __invoke(
|
||||
Request $request
|
||||
): Response {
|
||||
$settings = Setting::whereIn('name', [
|
||||
'storage_default', 'registration',
|
||||
])
|
||||
->pluck('value', 'name');
|
||||
RegisterUserRequest $request
|
||||
): Application|ResponseFactory|Response
|
||||
{
|
||||
$settings = get_settings([
|
||||
'storage_default', 'registration', 'user_verification'
|
||||
]);
|
||||
|
||||
// Check if account registration is enabled
|
||||
if (! intval($settings['registration'])) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
Validator::make($request->all(), [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class),
|
||||
],
|
||||
'password' => $this->passwordRules(),
|
||||
])->validate();
|
||||
|
||||
// Create user
|
||||
$user = User::create([
|
||||
'email' => $request->email,
|
||||
'password' => bcrypt($request->password),
|
||||
'password' => bcrypt($request->input('password')),
|
||||
'email' => $request->input('email'),
|
||||
]);
|
||||
|
||||
// Mark as verified if verification is disabled
|
||||
if (! intval($settings['user_verification'])) {
|
||||
$user->markEmailAsVerified();
|
||||
}
|
||||
|
||||
UserSettings::unguard();
|
||||
|
||||
$user
|
||||
->settings()
|
||||
->create([
|
||||
'name' => $request->name,
|
||||
'name' => $request->input('name'),
|
||||
'storage_capacity' => $settings['storage_default'],
|
||||
]);
|
||||
|
||||
if (! get_setting('user_verification')) {
|
||||
$user->markEmailAsVerified();
|
||||
}
|
||||
|
||||
UserSettings::reguard();
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
if (! get_setting('user_verification')) {
|
||||
// Log in if verification is disabled
|
||||
if (! intval($settings['user_verification'])) {
|
||||
$this->guard->login($user);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
* @method static sortable(string[] $array)
|
||||
* @method static forceCreate(array $array)
|
||||
* @method static where(string $string, string $string1, string $toDateString)
|
||||
* @method static create(array $array)
|
||||
*/
|
||||
class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
@@ -91,7 +92,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
public function getStorageAttribute(): array
|
||||
{
|
||||
$is_storage_limit = get_setting('storage_limitation') ?? 1;
|
||||
$is_storage_limit = get_settings('storage_limitation') ?? 1;
|
||||
|
||||
if (! $is_storage_limit) {
|
||||
return [
|
||||
|
||||
@@ -41,7 +41,7 @@ class ResetPassword extends Notification
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$reset_url = url('/create-new-password?token=' . $this->token);
|
||||
$app_name = get_setting('app_title') ?? 'VueFileManager';
|
||||
$app_name = get_settings('app_title') ?? 'VueFileManager';
|
||||
|
||||
return (new MailMessage)
|
||||
->subject(__t('reset_password_subject') . $app_name)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Requests;
|
||||
|
||||
use App\Users\Rules\EmailProvider;
|
||||
use App\Users\Rules\PasswordValidationRules;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RegisterUserRequest extends FormRequest
|
||||
{
|
||||
use PasswordValidationRules;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email', new EmailProvider],
|
||||
'name' => 'required|string|max:255',
|
||||
'password' => $this->passwordRules(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class EmailProvider implements Rule
|
||||
{
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*/
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
$providers = config('disposable-email-providers');
|
||||
$provider = get_email_provider($value);
|
||||
|
||||
return ! in_array($provider, $providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*/
|
||||
public function message(): string
|
||||
{
|
||||
return 'This :attribute email provider is not accepted.';
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\Users\Actions;
|
||||
namespace App\Users\Rules;
|
||||
|
||||
use Laravel\Fortify\Rules\Password;
|
||||
|
||||
@@ -7,10 +7,8 @@ trait PasswordValidationRules
|
||||
{
|
||||
/**
|
||||
* Get the validation rules used to validate passwords.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function passwordRules()
|
||||
protected function passwordRules(): array
|
||||
{
|
||||
return ['required', 'string', new Password, 'confirmed'];
|
||||
}
|
||||
Reference in New Issue
Block a user