mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
039f5da0e1
* Use correct Request include * Updated to use additional form request * Added SVG sanitizer * Added response method to form request * Allow ImageUploadRequest to accept fieldname params, added SVG sanitization, fixed delete * Fixed upload path for avatars * Added fieldname variable to blade partial for image upload * Added enctype="multipart/form-data" to form to allow uploads * Added image field * Updated Request::old() to use $request->old() * Fixed derp in edit blade referring to $item when it should be $user * Added svg+xml to image rule
75 lines
1.8 KiB
PHP
75 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
|
|
class SaveUserRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function response(array $errors)
|
|
{
|
|
return $this->redirector->back()->withInput()->withErrors($errors, $this->errorBag);
|
|
}
|
|
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
|
|
$rules = [];
|
|
|
|
switch($this->method())
|
|
{
|
|
|
|
// Brand new user
|
|
case 'POST':
|
|
{
|
|
$rules['first_name'] = 'required|string|min:1';
|
|
$rules['username'] = 'required_unless:ldap_import,1|string|min:1';
|
|
if ($this->request->get('ldap_import') == false)
|
|
{
|
|
$rules['password'] = Setting::passwordComplexityRulesSaving('store').'|confirmed';
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Save all fields
|
|
case 'PUT':
|
|
$rules['first_name'] = 'required|string|min:1';
|
|
$rules['username'] = 'required_unless:ldap_import,1|string|min:1';
|
|
$rules['password'] = Setting::passwordComplexityRulesSaving('update').'|confirmed';
|
|
break;
|
|
|
|
// Save only what's passed
|
|
case 'PATCH':
|
|
{
|
|
$rules['password'] = Setting::passwordComplexityRulesSaving('update');
|
|
break;
|
|
}
|
|
|
|
default:break;
|
|
}
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|