mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Support for system APP_LOCALE * Start preferences re-write * port 2fa form * Working user preferences * Language user preference * Don't look up locale from the DB every request * Device list working * Deny demo user middleware * Finish password changing * remove used resource methods * remove leftover use * warn that translation is incomplete * fix style
76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Hash;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use LibreNMS\Config;
|
|
|
|
class UpdateUserRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
if ($this->user()->isAdmin()) {
|
|
return true;
|
|
}
|
|
|
|
$user = $this->route('user');
|
|
if ($user && $this->user()->can('update', $user)) {
|
|
// normal users cannot edit their level or ability to modify a password
|
|
unset($this['level'], $this['can_modify_passwd']);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'realname' => 'max:64',
|
|
'email' => 'nullable|email|max:64',
|
|
'descr' => 'max:30',
|
|
'level' => 'int',
|
|
'old_password' => 'nullable|string',
|
|
'new_password' => 'nullable|confirmed|min:' . Config::get('password.min_length', 8),
|
|
'new_password_confirmation' => 'nullable|same:new_password',
|
|
'dashboard' => 'int',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Configure the validator instance.
|
|
*
|
|
* @param \Illuminate\Validation\Validator $validator
|
|
* @return void
|
|
*/
|
|
public function withValidator($validator)
|
|
{
|
|
$validator->after(function ($validator) {
|
|
// if not an admin and new_password is set, check old password matches
|
|
if (!$this->user()->isAdmin()) {
|
|
if ($this->has('new_password')) {
|
|
if ($this->has('old_password')) {
|
|
$user = $this->route('user');
|
|
if ($user && !Hash::check($this->old_password, $user->password)) {
|
|
$validator->errors()->add('old_password', __('Existing password did not match'));
|
|
}
|
|
} else {
|
|
$validator->errors()->add('old_password', __('The :attribute field is required.', ['attribute' => 'old_password']));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|