| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace App\Http\Controllers\Auth;
- use Illuminate\Foundation\Auth\RegistersUsers;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Http\Request;
- use Illuminate\Auth\Events\Registered;
- use Illuminate\Http\JsonResponse;
- use App\Http\Controllers\Controller;
- use App\Providers\RouteServiceProvider;
- use App\Models\User;
- use App\Models\Document;
- use App\Rules\AllowNickname;
- use App\Rules\NumberLength;
- use App\Rules\SpecialCharLength;
- use App\Rules\UppercaseLength;
- use App\Rules\DeniedEmail;
- class RegisterController extends Controller
- {
- /*
- |--------------------------------------------------------------------------
- | Register Controller
- |--------------------------------------------------------------------------
- |
- | This controller handles the registration of new users as well as their
- | validation and creation. By default this controller uses a trait to
- | provide this functionality without requiring any additional code.
- |
- */
- use RegistersUsers;
- /**
- * Where to redirect users after registration.
- *
- * @var string
- */
- protected $redirectTo = RouteServiceProvider::HOME;
- /**
- * Create a new controller instance.
- *
- * @return void
- */
- public function __construct()
- {
- $this->middleware('guest');
- }
- /**
- * Show the application registration form.
- *
- * @return \Illuminate\View\View
- */
- public function showRegistrationForm()
- {
- // 개인정보처리방침
- $privacy = (new Document)->findByCode('privacy');
- // 비밀번호 조건 확인
- $passwordMinLength = config('password_min_length');
- $passwordUppercaseLength = config('password_uppercase_length');
- $passwordNumbersLength = config('password_numbers_length');
- $passwordSpecialcharsLength = config('password_specialchars_length');
- $passwordGuideTip = "";
- if($passwordMinLength > 0) {
- $passwordGuideTip .= sprintf('최소 %d자 이상, ', $passwordMinLength);
- }
- if($passwordUppercaseLength > 0) {
- $passwordGuideTip .= sprintf('대문자 %d자 이상, ', $passwordUppercaseLength);
- }
- if($passwordNumbersLength > 0) {
- $passwordGuideTip .= sprintf('숫자 %d자 이상, ', $passwordNumbersLength);
- }
- if($passwordSpecialcharsLength > 0) {
- $passwordGuideTip .= sprintf('특수문자 %d자 이상, ', $passwordSpecialcharsLength);
- }
- $passwordGuideTip = rtrim($passwordGuideTip, ', ');
- return view('auth.register', [
- 'privacy' => $privacy,
- 'passwordGuideTip' => $passwordGuideTip
- ]);
- }
- /**
- * Get a validator for an incoming registration request.
- *
- * @param array $data
- * @return \Illuminate\Contracts\Validation\Validator
- */
- protected function validator(array $data)
- {
- return Validator::make($data, [
- 'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email', new DeniedEmail],
- 'nickname' => ['required', 'string', 'unique:users,nickname', 'min:2', 'max:20', new AllowNickname],
- 'password' => ['required', 'string', 'min:' . config('password_min_length', 4), 'confirmed', new NumberLength, new SpecialCharLength, new UppercaseLength],
- 'agree_1' => 'required|numeric|in:1',
- 'agree_2' => 'required|numeric|in:2'
- ], [], [
- 'email' => '이메일',
- 'nickname' => '닉네임',
- 'password' => '비밀번호',
- 'agree_1' => '이용약관 동의',
- 'agree_2' => '개인정보처리방침 동의'
- ]);
- }
- /**
- * Create a new user instance after a valid registration.
- *
- * @param array $data
- * @return \App\Models\User
- */
- protected function create(array $data): mixed
- {
- return (new User)->register($data);
- }
- /**
- * Handle a registration request for the application.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
- */
- public function register(Request $request)
- {
- // 회원가입 차단 확인
- if(config('use_register_block')) {
- return back()->withErrors('현재 회원 신청이 차단되어 회원가입을 할 수 없습니다. 관리자에게 문의하십시오.');
- }
- $this->validator($request->all())->validate();
- event(new Registered($user = $this->create($request->all())));
- $this->guard()->login($user);
- if ($response = $this->registered($request, $user)) {
- return $response;
- }
- return $request->wantsJson()
- ? new JsonResponse([], 201)
- : redirect($this->redirectPath());
- }
- }
|