-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #505 from range-of-motion/support-registering-thro…
…ugh-spa-prototype Support registering through SPA prototype
- Loading branch information
Showing
11 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\CurrencyResource; | ||
use App\Models\Currency; | ||
|
||
class CurrencyController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return CurrencyResource::collection(Currency::all()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Actions\SendVerificationMailAction; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Space; | ||
use App\Models\User; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Str; | ||
|
||
class RegisterController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
if (config('app.disable_registration')) { | ||
abort(404); | ||
} | ||
|
||
$request->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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class CurrencyResource extends JsonResource | ||
{ | ||
public function toArray(Request $request): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'name' => $this->name, | ||
'symbol' => $this->symbol, | ||
'iso' => $this->iso, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<script setup> | ||
import axios from 'axios'; | ||
import { Loader2 } from 'lucide-vue'; | ||
import { getCurrentInstance, ref } from 'vue'; | ||
const router = getCurrentInstance().proxy.$router; | ||
const isBusy = ref(false); | ||
const errors = ref({}); | ||
const name = ref(''); | ||
const email = ref(''); | ||
const password = ref(''); | ||
const repeatedPassword = ref(''); | ||
const currencies = ref([]); | ||
const currency = ref(1); | ||
const fetchCurrencies = () => { | ||
axios | ||
.get('/api/currencies') | ||
.then(response => { | ||
currencies.value = response.data; | ||
}); | ||
}; | ||
const register = () => { | ||
isBusy.value = true; | ||
axios | ||
.post('/api/register', { name: name.value, email: email.value, password: password.value, password_confirmation: repeatedPassword.value, currency: currency.value }) | ||
.then(response => { | ||
const json = response.data; | ||
if (json.success) { | ||
router.push({ name: 'login' }); | ||
} | ||
}) | ||
.catch(error => { | ||
isBusy.value = false; | ||
password.value = ''; | ||
repeatedPassword.value = ''; | ||
if (error.response && error.response.data) { | ||
const json = error.response.data; | ||
if (json.errors) { | ||
errors.value = json.errors; | ||
} | ||
} | ||
}); | ||
}; | ||
fetchCurrencies(); | ||
</script> | ||
|
||
<template> | ||
<div class="flex items-center justify-center min-h-screen"> | ||
<div class="flex-1 max-w-sm"> | ||
<div class="p-5 space-y-5 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg"> | ||
<div> | ||
<label class="block mb-2 text-sm dark:text-white">{{ $t('name') }}</label> | ||
<input class="w-full px-3.5 py-2.5 text-sm dark:text-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg" type="text" v-model="name" @keyup.enter="register" /> | ||
<div v-if="errors.name" class="mt-1.5 text-sm text-red-500">{{ errors.name[0] }}</div> | ||
</div> | ||
<div> | ||
<label class="block mb-2 text-sm dark:text-white">{{ $t('email') }}</label> | ||
<input class="w-full px-3.5 py-2.5 text-sm dark:text-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg" type="email" v-model="email" @keyup.enter="register" /> | ||
<div v-if="errors.email" class="mt-1.5 text-sm text-red-500">{{ errors.email[0] }}</div> | ||
</div> | ||
<div> | ||
<label class="block mb-2 text-sm dark:text-white">{{ $t('password') }}</label> | ||
<input class="w-full px-3.5 py-2.5 text-sm dark:text-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg" type="password" v-model="password" @keyup.enter="register" /> | ||
<div v-if="errors.password" class="mt-1.5 text-sm text-red-500">{{ errors.password[0] }}</div> | ||
</div> | ||
<div> | ||
<label class="block mb-2 text-sm dark:text-white">{{ $t('repeatPassword') }}</label> | ||
<input class="w-full px-3.5 py-2.5 text-sm dark:text-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg" type="password" v-model="repeatedPassword" @keyup.enter="register" /> | ||
</div> | ||
<div> | ||
<label class="block mb-2 text-sm dark:text-white">{{ $t('currency') }}</label> | ||
<select class="w-full px-3.5 py-2.5 text-sm dark:text-white dark:bg-gray-700 border border-gray-200 dark:border-gray-600 rounded-lg appearance-none" v-model="currency"> | ||
<option v-for="currency in currencies" :value="currency.id">{{ currency.name }} (<span v-html="currency.symbol"></span>)</option> | ||
</select> | ||
</div> | ||
<button class="w-full py-3 text-sm text-white bg-gray-900 dark:bg-gray-950 rounded-lg" @click="register"> | ||
<span v-if="!isBusy">{{ $t('register') }}</span> | ||
<div v-if="isBusy" class="flex justify-center h-5"> | ||
<Loader2 class="animate-spin" :size="18" :strokeWidth="2.4" /> | ||
</div> | ||
</button> | ||
</div> | ||
<div class="mt-4 text-sm text-center"> | ||
<router-link class="text-gray-500 dark:text-white" :to="{ name: 'login' }">Already using Budget? Log in.</router-link> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters