init commit
This commit is contained in:
110
app/Http/Requests/Auth/LoginRequest.php
Normal file
110
app/Http/Requests/Auth/LoginRequest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
209
app/Http/Requests/Auth/RegisterRequest.php
Normal file
209
app/Http/Requests/Auth/RegisterRequest.php
Normal 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);
|
||||
}
|
||||
}
|
||||
119
app/Http/Requests/Auth/UpdateProfileRequest.php
Normal file
119
app/Http/Requests/Auth/UpdateProfileRequest.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
336
app/Http/Requests/Resume/StoreResumeRequest.php
Normal file
336
app/Http/Requests/Resume/StoreResumeRequest.php
Normal file
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Resume;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Store Resume Form Request
|
||||
*
|
||||
* Validates data for creating a new resume with comprehensive validation rules.
|
||||
* Implements business logic validations and data sanitization.
|
||||
*
|
||||
* @author David Valera Melendez <david@valera-melendez.de>
|
||||
* @since February 2025
|
||||
*/
|
||||
class StoreResumeRequest 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 [
|
||||
'title' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:3',
|
||||
'max:255',
|
||||
'regex:/^[a-zA-Z0-9\s\-\_\.\,\!\?]+$/',
|
||||
],
|
||||
'description' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:1000',
|
||||
],
|
||||
'template' => [
|
||||
'required',
|
||||
'string',
|
||||
'in:professional,modern,executive,minimal,technical',
|
||||
],
|
||||
'content' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'content.personal_info' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'content.personal_info.full_name' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.title' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.email' => [
|
||||
'nullable',
|
||||
'email',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.phone' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:20',
|
||||
],
|
||||
'content.personal_info.location' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.website' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.linkedin' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.github' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
],
|
||||
'content.summary' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:2000',
|
||||
],
|
||||
'content.experience' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:20',
|
||||
],
|
||||
'content.experience.*.company' => [
|
||||
'required_with:content.experience',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.experience.*.position' => [
|
||||
'required_with:content.experience',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.experience.*.start_date' => [
|
||||
'required_with:content.experience',
|
||||
'date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.experience.*.end_date' => [
|
||||
'nullable',
|
||||
'date',
|
||||
'after:content.experience.*.start_date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.experience.*.current' => [
|
||||
'boolean',
|
||||
],
|
||||
'content.experience.*.description' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:2000',
|
||||
],
|
||||
'content.education' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:10',
|
||||
],
|
||||
'content.education.*.institution' => [
|
||||
'required_with:content.education',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.education.*.degree' => [
|
||||
'required_with:content.education',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.education.*.field' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.education.*.start_date' => [
|
||||
'required_with:content.education',
|
||||
'date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.education.*.end_date' => [
|
||||
'nullable',
|
||||
'date',
|
||||
'after:content.education.*.start_date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.skills' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'settings' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'settings.color_scheme' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'in:blue,green,red,purple,orange,gray,black',
|
||||
],
|
||||
'settings.font_family' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'in:Arial,Times New Roman,Calibri,Helvetica,Georgia',
|
||||
],
|
||||
'settings.font_size' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'min:8',
|
||||
'max:16',
|
||||
],
|
||||
'is_public' => [
|
||||
'boolean',
|
||||
],
|
||||
'allow_comments' => [
|
||||
'boolean',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom error messages for validation rules.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'title.required' => 'Resume title is required.',
|
||||
'title.min' => 'Resume title must be at least 3 characters.',
|
||||
'title.max' => 'Resume title cannot exceed 255 characters.',
|
||||
'title.regex' => 'Resume title contains invalid characters.',
|
||||
'description.max' => 'Description cannot exceed 1000 characters.',
|
||||
'template.required' => 'Please select a resume template.',
|
||||
'template.in' => 'Selected template is not available.',
|
||||
'content.experience.max' => 'You cannot add more than 20 work experiences.',
|
||||
'content.education.max' => 'You cannot add more than 10 education entries.',
|
||||
'content.personal_info.email.email' => 'Please enter a valid email address.',
|
||||
'content.personal_info.website.url' => 'Please enter a valid website URL.',
|
||||
'content.personal_info.linkedin.url' => 'Please enter a valid LinkedIn URL.',
|
||||
'content.personal_info.github.url' => 'Please enter a valid GitHub URL.',
|
||||
'content.experience.*.company.required_with' => 'Company name is required for work experience.',
|
||||
'content.experience.*.position.required_with' => 'Position title is required for work experience.',
|
||||
'content.experience.*.start_date.required_with' => 'Start date is required for work experience.',
|
||||
'content.experience.*.start_date.before_or_equal' => 'Start date cannot be in the future.',
|
||||
'content.experience.*.end_date.after' => 'End date must be after start date.',
|
||||
'content.experience.*.end_date.before_or_equal' => 'End date cannot be in the future.',
|
||||
'content.education.*.institution.required_with' => 'Institution name is required for education.',
|
||||
'content.education.*.degree.required_with' => 'Degree is required for education.',
|
||||
'content.education.*.start_date.required_with' => 'Start date is required for education.',
|
||||
'settings.font_size.min' => 'Font size must be at least 8.',
|
||||
'settings.font_size.max' => 'Font size cannot exceed 16.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'resume title',
|
||||
'description' => 'resume description',
|
||||
'template' => 'resume template',
|
||||
'content.personal_info.full_name' => 'full name',
|
||||
'content.personal_info.title' => 'professional title',
|
||||
'content.personal_info.email' => 'email address',
|
||||
'content.personal_info.phone' => 'phone number',
|
||||
'content.personal_info.location' => 'location',
|
||||
'content.personal_info.website' => 'website',
|
||||
'content.personal_info.linkedin' => 'LinkedIn profile',
|
||||
'content.personal_info.github' => 'GitHub profile',
|
||||
'content.summary' => 'professional summary',
|
||||
'is_public' => 'public visibility',
|
||||
'allow_comments' => 'allow comments',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'title' => trim($this->title),
|
||||
'description' => $this->description ? trim($this->description) : null,
|
||||
'is_public' => $this->boolean('is_public'),
|
||||
'allow_comments' => $this->boolean('allow_comments'),
|
||||
]);
|
||||
|
||||
if ($this->has('content.personal_info')) {
|
||||
$personalInfo = $this->input('content.personal_info', []);
|
||||
|
||||
if (isset($personalInfo['email'])) {
|
||||
$personalInfo['email'] = strtolower(trim($personalInfo['email']));
|
||||
}
|
||||
|
||||
if (isset($personalInfo['full_name'])) {
|
||||
$personalInfo['full_name'] = trim($personalInfo['full_name']);
|
||||
}
|
||||
|
||||
$this->merge(['content' => array_merge($this->input('content', []), [
|
||||
'personal_info' => $personalInfo
|
||||
])]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*/
|
||||
public function withValidator($validator): void
|
||||
{
|
||||
$validator->after(function ($validator) {
|
||||
$userId = Auth::id();
|
||||
$existingResume = \App\Models\Resume::where('user_id', $userId)
|
||||
->where('title', $this->title)
|
||||
->first();
|
||||
|
||||
if ($existingResume) {
|
||||
$validator->errors()->add(
|
||||
'title',
|
||||
'You already have a resume with this title. Please choose a different title.'
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->has('content.experience') && is_array($this->content['experience'])) {
|
||||
foreach ($this->content['experience'] as $index => $experience) {
|
||||
if (!empty($experience['start_date']) && !empty($experience['end_date'])) {
|
||||
$startDate = Carbon::parse($experience['start_date']);
|
||||
$endDate = Carbon::parse($experience['end_date']);
|
||||
|
||||
if ($startDate->greaterThan($endDate)) {
|
||||
$validator->errors()->add(
|
||||
"content.experience.{$index}.end_date",
|
||||
'End date must be after start date.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*/
|
||||
protected function failedValidation($validator): void
|
||||
{
|
||||
logger()->warning('Resume creation validation failed', [
|
||||
'user_id' => Auth::id(),
|
||||
'title' => $this->input('title'),
|
||||
'template' => $this->input('template'),
|
||||
'errors' => $validator->errors()->toArray(),
|
||||
]);
|
||||
|
||||
parent::failedValidation($validator);
|
||||
}
|
||||
}
|
||||
465
app/Http/Requests/Resume/UpdateResumeRequest.php
Normal file
465
app/Http/Requests/Resume/UpdateResumeRequest.php
Normal file
@@ -0,0 +1,465 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Resume;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Update Resume Form Request
|
||||
*
|
||||
* Validates data for updating an existing resume with comprehensive validation rules.
|
||||
* Implements business logic validations and data sanitization for resume updates.
|
||||
*
|
||||
* @author David Valera Melendez <david@valera-melendez.de>
|
||||
* @since February 2025
|
||||
*/
|
||||
class UpdateResumeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
$resume = $this->route('resume');
|
||||
return Auth::check() && $resume && $resume->user_id === Auth::id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$resumeId = $this->route('resume')->id ?? null;
|
||||
|
||||
return [
|
||||
'title' => [
|
||||
'sometimes',
|
||||
'required',
|
||||
'string',
|
||||
'min:3',
|
||||
'max:255',
|
||||
'regex:/^[a-zA-Z0-9\s\-\_\.\,\!\?]+$/',
|
||||
],
|
||||
'description' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:1000',
|
||||
],
|
||||
'template' => [
|
||||
'sometimes',
|
||||
'required',
|
||||
'string',
|
||||
'in:professional,modern,executive,minimal,technical',
|
||||
],
|
||||
'status' => [
|
||||
'sometimes',
|
||||
'string',
|
||||
'in:draft,published,archived',
|
||||
],
|
||||
'content' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'content.personal_info' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'content.personal_info.full_name' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.title' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.email' => [
|
||||
'nullable',
|
||||
'email',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.phone' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:20',
|
||||
'regex:/^[\+]?[0-9\s\-\(\)]+$/',
|
||||
],
|
||||
'content.personal_info.location' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.website' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
],
|
||||
'content.personal_info.linkedin' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
'regex:/^https:\/\/(www\.)?linkedin\.com\/in\/[a-zA-Z0-9\-]+\/?$/',
|
||||
],
|
||||
'content.personal_info.github' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
'regex:/^https:\/\/(www\.)?github\.com\/[a-zA-Z0-9\-]+\/?$/',
|
||||
],
|
||||
'content.summary' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:2000',
|
||||
],
|
||||
'content.experience' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:20',
|
||||
],
|
||||
'content.experience.*.company' => [
|
||||
'required_with:content.experience',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.experience.*.position' => [
|
||||
'required_with:content.experience',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.experience.*.location' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.experience.*.start_date' => [
|
||||
'required_with:content.experience',
|
||||
'date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.experience.*.end_date' => [
|
||||
'nullable',
|
||||
'date',
|
||||
'after:content.experience.*.start_date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.experience.*.current' => [
|
||||
'boolean',
|
||||
],
|
||||
'content.experience.*.description' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:2000',
|
||||
],
|
||||
'content.experience.*.achievements' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:10',
|
||||
],
|
||||
'content.experience.*.achievements.*' => [
|
||||
'string',
|
||||
'max:500',
|
||||
],
|
||||
'content.education' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:10',
|
||||
],
|
||||
'content.education.*.institution' => [
|
||||
'required_with:content.education',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.education.*.degree' => [
|
||||
'required_with:content.education',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.education.*.field' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.education.*.start_date' => [
|
||||
'required_with:content.education',
|
||||
'date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.education.*.end_date' => [
|
||||
'nullable',
|
||||
'date',
|
||||
'after:content.education.*.start_date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.education.*.gpa' => [
|
||||
'nullable',
|
||||
'numeric',
|
||||
'min:0',
|
||||
'max:4',
|
||||
],
|
||||
'content.education.*.description' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:1000',
|
||||
],
|
||||
'content.skills' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'content.projects' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:15',
|
||||
],
|
||||
'content.projects.*.name' => [
|
||||
'required_with:content.projects',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.projects.*.description' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:1000',
|
||||
],
|
||||
'content.projects.*.url' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
],
|
||||
'content.projects.*.technologies' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:20',
|
||||
],
|
||||
'content.certifications' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:20',
|
||||
],
|
||||
'content.certifications.*.name' => [
|
||||
'required_with:content.certifications',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.certifications.*.issuer' => [
|
||||
'required_with:content.certifications',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
'content.certifications.*.date' => [
|
||||
'required_with:content.certifications',
|
||||
'date',
|
||||
'before_or_equal:today',
|
||||
],
|
||||
'content.certifications.*.url' => [
|
||||
'nullable',
|
||||
'url',
|
||||
'max:255',
|
||||
],
|
||||
'content.languages' => [
|
||||
'nullable',
|
||||
'array',
|
||||
'max:10',
|
||||
],
|
||||
'content.languages.*.language' => [
|
||||
'required_with:content.languages',
|
||||
'string',
|
||||
'max:100',
|
||||
],
|
||||
'content.languages.*.level' => [
|
||||
'required_with:content.languages',
|
||||
'string',
|
||||
'in:Native,Fluent,Advanced,Intermediate,Basic',
|
||||
],
|
||||
'settings' => [
|
||||
'nullable',
|
||||
'array',
|
||||
],
|
||||
'settings.color_scheme' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'in:blue,green,red,purple,orange,gray,black',
|
||||
],
|
||||
'settings.font_family' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'in:Arial,Times New Roman,Calibri,Helvetica,Georgia',
|
||||
],
|
||||
'settings.font_size' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'min:8',
|
||||
'max:16',
|
||||
],
|
||||
'settings.line_spacing' => [
|
||||
'nullable',
|
||||
'numeric',
|
||||
'min:1.0',
|
||||
'max:2.0',
|
||||
],
|
||||
'settings.margin' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
'min:10',
|
||||
'max:30',
|
||||
],
|
||||
'settings.show_photo' => [
|
||||
'boolean',
|
||||
],
|
||||
'is_public' => [
|
||||
'boolean',
|
||||
],
|
||||
'allow_comments' => [
|
||||
'boolean',
|
||||
],
|
||||
'password' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'min:6',
|
||||
'max:50',
|
||||
],
|
||||
'expires_at' => [
|
||||
'nullable',
|
||||
'date',
|
||||
'after:today',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom error messages for validation rules.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'title.required' => 'Resume title is required.',
|
||||
'title.min' => 'Resume title must be at least 3 characters.',
|
||||
'title.regex' => 'Resume title contains invalid characters.',
|
||||
'template.in' => 'Selected template is not available.',
|
||||
'status.in' => 'Invalid resume status.',
|
||||
'content.personal_info.email.email' => 'Please enter a valid email address.',
|
||||
'content.personal_info.phone.regex' => 'Please enter a valid phone number.',
|
||||
'content.personal_info.linkedin.regex' => 'Please enter a valid LinkedIn profile URL.',
|
||||
'content.personal_info.github.regex' => 'Please enter a valid GitHub profile URL.',
|
||||
'content.experience.max' => 'You cannot have more than 20 work experiences.',
|
||||
'content.education.max' => 'You cannot have more than 10 education entries.',
|
||||
'content.projects.max' => 'You cannot have more than 15 projects.',
|
||||
'content.certifications.max' => 'You cannot have more than 20 certifications.',
|
||||
'content.languages.max' => 'You cannot have more than 10 languages.',
|
||||
'content.experience.*.end_date.after' => 'End date must be after start date.',
|
||||
'content.education.*.gpa.max' => 'GPA cannot exceed 4.0.',
|
||||
'content.languages.*.level.in' => 'Invalid language proficiency level.',
|
||||
'settings.font_size.min' => 'Font size must be at least 8.',
|
||||
'settings.font_size.max' => 'Font size cannot exceed 16.',
|
||||
'settings.line_spacing.min' => 'Line spacing must be at least 1.0.',
|
||||
'settings.line_spacing.max' => 'Line spacing cannot exceed 2.0.',
|
||||
'expires_at.after' => 'Expiration date must be in the future.',
|
||||
'password.min' => 'Password must be at least 6 characters.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('title')) {
|
||||
$this->merge(['title' => trim($this->title)]);
|
||||
}
|
||||
|
||||
if ($this->has('description')) {
|
||||
$this->merge(['description' => $this->description ? trim($this->description) : null]);
|
||||
}
|
||||
|
||||
$this->merge([
|
||||
'is_public' => $this->boolean('is_public'),
|
||||
'allow_comments' => $this->boolean('allow_comments'),
|
||||
]);
|
||||
|
||||
|
||||
if ($this->has('content.personal_info')) {
|
||||
$personalInfo = $this->input('content.personal_info', []);
|
||||
|
||||
if (isset($personalInfo['email'])) {
|
||||
$personalInfo['email'] = strtolower(trim($personalInfo['email']));
|
||||
}
|
||||
|
||||
$this->merge(['content' => array_merge($this->input('content', []), [
|
||||
'personal_info' => $personalInfo
|
||||
])]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator instance.
|
||||
*/
|
||||
public function withValidator($validator): void
|
||||
{
|
||||
$validator->after(function ($validator) {
|
||||
$resume = $this->route('resume');
|
||||
|
||||
if ($this->has('title')) {
|
||||
$userId = Auth::id();
|
||||
$existingResume = \App\Models\Resume::where('user_id', $userId)
|
||||
->where('title', $this->title)
|
||||
->where('id', '!=', $resume->id)
|
||||
->first();
|
||||
|
||||
if ($existingResume) {
|
||||
$validator->errors()->add(
|
||||
'title',
|
||||
'You already have a resume with this title. Please choose a different title.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->has('content.experience') && is_array($this->content['experience'])) {
|
||||
foreach ($this->content['experience'] as $index => $experience) {
|
||||
if (!empty($experience['start_date']) && !empty($experience['end_date'])) {
|
||||
$startDate = Carbon::parse($experience['start_date']);
|
||||
$endDate = Carbon::parse($experience['end_date']);
|
||||
|
||||
if ($startDate->greaterThan($endDate)) {
|
||||
$validator->errors()->add(
|
||||
"content.experience.{$index}.end_date",
|
||||
'End date must be after start date.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->has('status') && $this->status === 'published') {
|
||||
$content = $this->input('content', []);
|
||||
$requiredSections = ['personal_info', 'summary'];
|
||||
|
||||
foreach ($requiredSections as $section) {
|
||||
if (empty($content[$section])) {
|
||||
$validator->errors()->add(
|
||||
'status',
|
||||
"Cannot publish resume: {$section} section is required."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*/
|
||||
protected function failedValidation($validator): void
|
||||
{
|
||||
$resume = $this->route('resume');
|
||||
|
||||
logger()->warning('Resume update validation failed', [
|
||||
'user_id' => Auth::id(),
|
||||
'resume_id' => $resume->id ?? null,
|
||||
'title' => $this->input('title'),
|
||||
'errors' => $validator->errors()->toArray(),
|
||||
]);
|
||||
|
||||
parent::failedValidation($validator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user