From 5a83254bdc17349aebdc9f7b2194acb47712c62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Drunen?= Date: Sat, 7 Sep 2024 22:45:51 +0200 Subject: [PATCH] Support registering through SPA prototype --- .../Controllers/Api/CurrencyController.php | 16 ++++ .../Controllers/Api/RegisterController.php | 50 ++++++++++ app/Http/Resources/CurrencyResource.php | 19 ++++ resources/assets/js/prototype/app.js | 5 + .../assets/js/prototype/screens/Login.vue | 4 +- .../assets/js/prototype/screens/Register.vue | 96 +++++++++++++++++++ .../assets/js/prototype/translations/en.json | 4 + routes/api.php | 5 + 8 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Api/CurrencyController.php create mode 100644 app/Http/Controllers/Api/RegisterController.php create mode 100644 app/Http/Resources/CurrencyResource.php create mode 100644 resources/assets/js/prototype/screens/Register.vue diff --git a/app/Http/Controllers/Api/CurrencyController.php b/app/Http/Controllers/Api/CurrencyController.php new file mode 100644 index 00000000..4976db78 --- /dev/null +++ b/app/Http/Controllers/Api/CurrencyController.php @@ -0,0 +1,16 @@ +validate([ + 'name' => ['required'], + 'email' => ['required', 'email', 'unique:users'], + 'password' => ['required', 'confirmed'], + 'currency' => ['required', 'exists:currencies,id'], + ]); + + $user = User::query() + ->create([ + 'name' => $request->input('name'), + 'email' => $request->input('email'), + 'password' => Hash::make($request->input('password')), + 'verification_token' => Str::random(100), + ]); + + $space = Space::query() + ->create([ + 'currency_id' => $request->input('currency'), + 'name' => $user->name . '\'s Space', + ]); + + $user->spaces()->attach($space->id, ['role' => 'admin']); + + (new SendVerificationMailAction())->execute($user->id); + + return [ + 'success' => true, + ]; + } +} diff --git a/app/Http/Resources/CurrencyResource.php b/app/Http/Resources/CurrencyResource.php new file mode 100644 index 00000000..ca800ebc --- /dev/null +++ b/app/Http/Resources/CurrencyResource.php @@ -0,0 +1,19 @@ + $this->id, + 'name' => $this->name, + 'symbol' => $this->symbol, + 'iso' => $this->iso, + ]; + } +} diff --git a/resources/assets/js/prototype/app.js b/resources/assets/js/prototype/app.js index c336c189..4405fdba 100644 --- a/resources/assets/js/prototype/app.js +++ b/resources/assets/js/prototype/app.js @@ -8,6 +8,7 @@ import translations from './translations'; import App from './components/App.vue'; import Login from './screens/Login.vue'; +import Register from './screens/Register.vue'; import Dashboard from './screens/Dashboard.vue'; import TransactionsIndex from './screens/Transactions/Index.vue'; import TransactionsCreate from './screens/Transactions/Create.vue'; @@ -27,6 +28,10 @@ const routes = [ path: '/prototype/login', name: 'login', component: Login, + }, { + path: '/prototype/register', + name: 'register', + component: Register, }, { path: '/prototype/dashboard', name: 'dashboard', diff --git a/resources/assets/js/prototype/screens/Login.vue b/resources/assets/js/prototype/screens/Login.vue index 45bf9a50..80986a5c 100644 --- a/resources/assets/js/prototype/screens/Login.vue +++ b/resources/assets/js/prototype/screens/Login.vue @@ -69,7 +69,9 @@ watch(showError, value => { -
{{ versionNumber }}
+
+ First time here? Register. +
diff --git a/resources/assets/js/prototype/screens/Register.vue b/resources/assets/js/prototype/screens/Register.vue new file mode 100644 index 00000000..6e0eca41 --- /dev/null +++ b/resources/assets/js/prototype/screens/Register.vue @@ -0,0 +1,96 @@ + + + diff --git a/resources/assets/js/prototype/translations/en.json b/resources/assets/js/prototype/translations/en.json index 472d9d74..0e4a4a17 100644 --- a/resources/assets/js/prototype/translations/en.json +++ b/resources/assets/js/prototype/translations/en.json @@ -1,6 +1,7 @@ { "amount": "Amount", "create": "Create", + "currency": "Currency", "dailyBalanceGraphDescription": "Here is your balance throughout the month", "dashboard": "Dashboard", "date": "Date", @@ -13,8 +14,11 @@ "goodMorning": "Good morning", "language": "Language", "logIn": "Log in", + "name": "Name", "password": "Password", "recurringDescription": "This is a recurring transaction—create it for me in the future", + "register": "Register", + "repeatPassword": "Repeat password", "spending": "Spending", "spendingDescriptionPlaceholder": "Birthday present for Angela", "tag": "Tag", diff --git a/routes/api.php b/routes/api.php index 337fefbc..ab199e7d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,15 +1,20 @@ group(function () {