2016-06-06 14:15:50 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
2017-08-22 20:32:39 -07:00
|
|
|
use App\Models\Setting;
|
2016-06-06 14:15:50 -07:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2017-08-22 20:32:39 -07:00
|
|
|
|
|
|
|
$rules = [];
|
|
|
|
|
2017-10-24 16:56:46 -07:00
|
|
|
\Log::debug($this->method());
|
2017-08-22 21:15:35 -07:00
|
|
|
switch($this->method())
|
|
|
|
{
|
|
|
|
|
2017-10-24 16:56:46 -07:00
|
|
|
// Brand new user
|
2017-08-22 21:15:35 -07:00
|
|
|
case 'POST':
|
|
|
|
{
|
|
|
|
$rules['first_name'] = 'required|string|min:1';
|
2017-08-31 10:43:36 -07:00
|
|
|
$rules['username'] = 'required_unless:ldap_import,1|string|min:1';
|
2017-08-22 21:15:35 -07:00
|
|
|
$rules['password'] = Setting::passwordComplexityRulesSaving('store');
|
2017-10-24 16:56:46 -07:00
|
|
|
break;
|
2017-08-22 21:15:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save all fields
|
|
|
|
case 'PUT':
|
|
|
|
$rules['first_name'] = 'required|string|min:1';
|
2017-08-31 10:43:36 -07:00
|
|
|
$rules['username'] = 'required_unless:ldap_import,1|string|min:1';
|
2017-08-22 21:15:35 -07:00
|
|
|
$rules['password'] = Setting::passwordComplexityRulesSaving('update');
|
2017-10-24 16:56:46 -07:00
|
|
|
break;
|
2017-08-22 21:15:35 -07:00
|
|
|
|
|
|
|
// Save only what's passed
|
|
|
|
case 'PATCH':
|
|
|
|
{
|
|
|
|
$rules['password'] = Setting::passwordComplexityRulesSaving('update');
|
2017-10-24 16:56:46 -07:00
|
|
|
break;
|
2017-08-22 21:15:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
default:break;
|
2017-08-22 20:32:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$rules['password_confirm'] = 'sometimes|required_with:password';
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
|
2016-06-06 14:15:50 -07:00
|
|
|
}
|
|
|
|
}
|