mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-15 01:35:02 +00:00
Disable account registering from disabled email provider
This commit is contained in:
@@ -22,7 +22,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
public function boot()
|
||||
{
|
||||
try {
|
||||
$app_locale = get_setting('language') ?? 'en';
|
||||
$app_locale = get_settings('language') ?? 'en';
|
||||
} catch (\PDOException $exception) {
|
||||
$app_locale = 'en';
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class GetWidgetsValuesController extends Controller
|
||||
)->format();
|
||||
|
||||
return [
|
||||
'license' => get_setting('license'),
|
||||
'license' => get_settings('license'),
|
||||
'app_version' => config('vuefilemanager.version'),
|
||||
'total_users' => User::count(),
|
||||
'total_used_space' => $storage_usage,
|
||||
|
||||
@@ -13,7 +13,7 @@ class DisabledMimetypes implements Rule
|
||||
*/
|
||||
public function passes($attribute, $value): bool
|
||||
{
|
||||
$mimetype_blacklist = explode(',', get_setting('mimetypes_blacklist'));
|
||||
$mimetype_blacklist = explode(',', get_settings('mimetypes_blacklist'));
|
||||
$file_mimetype = explode('/', $value->getMimeType());
|
||||
|
||||
return ! array_intersect($file_mimetype, $mimetype_blacklist);
|
||||
|
||||
@@ -44,7 +44,7 @@ class UploadFileAction
|
||||
$file_size = File::size($file_path);
|
||||
|
||||
// Size of limit
|
||||
$limit = get_setting('upload_limit');
|
||||
$limit = get_settings('upload_limit');
|
||||
|
||||
// File size handling
|
||||
if ($limit && $file_size > format_bytes($limit)) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class SendContactMessageController extends Controller
|
||||
public function __invoke(
|
||||
SendContactMessageRequest $request
|
||||
): Response {
|
||||
$contactEmail = get_setting('contact_email');
|
||||
$contactEmail = get_settings('contact_email');
|
||||
|
||||
if ($contactEmail) {
|
||||
Mail::to($contactEmail)
|
||||
|
||||
@@ -33,7 +33,7 @@ class UpgradeLanguageTranslationsAction
|
||||
])->collapse(),
|
||||
];
|
||||
|
||||
$license = strtolower(get_setting('license'));
|
||||
$license = strtolower(get_settings('license'));
|
||||
|
||||
// Find new translations in default translations
|
||||
$newbies = $default_translations[$license]
|
||||
|
||||
@@ -89,7 +89,7 @@ class LanguageController extends Controller
|
||||
|
||||
// If user try to delete language used as default,
|
||||
// then set en language as default
|
||||
if ($language->locale === get_setting('language')) {
|
||||
if ($language->locale === get_settings('language')) {
|
||||
Setting::whereName('language')->first()
|
||||
->update(['value' => 'en']);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Language extends Model
|
||||
$language->id = Str::uuid();
|
||||
|
||||
resolve(SeedDefaultLanguageTranslationsAction::class)(
|
||||
license: get_setting('license') ?? 'extended',
|
||||
license: get_settings('license') ?? 'extended',
|
||||
locale: $language->locale
|
||||
);
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ class LanguageCollection extends ResourceCollection
|
||||
public function toArray($request)
|
||||
{
|
||||
$current_language = Language::with('languageTranslations')
|
||||
->whereLocale(get_setting('language') ?? 'en')
|
||||
->whereLocale(get_settings('language') ?? 'en')
|
||||
->first();
|
||||
|
||||
return [
|
||||
|
||||
@@ -18,7 +18,7 @@ class SetStripeController
|
||||
{
|
||||
// TODO: pridat validator do requestu
|
||||
// Check payment setup status
|
||||
if (get_setting('payments_configured')) {
|
||||
if (get_settings('payments_configured')) {
|
||||
abort(401, 'Gone');
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
* @method static where(string $string, mixed $get)
|
||||
* @method static whereIn(string $string, string[] $columns)
|
||||
* @method static create(string[] $array)
|
||||
* @method static find(array|string $setting)
|
||||
* @property string value
|
||||
* @property string name
|
||||
*/
|
||||
|
||||
@@ -48,7 +48,7 @@ class CreateAdminAccountController extends Controller
|
||||
$user
|
||||
->settings()
|
||||
->create([
|
||||
'storage_capacity' => get_setting('storage_default') ?? 5,
|
||||
'storage_capacity' => get_settings('storage_default') ?? 5,
|
||||
'avatar' => store_avatar($request, 'avatar'),
|
||||
'name' => $request->input('name'),
|
||||
]);
|
||||
|
||||
@@ -63,7 +63,7 @@ class StoreAppSettingsController extends Controller
|
||||
[
|
||||
'name' => 'storage_default',
|
||||
'value' => $request->input('defaultStorage') ?? 5,
|
||||
],
|
||||
]
|
||||
])->each(function ($col) {
|
||||
Setting::forceCreate([
|
||||
'name' => $col['name'],
|
||||
|
||||
@@ -45,7 +45,7 @@ class SharedSendViaEmail extends Notification
|
||||
->greeting(__t('shared_link_email_greeting'))
|
||||
->line(__t('shared_link_email_user', ['user' => $this->user->settings->name, 'email' => $this->user->email]))
|
||||
->action(__t('shared_link_email_link'), url('/share', ['token' => $this->token]))
|
||||
->salutation(__t('shared_link_email_salutation', ['app_name' => get_setting('app_title') ?? 'VueFileManager']));
|
||||
->salutation(__t('shared_link_email_salutation', ['app_name' => get_settings('app_title') ?? 'VueFileManager']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,7 +34,7 @@ class StripeWebhookController extends CashierController
|
||||
$user
|
||||
->settings()
|
||||
->update([
|
||||
'storage_capacity' => get_setting('storage_default'),
|
||||
'storage_capacity' => get_settings('storage_default'),
|
||||
]);
|
||||
|
||||
return $this->successMethod();
|
||||
|
||||
@@ -19,7 +19,7 @@ class ProtectSetupWizardRoutes
|
||||
DB::getPdo();
|
||||
|
||||
// Get setup_wizard status
|
||||
if (Schema::hasTable('settings') && get_setting('setup_wizard_success')) {
|
||||
if (Schema::hasTable('settings') && get_settings('setup_wizard_success')) {
|
||||
return response('Gone', 410);
|
||||
}
|
||||
|
||||
|
||||
+22
-8
@@ -33,15 +33,29 @@ if (! function_exists('obfuscate_email')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('get_setting')) {
|
||||
if (! function_exists('get_email_provider')) {
|
||||
/**
|
||||
* Get single value from settings table
|
||||
*
|
||||
* @param $setting
|
||||
* @return |null
|
||||
* Get single or multiple values from settings table
|
||||
*/
|
||||
function get_setting($setting)
|
||||
function get_email_provider(string $email): string
|
||||
{
|
||||
$provider = explode('@', $email);
|
||||
|
||||
return end($provider);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('get_settings')) {
|
||||
/**
|
||||
* Get single or multiple values from settings table
|
||||
*/
|
||||
function get_settings(array|string $setting): Collection|string|null
|
||||
{
|
||||
if (is_array($setting)) {
|
||||
return Setting::whereIn('name', $setting)
|
||||
->pluck('value', 'name');
|
||||
}
|
||||
|
||||
return Setting::find($setting)->value ?? null;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +82,7 @@ if (! function_exists('get_setup_status')) {
|
||||
*/
|
||||
function get_setup_status()
|
||||
{
|
||||
$setup_success = get_setting('setup_wizard_success');
|
||||
$setup_success = get_settings('setup_wizard_success');
|
||||
|
||||
return boolval($setup_success) ? 'setup-done' : 'setup-disclaimer';
|
||||
}
|
||||
@@ -943,7 +957,7 @@ if (! function_exists('__t')) {
|
||||
// Get current locale
|
||||
$locale = cache()->rememberForever('language', function () {
|
||||
try {
|
||||
return get_setting('language') ?? 'en';
|
||||
return get_settings('language') ?? 'en';
|
||||
} catch (QueryException $e) {
|
||||
return 'en';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user