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('/');
54 parent::__construct();
58 * Get a validator for an incoming registration request.
60 * @return \Illuminate\Contracts\Validation\Validator
62 protected function validator(array $data)
64 return Validator::make($data, [
65 'name' => 'required|min:2|max:255',
66 'email' => 'required|email|max:255|unique:users',
67 'password' => 'required|min:8',
72 * Show the application registration form.
73 * @throws UserRegistrationException
75 public function getRegister()
77 $this->registrationService->ensureRegistrationAllowed();
78 $socialDrivers = $this->socialAuthService->getActiveDrivers();
79 return view('auth.register', [
80 'socialDrivers' => $socialDrivers,
85 * Handle a registration request for the application.
86 * @throws UserRegistrationException
88 public function postRegister(Request $request)
90 $this->registrationService->ensureRegistrationAllowed();
91 $this->validator($request->all())->validate();
92 $userData = $request->all();
95 $user = $this->registrationService->registerUser($userData);
97 } catch (UserRegistrationException $exception) {
98 if ($exception->getMessage()) {
99 $this->showErrorNotification($exception->getMessage());
101 return redirect($exception->redirectLocation);
104 $this->showSuccessNotification(trans('auth.register_success'));
105 return redirect($this->redirectPath());
109 * Create a new user instance after a valid registration.
113 protected function create(array $data)
115 return User::create([
116 'name' => $data['name'],
117 'email' => $data['email'],
118 'password' => Hash::make($data['password']),