33namespace App \Http \Controllers \Auth ;
44
55use App \Http \Controllers \Controller ;
6+ use App \Http \Controllers \SettingsController ;
67use App \Providers \RouteServiceProvider ;
78use App \User ;
9+ use App \UserEmail ;
810use Carbon \Carbon ;
11+ use Exception ;
912use Illuminate \Foundation \Auth \RegistersUsers ;
1013use Illuminate \Support \Facades \Hash ;
1114use Illuminate \Support \Facades \Validator ;
1215
13- class RegisterController extends Controller
14- {
16+ class RegisterController extends Controller {
1517 /*
1618 |--------------------------------------------------------------------------
1719 | Register Controller
@@ -30,15 +32,14 @@ class RegisterController extends Controller
3032 *
3133 * @var string
3234 */
33- protected $ redirectTo = RouteServiceProvider::HOME ;
35+ protected string $ redirectTo = RouteServiceProvider::HOME ;
3436
3537 /**
3638 * Create a new controller instance.
3739 *
3840 * @return void
3941 */
40- public function __construct ()
41- {
42+ public function __construct () {
4243 $ this ->middleware ('guest ' );
4344 }
4445
@@ -48,8 +49,7 @@ public function __construct()
4849 * @param array $data
4950 * @return \Illuminate\Contracts\Validation\Validator
5051 */
51- protected function validator (array $ data )
52- {
52+ protected function validator (array $ data ): \Illuminate \Contracts \Validation \Validator {
5353 return Validator::make ($ data , [
5454 'username ' => ['required ' , 'string ' , 'max:255 ' ],
5555 'email ' => ['required ' , 'string ' , 'email ' , 'max:255 ' , 'unique:users ' ],
@@ -61,15 +61,28 @@ protected function validator(array $data)
6161 * Create a new user instance after a valid registration.
6262 *
6363 * @param array $data
64- * @return \App\ User
64+ * @return User
6565 */
66- protected function create (array $ data )
67- {
68- return User::create ([
69- 'username ' => $ data ['username ' ],
70- 'email ' => $ data ['email ' ],
71- 'password ' => Hash::make ($ data ['password ' ]),
72- 'last_login ' => Carbon::now ()
73- ]);
66+ protected function create (array $ data ): User {
67+ $ user = User::create ([
68+ 'username ' => $ data ['username ' ],
69+ 'email ' => $ data ['email ' ],
70+ 'password ' => Hash::make ($ data ['password ' ]),
71+ 'last_login ' => Carbon::now ()
72+ ]);
73+
74+
75+ $ userEmail = UserEmail::create ([
76+ 'email ' => $ user ->email ,
77+ 'unverified_user_id ' => $ user ->id ,
78+ 'verification_key ' => md5 (rand (0 , 99999 ) . time () . $ user ->id )
79+ ]);
80+
81+ try {
82+ SettingsController::sendEmailVerification ($ userEmail );
83+ } catch (Exception $ e ) {
84+ report ($ e );
85+ }
86+ return $ user ;
7487 }
7588}
0 commit comments