init commit

This commit is contained in:
David Melendez
2026-01-14 22:38:44 +01:00
parent 4e0c415f0b
commit e25d53d054
124 changed files with 21653 additions and 1 deletions

View File

@@ -0,0 +1,110 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Password;
/**
* Login Form Request
*
* Validates user login credentials with enterprise security standards.
* Implements rate limiting and security validations.
*
* @author David Valera Melendez <david@valera-melendez.de>
* @since February 2025
*/
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'email' => [
'required',
'string',
'email:rfc,dns',
'max:255',
'exists:users,email'
],
'password' => [
'required',
'string',
'min:6',
'max:255'
],
'remember' => [
'boolean'
]
];
}
/**
* Get custom error messages for validation rules.
*/
public function messages(): array
{
return [
'email.required' => 'Email address is required.',
'email.email' => 'Please enter a valid email address.',
'email.exists' => 'No account found with this email address.',
'password.required' => 'Password is required.',
'password.min' => 'Password must be at least 6 characters long.',
];
}
/**
* Get custom attributes for validator errors.
*/
public function attributes(): array
{
return [
'email' => 'email address',
'password' => 'password',
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
'email' => strtolower(trim($this->email)),
'remember' => $this->boolean('remember'),
]);
}
/**
* Handle failed validation attempts for security monitoring
*
* Logs failed login validation attempts with security context
* including IP address, user agent, and validation errors.
* Essential for detecting potential security threats.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return void
* @throws \Illuminate\Validation\ValidationException
*/
protected function failedValidation($validator): void
{
logger()->warning('Login validation failed', [
'email' => $this->input('email'),
'ip' => $this->ip(),
'user_agent' => $this->userAgent(),
'errors' => $validator->errors()->toArray(),
]);
parent::failedValidation($validator);
}
}

View File

@@ -0,0 +1,209 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Password;
/**
* Registration Form Request
*
* Validates user registration data with comprehensive security checks.
* Implements password strength validation and data sanitization.
*
* @author David Valera Melendez <david@valera-melendez.de>
* @since February 2025
*/
class RegisterRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'first_name' => [
'required',
'string',
'min:2',
'max:50',
'regex:/^[a-zA-ZÀ-ÿ\s\-\'\.]+$/',
],
'last_name' => [
'required',
'string',
'min:2',
'max:50',
'regex:/^[a-zA-ZÀ-ÿ\s\-\'\.]+$/',
],
'email' => [
'required',
'string',
'email:rfc,dns',
'max:255',
'unique:users,email',
],
'password' => [
'required',
'string',
'confirmed',
Password::min(8)
->letters()
->mixedCase()
->numbers()
->symbols()
->uncompromised(),
],
'password_confirmation' => [
'required',
'string',
'same:password',
],
'phone' => [
'nullable',
'string',
'min:10',
'max:20',
'regex:/^[\+]?[0-9\s\-\(\)]+$/',
],
'terms' => [
'required',
'accepted',
],
'newsletter' => [
'boolean',
],
'marketing' => [
'boolean',
],
];
}
/**
* Get custom error messages for validation rules.
*/
public function messages(): array
{
return [
'first_name.required' => 'First name is required.',
'first_name.min' => 'First name must be at least 2 characters.',
'first_name.regex' => 'First name contains invalid characters.',
'last_name.required' => 'Last name is required.',
'last_name.min' => 'Last name must be at least 2 characters.',
'last_name.regex' => 'Last name contains invalid characters.',
'email.required' => 'Email address is required.',
'email.email' => 'Please enter a valid email address.',
'email.unique' => 'An account with this email address already exists.',
'password.required' => 'Password is required.',
'password.min' => 'Password must be at least 8 characters long.',
'password.confirmed' => 'Password confirmation does not match.',
'password_confirmation.required' => 'Password confirmation is required.',
'password_confirmation.same' => 'Password confirmation must match the password.',
'phone.regex' => 'Please enter a valid phone number.',
'terms.required' => 'You must accept the terms and conditions.',
'terms.accepted' => 'You must accept the terms and conditions.',
];
}
/**
* Get custom attributes for validator errors.
*/
public function attributes(): array
{
return [
'first_name' => 'first name',
'last_name' => 'last name',
'email' => 'email address',
'password' => 'password',
'password_confirmation' => 'password confirmation',
'phone' => 'phone number',
'terms' => 'terms and conditions',
'newsletter' => 'newsletter subscription',
'marketing' => 'marketing communications',
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
'first_name' => ucfirst(strtolower(trim($this->first_name))),
'last_name' => ucfirst(strtolower(trim($this->last_name))),
'email' => strtolower(trim($this->email)),
'phone' => $this->phone ? preg_replace('/[^\+0-9]/', '', $this->phone) : null,
'newsletter' => $this->boolean('newsletter'),
'marketing' => $this->boolean('marketing'),
]);
}
/**
* Configure advanced validation rules and security checks
*
* Implements additional validation logic beyond standard rules:
* - Name similarity validation
* - Suspicious pattern detection
* - Data integrity verification
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
public function withValidator($validator): void
{
$validator->after(function ($validator) {
if ($this->first_name === $this->last_name) {
$validator->errors()->add(
'last_name',
'Last name should be different from first name.'
);
}
$suspiciousPatterns = ['test', 'admin', 'root', 'null', 'undefined'];
$fullName = strtolower($this->first_name . ' ' . $this->last_name);
foreach ($suspiciousPatterns as $pattern) {
if (strpos($fullName, $pattern) !== false) {
$validator->errors()->add(
'first_name',
'Please enter your real name.'
);
break;
}
}
});
}
/**
* Handle failed registration validation for security monitoring
*
* Logs failed registration attempts with comprehensive security context
* including user input, IP address, and validation errors.
* Critical for detecting registration abuse and attacks.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return void
* @throws \Illuminate\Validation\ValidationException
*/
protected function failedValidation($validator): void
{
logger()->warning('Registration validation failed', [
'email' => $this->input('email'),
'first_name' => $this->input('first_name'),
'last_name' => $this->input('last_name'),
'ip' => $this->ip(),
'user_agent' => $this->userAgent(),
'errors' => $validator->errors()->toArray(),
]);
parent::failedValidation($validator);
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
/**
* Update Profile Form Request
*
* Validates user profile update data with comprehensive security checks.
*
* @author David Valera Melendez <david@valera-melendez.de>
* @since February 2025
*/
class UpdateProfileRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Auth::check();
}
/**
* Get the validation rules that apply to the request.
*/
public function rules(): array
{
return [
'first_name' => [
'required',
'string',
'min:2',
'max:50',
'regex:/^[a-zA-ZÀ-ÿ\s\-\'\.]+$/',
],
'last_name' => [
'required',
'string',
'min:2',
'max:50',
'regex:/^[a-zA-ZÀ-ÿ\s\-\'\.]+$/',
],
'phone' => [
'nullable',
'string',
'min:10',
'max:20',
'regex:/^[\+]?[0-9\s\-\(\)]+$/',
],
'bio' => [
'nullable',
'string',
'max:1000',
],
'website' => [
'nullable',
'url',
'max:255',
'regex:/^https?:\/\/.+$/',
],
'linkedin' => [
'nullable',
'url',
'max:255',
'regex:/^https:\/\/(www\.)?linkedin\.com\/in\/[a-zA-Z0-9\-]+\/?$/',
],
'github' => [
'nullable',
'url',
'max:255',
'regex:/^https:\/\/(www\.)?github\.com\/[a-zA-Z0-9\-]+\/?$/',
],
'twitter' => [
'nullable',
'url',
'max:255',
'regex:/^https:\/\/(www\.)?twitter\.com\/[a-zA-Z0-9_]+\/?$/',
],
];
}
/**
* Get custom error messages for validation rules.
*/
public function messages(): array
{
return [
'first_name.required' => 'First name is required.',
'first_name.regex' => 'First name contains invalid characters.',
'last_name.required' => 'Last name is required.',
'last_name.regex' => 'Last name contains invalid characters.',
'phone.regex' => 'Please enter a valid phone number.',
'website.regex' => 'Website URL must start with http:// or https://',
'linkedin.regex' => 'Please enter a valid LinkedIn profile URL.',
'github.regex' => 'Please enter a valid GitHub profile URL.',
'twitter.regex' => 'Please enter a valid Twitter profile URL.',
];
}
/**
* Prepare the data for validation.
*/
protected function prepareForValidation(): void
{
$this->merge([
'first_name' => ucfirst(strtolower(trim($this->first_name ?? ''))),
'last_name' => ucfirst(strtolower(trim($this->last_name ?? ''))),
'phone' => $this->phone ? preg_replace('/[^\+0-9]/', '', $this->phone) : null,
'bio' => $this->bio ? trim($this->bio) : null,
'website' => $this->website ? strtolower(trim($this->website)) : null,
'linkedin' => $this->linkedin ? strtolower(trim($this->linkedin)) : null,
'github' => $this->github ? strtolower(trim($this->github)) : null,
'twitter' => $this->twitter ? strtolower(trim($this->twitter)) : null,
]);
}
}