Merge pull request 'Fix registration not displaying' (#14) from registration into master
Reviewed-on: #14
This commit is contained in:
commit
eeb2d425e5
@ -94,7 +94,7 @@ func (n Numeric) Add(other Numeric) Numeric {
|
|||||||
|
|
||||||
func (n Numeric) MarshalJSON() ([]byte, error) {
|
func (n Numeric) MarshalJSON() ([]byte, error) {
|
||||||
if n.Int.Int64() == 0 {
|
if n.Int.Int64() == 0 {
|
||||||
return []byte("\"0\""), nil
|
return []byte("0"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s := fmt.Sprintf("%d", n.Int)
|
s := fmt.Sprintf("%d", n.Int)
|
||||||
|
@ -5,6 +5,7 @@ import { useSessionStore } from "../stores/session";
|
|||||||
|
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
const login = ref({ user: "", password: "" });
|
const login = ref({ user: "", password: "" });
|
||||||
|
const router = useRouter(); // has to be called in setup
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
useSessionStore().setTitle("Login");
|
useSessionStore().setTitle("Login");
|
||||||
@ -15,7 +16,8 @@ function formSubmit(e: MouseEvent) {
|
|||||||
useSessionStore().login(login.value)
|
useSessionStore().login(login.value)
|
||||||
.then(x => {
|
.then(x => {
|
||||||
error.value = "";
|
error.value = "";
|
||||||
useRouter().replace("/dashboard");
|
router.replace("/dashboard");
|
||||||
|
return x;
|
||||||
})
|
})
|
||||||
.catch(x => error.value = "The entered credentials are invalid!");
|
.catch(x => error.value = "The entered credentials are invalid!");
|
||||||
|
|
||||||
@ -26,23 +28,17 @@ function formSubmit(e: MouseEvent) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<input
|
<input type="text" v-model="login.user"
|
||||||
type="text"
|
|
||||||
v-model="login.user"
|
|
||||||
placeholder="Username"
|
placeholder="Username"
|
||||||
class="border-2 border-black rounded-lg block px-2 my-2 w-48"
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
/>
|
<input type="password" v-model="login.password"
|
||||||
<input
|
|
||||||
type="password"
|
|
||||||
v-model="login.password"
|
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
class="border-2 border-black rounded-lg block px-2 my-2 w-48"
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div>{{ error }}</div>
|
<div>{{ error }}</div>
|
||||||
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Login</button>
|
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Login</button>
|
||||||
<p>
|
<p>
|
||||||
New user?
|
New user?
|
||||||
<router-link to="/register">Register</router-link>instead!
|
<router-link to="/register">Register</router-link> instead!
|
||||||
</p>
|
</p>
|
||||||
</template>
|
</template>
|
@ -1,16 +1,25 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue';
|
import { onMounted, ref } from "vue";
|
||||||
import { useSessionStore } from '../stores/session';
|
import { useRouter } from "vue-router";
|
||||||
|
import { useSessionStore } from "../stores/session";
|
||||||
|
|
||||||
const error = ref("");
|
const error = ref("");
|
||||||
const login = ref({ email: "", password: "", name: "" });
|
const login = ref({ email: "", password: "", name: "" });
|
||||||
const showPassword = ref(false);
|
const router = useRouter(); // has to be called in setup
|
||||||
|
|
||||||
function formSubmit(e: FormDataEvent) {
|
onMounted(() => {
|
||||||
|
useSessionStore().setTitle("Login");
|
||||||
|
});
|
||||||
|
|
||||||
|
function formSubmit(e: MouseEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
useSessionStore().register(login)
|
useSessionStore().register(login.value)
|
||||||
.then(() => error.value = "")
|
.then(x => {
|
||||||
.catch(() => error.value = "Something went wrong!");
|
error.value = "";
|
||||||
|
router.replace("/dashboard");
|
||||||
|
return x;
|
||||||
|
})
|
||||||
|
.catch(x => error.value = "The entered credentials are invalid!");
|
||||||
|
|
||||||
// TODO display invalidCredentials
|
// TODO display invalidCredentials
|
||||||
// TODO redirect to dashboard on success
|
// TODO redirect to dashboard on success
|
||||||
@ -18,44 +27,21 @@ function formSubmit(e: FormDataEvent) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-container>
|
<div>
|
||||||
<v-row>
|
<input type="text" v-model="login.name"
|
||||||
<v-col cols="12">
|
placeholder="Name"
|
||||||
<v-text-field v-model="login.email" type="text" label="E-Mail" />
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
</v-col>
|
<input type="text" v-model="login.email"
|
||||||
<v-col cols="12">
|
placeholder="Email"
|
||||||
<v-text-field v-model="login.name" type="text" label="Name" />
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
</v-col>
|
<input type="password" v-model="login.password"
|
||||||
<v-col cols="6">
|
placeholder="Password"
|
||||||
<v-text-field
|
class="border-2 border-black rounded-lg block px-2 my-2 w-48" />
|
||||||
v-model="login.password"
|
</div>
|
||||||
label="Password"
|
<div>{{ error }}</div>
|
||||||
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
<button type="submit" @click="formSubmit" class="bg-blue-300 rounded-lg p-2 w-48">Register</button>
|
||||||
:type="showPassword ? 'text' : 'password'"
|
<p>
|
||||||
@click:append="showPassword = showPassword"
|
Existing user?
|
||||||
:error-message="error"
|
<router-link to="/login">Login</router-link> instead!
|
||||||
error-count="2"
|
</p>
|
||||||
error
|
</template>
|
||||||
/>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="6">
|
|
||||||
<v-text-field
|
|
||||||
v-model="login.password"
|
|
||||||
label="Repeat password"
|
|
||||||
:append-icon="showPassword ? 'mdi-eye' : 'mdi-eye-off'"
|
|
||||||
:type="showPassword ? 'text' : 'password'"
|
|
||||||
@click:append="showPassword = showPassword"
|
|
||||||
:error-message="error"
|
|
||||||
error-count="2"
|
|
||||||
error
|
|
||||||
/>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
<div class="form-group">{{ error }}</div>
|
|
||||||
<v-btn type="submit" @click="formSubmit">Register</v-btn>
|
|
||||||
<p>
|
|
||||||
Existing user?
|
|
||||||
<router-link to="/login">Login</router-link>instead!
|
|
||||||
</p>
|
|
||||||
</v-container>
|
|
||||||
</template>
|
|
@ -20,12 +20,12 @@ export interface Budget {
|
|||||||
|
|
||||||
export const useSessionStore = defineStore('session', {
|
export const useSessionStore = defineStore('session', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
Session: useStorage<Session>('session', null, undefined, { serializer: StorageSerializers.object }),
|
Session: useStorage<Session | null>('session', null, undefined, { serializer: StorageSerializers.object }),
|
||||||
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
|
Budgets: useStorage<Map<string, Budget>>('budgets', new Map<string, Budget>(), undefined, { serializer: StorageSerializers.map }),
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
BudgetsList: (state) => [ ...state.Budgets.values() ],
|
BudgetsList: (state) => [ ...state.Budgets.values() ],
|
||||||
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session.Token}),
|
AuthHeaders: (state) => ({'Authorization': 'Bearer ' + state.Session?.Token}),
|
||||||
LoggedIn: (state) => state.Session != null,
|
LoggedIn: (state) => state.Session != null,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -42,15 +42,18 @@ export const useSessionStore = defineStore('session', {
|
|||||||
async login(login: any) {
|
async login(login: any) {
|
||||||
const response = await POST("/user/login", JSON.stringify(login));
|
const response = await POST("/user/login", JSON.stringify(login));
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return this.loginSuccess(result);
|
this.loginSuccess(result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
async register(login : any) {
|
async register(login : any) {
|
||||||
const response = await POST("/user/register", JSON.stringify(login));
|
const response = await POST("/user/register", JSON.stringify(login));
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
return this.loginSuccess(result);
|
this.loginSuccess(result);
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
this.$reset()
|
this.Session = null;
|
||||||
|
this.Budgets.clear();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
Loading…
x
Reference in New Issue
Block a user