3 namespace BookStack\Http\Controllers\Auth;
5 use BookStack\Auth\Access\RegistrationService;
6 use BookStack\Auth\Access\SocialAuthService;
7 use BookStack\Auth\User;
8 use BookStack\Exceptions\UserRegistrationException;
9 use BookStack\Http\Controllers\Controller;
10 use Illuminate\Foundation\Auth\RegistersUsers;
11 use Illuminate\Http\Request;
12 use Illuminate\Support\Facades\Hash;
15 class RegisterController extends Controller
18 |--------------------------------------------------------------------------
20 |--------------------------------------------------------------------------
22 | This controller handles the registration of new users as well as their
23 | validation and creation. By default this controller uses a trait to
24 | provide this functionality without requiring any additional code.
30 protected $socialAuthService;
31 protected $registrationService;
34 * Where to redirect users after login / registration.
38 protected $redirectTo = '/';
39 protected $redirectPath = '/';
42 * Create a new controller instance.
44 public function __construct(SocialAuthService $socialAuthService, RegistrationService $registrationService)
46 $this->middleware('guest');
47 $this->middleware('guard:standard');
49 $this->socialAuthService = $socialAuthService;
50 $this->registrationService = $registrationService;
52 $this->redirectTo = url('/');
53 $this->redirectPath = url('/');
57 * Get a validator for an incoming registration request.
59 * @return \Illuminate\Contracts\Validation\Validator
61 protected function validator(array $data)
63 return Validator::make($data, [
64 'name' => 'required|min:2|max:255',
65 'email' => 'required|email|max:255|unique:users',
66 'password' => 'required|min:8',
71 * Show the application registration form.
72 * @throws UserRegistrationException
74 public function getRegister()
76 $this->registrationService->ensureRegistrationAllowed();
77 $socialDrivers = $this->socialAuthService->getActiveDrivers();
78 return view('auth.register', [
79 'socialDrivers' => $socialDrivers,
84 * Handle a registration request for the application.
85 * @throws UserRegistrationException
87 public function postRegister(Request $request)
89 $this->registrationService->ensureRegistrationAllowed();
90 $this->validator($request->all())->validate();
91 $userData = $request->all();
94 $user = $this->registrationService->registerUser($userData);
96 } catch (UserRegistrationException $exception) {
97 if ($exception->getMessage()) {
98 $this->showErrorNotification($exception->getMessage());
100 return redirect($exception->redirectLocation);
103 $this->showSuccessNotification(trans('auth.register_success'));
104 return redirect($this->redirectPath());
108 * Create a new user instance after a valid registration.
112 protected function create(array $data)
114 return User::create([
115 'name' => $data['name'],
116 'email' => $data['email'],
117 'password' => Hash::make($data['password']),