From 95f40ad22a128eb8a110a3c97a0e9f81004c3cd1 Mon Sep 17 00:00:00 2001 From: Nuno Pereira Date: Sun, 4 Aug 2024 20:56:46 +0100 Subject: [PATCH] Added custom registration logic to account for promoter codes --- .env | 6 +- app/Actions/Fortify/CreateNewUser.php | 7 ++ .../Controllers/RegisteredUserController.php | 66 +++++++++++++++++++ resources/js/Pages/Auth/Register.vue | 16 +++++ routes/fortify.php | 6 +- 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/RegisteredUserController.php diff --git a/.env b/.env index 81193ef0..277b3931 100644 --- a/.env +++ b/.env @@ -1,7 +1,9 @@ APP_NAME=ENEI APP_KEY=base64:O8e0ShbVWB3OAAFGbSUweWr1JM3xutu1isYLKLk4mqU= APP_DEBUG=true -APP_URL=http://localhost +APP_URL=http://localhost:8000 +APP_ENV=local +APP_PORT=8000 LOCALE=pt FAKER_LOCALE=pt_PT @@ -15,7 +17,7 @@ DB_USERNAME=postgres SCOUT_QUEUE=true SCOUT_DRIVER=meilisearch -MEILISEARCH_HOST=http://meilisearch:3331 +MEILISEARCH_HOST=http://meilisearch:7700 MEILISEARCH_KEY=my-master-key MEILISEARCH_NO_ANALYTICS=false diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index baaed059..978959a6 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -26,8 +26,15 @@ public function create(array $input): User 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 'password' => $this->passwordRules(), 'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '', + 'promoter' => ['optional', 'string'], ])->validate(); + $promoter = $input['promoter']; + + if (! is_null($promoter)) { + // TODO: Trigger promoter point attribution algorithm + } + $data = [ 'name' => $input['name'], 'email' => $input['email'], diff --git a/app/Http/Controllers/RegisteredUserController.php b/app/Http/Controllers/RegisteredUserController.php new file mode 100644 index 00000000..fc2c4fc6 --- /dev/null +++ b/app/Http/Controllers/RegisteredUserController.php @@ -0,0 +1,66 @@ +guard = $guard; + } + + /** + * Show the registration view. + */ + public function create(Request $request): RegisterViewResponse + { + $promoter = null; + if ($request->is('register/promoter/*')) { + $promoter = $request->route('promoter'); + dd($promoter); + } + + return app(RegisterViewResponse::class); + } + + /** + * Create a new registered user. + */ + public function store(Request $request, + CreatesNewUsers $creator): RegisterResponse + { + if (config('fortify.lowercase_usernames')) { + $request->merge([ + Fortify::username() => Str::lower($request->{Fortify::username()}), + ]); + } + + event(new Registered($user = $creator->create($request->all()))); + + $this->guard->login($user); + + return app(RegisterResponse::class); + } +} diff --git a/resources/js/Pages/Auth/Register.vue b/resources/js/Pages/Auth/Register.vue index 1dedefb0..c7f0828b 100644 --- a/resources/js/Pages/Auth/Register.vue +++ b/resources/js/Pages/Auth/Register.vue @@ -6,11 +6,18 @@ import TextInput from "@/Components/TextInput.vue"; import CardLayout from "../../Layouts/CardLayout.vue"; import route from "ziggy-js"; +interface Props { + promoter?: string; +} + +defineProps(); + const form = useForm({ name: "", email: "", password: "", password_confirmation: "", + promoter: "", terms: false, }); @@ -65,6 +72,15 @@ const submit = () => { :error-message="form.errors.password_confirmation" /> + +