mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 06:04:08 -08:00
55ee90b25d
* Fixes for #7252 - custom fields not validating / no validaton messages in API w/form requests * Removed debug info * More fixes for #7252 This is mostly working as intended, if not yet the way Laravel wants us to do it. Right now, the API returns correctly, and the form UI will return highlighted errors, with the input filled in ~sometimes~. I’m not sure why it’s only sometimes yet, but this is potentially progress. * Removed experimental method * Check for digits_between:0,240 for warranty * Removed debug code
69 lines
1.7 KiB
PHP
69 lines
1.7 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;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|