- 사용자 등록 시 비밀번호 입력 필드 제거 - 임의 비밀번호 자동 생성 후 이메일 발송 - 사용자 수정 페이지에 비밀번호 초기화 버튼 추가 - 사용자 모달에 비밀번호 초기화 버튼 추가 - 사용자 모달 프로필 이미지 없을 때 이름 첫글자 표시 (한글 지원) - UserPasswordMail 클래스 및 이메일 템플릿 추가
89 lines
2.7 KiB
PHP
89 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreUserRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Prepare the data for validation.
|
|
* 일반관리자가 슈퍼관리자를 생성하려는 경우 is_super_admin 필드 제거
|
|
*/
|
|
protected function prepareForValidation(): void
|
|
{
|
|
// 슈퍼관리자가 아닌 경우 is_super_admin 필드를 false로 강제 설정
|
|
if (! auth()->user()?->is_super_admin) {
|
|
$this->merge([
|
|
'is_super_admin' => false,
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'user_id' => 'nullable|string|max:50|unique:users,user_id',
|
|
'name' => 'required|string|max:100',
|
|
'email' => 'required|email|max:255|unique:users,email',
|
|
'phone' => 'nullable|string|max:20',
|
|
// password는 시스템이 자동 생성하므로 입력 받지 않음
|
|
'role' => 'nullable|string|max:50',
|
|
'is_active' => 'nullable|boolean',
|
|
'is_super_admin' => 'nullable|boolean',
|
|
'role_ids' => 'nullable|array',
|
|
'role_ids.*' => 'integer|exists:roles,id',
|
|
'department_ids' => 'nullable|array',
|
|
'department_ids.*' => 'integer|exists:departments,id',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'user_id' => '사용자 ID',
|
|
'name' => '이름',
|
|
'email' => '이메일',
|
|
'phone' => '연락처',
|
|
'password' => '비밀번호',
|
|
'password_confirmation' => '비밀번호 확인',
|
|
'role' => '역할',
|
|
'is_active' => '활성 상태',
|
|
'is_super_admin' => '슈퍼 관리자',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'email.unique' => '이미 사용 중인 이메일입니다.',
|
|
'user_id.unique' => '이미 사용 중인 사용자 ID입니다.',
|
|
'password.confirmed' => '비밀번호가 일치하지 않습니다.',
|
|
'password.min' => '비밀번호는 최소 8자 이상이어야 합니다.',
|
|
];
|
|
}
|
|
}
|