update: login & register form
This commit is contained in:
@@ -27,7 +27,7 @@ function validatePassword() {
|
|||||||
if (!password.value) {
|
if (!password.value) {
|
||||||
passwordError.value = '密碼為必填。';
|
passwordError.value = '密碼為必填。';
|
||||||
} else if (password.value.length < 8) {
|
} else if (password.value.length < 8) {
|
||||||
passwordError.value = '使用者名稱長度必須至少八個字元。';
|
passwordError.value = '密碼長度必須至少八個字元。';
|
||||||
} else {
|
} else {
|
||||||
passwordError.value = '';
|
passwordError.value = '';
|
||||||
}
|
}
|
||||||
@@ -69,8 +69,8 @@ const onSubmit = async () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<form @submit.prevent="onSubmit">
|
<form @submit.prevent="onSubmit">
|
||||||
<fieldset class="ts-fieldset">
|
<div class="ts-box ts-content">
|
||||||
<legend class="ts-legend">登入</legend>
|
<div class="ts-header is-large is-center-aligned has-bottom-spaced">登入</div>
|
||||||
<div class="ts-wrap is-vertical">
|
<div class="ts-wrap is-vertical">
|
||||||
<div class="ts-control is-wide">
|
<div class="ts-control is-wide">
|
||||||
<div class="label">使用者名稱</div>
|
<div class="label">使用者名稱</div>
|
||||||
@@ -92,11 +92,11 @@ const onSubmit = async () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ts-wrap has-top-spaced is-end-aligned">
|
<div class="ts-wrap has-top-spaced is-end-aligned">
|
||||||
<button class="ts-button" type="submit" :class="{
|
<button class="ts-button is-fluid" type="submit" :class="{
|
||||||
'is-disabled': username === '' || password === '' || usernameError !== '' || passwordError !== ''
|
'is-disabled': username === '' || password === '' || usernameError !== '' || passwordError !== ''
|
||||||
}">送出</button>
|
}">登入</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -105,4 +105,12 @@ const onSubmit = async () => {
|
|||||||
color: red;
|
color: red;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ts-control {
|
||||||
|
--label-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ts-control .content.is-fluid {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ function validatePassword() {
|
|||||||
if (!password.value) {
|
if (!password.value) {
|
||||||
passwordError.value = '密碼為必填。';
|
passwordError.value = '密碼為必填。';
|
||||||
} else if (password.value.length < 8) {
|
} else if (password.value.length < 8) {
|
||||||
passwordError.value = '使用者名稱長度必須至少八個字元。';
|
passwordError.value = '密碼長度必須至少八個字元。';
|
||||||
} else {
|
} else {
|
||||||
passwordError.value = '';
|
passwordError.value = '';
|
||||||
}
|
}
|
||||||
@@ -57,8 +57,8 @@ const submit = () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<form @submit.prevent="submit">
|
<form @submit.prevent="submit">
|
||||||
<fieldset class="ts-fieldset">
|
<div class="ts-box ts-content">
|
||||||
<legend class="ts-legend">註冊</legend>
|
<div class="ts-header is-large is-center-aligned has-bottom-spaced">註冊</div>
|
||||||
<div class="ts-wrap is-vertical">
|
<div class="ts-wrap is-vertical">
|
||||||
<div class="ts-control is-wide">
|
<div class="ts-control is-wide">
|
||||||
<div class="label ts-text is-required">使用者名稱</div>
|
<div class="label ts-text is-required">使用者名稱</div>
|
||||||
@@ -84,7 +84,7 @@ const submit = () => {
|
|||||||
<div class="ts-wrap has-top-spaced is-end-aligned">
|
<div class="ts-wrap has-top-spaced is-end-aligned">
|
||||||
<button class="ts-button" type="submit" :class="{'is-disabled': username === '' || password === '' }">送出</button>
|
<button class="ts-button" type="submit" :class="{'is-disabled': username === '' || password === '' }">送出</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -93,4 +93,12 @@ const submit = () => {
|
|||||||
color: red;
|
color: red;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ts-control {
|
||||||
|
--label-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ts-control .content.is-fluid {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+5
-19
@@ -1,24 +1,10 @@
|
|||||||
|
<script setup>
|
||||||
|
import LoginForm from '../components/Login/LoginForm.vue';
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="ts-container">
|
<div class="ts-app-center">
|
||||||
<LoginForm />
|
<LoginForm />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import LoginForm from '../components/Login/LoginForm.vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const onSubmit = async () => {
|
|
||||||
try {
|
|
||||||
const response = await login(username.value, password.value);
|
|
||||||
const { jwt } = response;
|
|
||||||
localStorage.setItem('jwt', jwt);
|
|
||||||
alert('Login successful!');
|
|
||||||
router.push('/');
|
|
||||||
} catch (error) {
|
|
||||||
alert("Login failed: " + error.message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const handleNewUser = async ({ username, password }) => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="ts-container">
|
<div class="ts-app-center">
|
||||||
<RegisterForm @new-user="handleNewUser" />
|
<RegisterForm @new-user="handleNewUser" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user