mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
e3e0d57f56
* Add IDE Helper files * Cleanup imports - Alphabetises imports - Removes unused imports * Add Platform requirements * Move filling asset into block where asset exists * Remove duplicate array keys
65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Setting;
|
|
|
|
class SaveUserRequest extends Request
|
|
{
|
|
/**
|
|
* 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;
|
|
|
|
}
|
|
}
|