Copy/pasted login from ImNote
This commit is contained in:
@@ -12,15 +12,20 @@
|
||||
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@felte/validator-yup": "^1.0.1",
|
||||
"@sveltejs/adapter-auto": "next",
|
||||
"@sveltejs/kit": "next",
|
||||
"@types/luxon": "^2.0.9",
|
||||
"@types/yup": "^0.29.13",
|
||||
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
||||
"@typescript-eslint/parser": "^5.10.1",
|
||||
"autoprefixer": "^10.4.2",
|
||||
"cookie": "^0.4.2",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-svelte3": "^3.2.1",
|
||||
"felte": "^1.0.1",
|
||||
"js-cookie": "^3.0.1",
|
||||
"luxon": "^2.3.1",
|
||||
"postcss": "^8.4.5",
|
||||
"postcss-load-config": "^3.1.1",
|
||||
@@ -32,7 +37,8 @@
|
||||
"svelte-preprocess": "^4.10.1",
|
||||
"tailwindcss": "^3.0.12",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "~4.5.4"
|
||||
"typescript": "~4.5.4",
|
||||
"yup": "^0.32.11"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
||||
|
||||
Generated
+106
@@ -1,15 +1,20 @@
|
||||
lockfileVersion: 5.3
|
||||
|
||||
specifiers:
|
||||
'@felte/validator-yup': ^1.0.1
|
||||
'@sveltejs/adapter-auto': next
|
||||
'@sveltejs/kit': next
|
||||
'@types/luxon': ^2.0.9
|
||||
'@types/yup': ^0.29.13
|
||||
'@typescript-eslint/eslint-plugin': ^5.10.1
|
||||
'@typescript-eslint/parser': ^5.10.1
|
||||
autoprefixer: ^10.4.2
|
||||
cookie: ^0.4.2
|
||||
eslint: ^7.32.0
|
||||
eslint-config-prettier: ^8.3.0
|
||||
eslint-plugin-svelte3: ^3.2.1
|
||||
felte: ^1.0.1
|
||||
js-cookie: ^3.0.1
|
||||
luxon: ^2.3.1
|
||||
postcss: ^8.4.5
|
||||
postcss-load-config: ^3.1.1
|
||||
@@ -22,17 +27,23 @@ specifiers:
|
||||
tailwindcss: ^3.0.12
|
||||
tslib: ^2.3.1
|
||||
typescript: ~4.5.4
|
||||
yup: ^0.32.11
|
||||
|
||||
devDependencies:
|
||||
'@felte/validator-yup': 1.0.1_yup@0.32.11
|
||||
'@sveltejs/adapter-auto': 1.0.0-next.29
|
||||
'@sveltejs/kit': 1.0.0-next.287_svelte@3.46.4
|
||||
'@types/luxon': 2.0.9
|
||||
'@types/yup': 0.29.13
|
||||
'@typescript-eslint/eslint-plugin': 5.12.1_78ba2542c270c83b2a80bb1c125195b6
|
||||
'@typescript-eslint/parser': 5.12.1_eslint@7.32.0+typescript@4.5.5
|
||||
autoprefixer: 10.4.2_postcss@8.4.7
|
||||
cookie: 0.4.2
|
||||
eslint: 7.32.0
|
||||
eslint-config-prettier: 8.4.0_eslint@7.32.0
|
||||
eslint-plugin-svelte3: 3.4.1_eslint@7.32.0+svelte@3.46.4
|
||||
felte: 1.0.1_svelte@3.46.4
|
||||
js-cookie: 3.0.1
|
||||
luxon: 2.3.1
|
||||
postcss: 8.4.7
|
||||
postcss-load-config: 3.1.3
|
||||
@@ -45,6 +56,7 @@ devDependencies:
|
||||
tailwindcss: 3.0.23_autoprefixer@10.4.2
|
||||
tslib: 2.3.1
|
||||
typescript: 4.5.5
|
||||
yup: 0.32.11
|
||||
|
||||
packages:
|
||||
|
||||
@@ -68,6 +80,13 @@ packages:
|
||||
js-tokens: 4.0.0
|
||||
dev: true
|
||||
|
||||
/@babel/runtime/7.17.2:
|
||||
resolution: {integrity: sha512-hzeyJyMA1YGdJTuWU0e/j4wKXrU4OMFvY2MSlaI9B7VQb0r5cxTE3EAIS2Q7Tn2RIcDkRvTA/v2JsAEhxe99uw==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
dependencies:
|
||||
regenerator-runtime: 0.13.9
|
||||
dev: true
|
||||
|
||||
/@eslint/eslintrc/0.4.3:
|
||||
resolution: {integrity: sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==}
|
||||
engines: {node: ^10.12.0 || >=12.0.0}
|
||||
@@ -85,6 +104,28 @@ packages:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/@felte/common/1.0.1:
|
||||
resolution: {integrity: sha512-P905IdJzdiawo+YsnM5Cg2ziou5VHBDCCiVHXqGFBrEmq/RyxSdOfuRbOBKAz3l5eigQl8QGK26b3rVLz7mxRQ==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
dev: true
|
||||
|
||||
/@felte/core/1.0.1:
|
||||
resolution: {integrity: sha512-wrdiiQIfw4fDTVN9THowqSQcckkwrW8EN92mIKqqa+wbcYz7cSBAi3GtgNWJcZuEV631ij2nnygQnxV/8hhdnA==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
dependencies:
|
||||
'@felte/common': 1.0.1
|
||||
dev: true
|
||||
|
||||
/@felte/validator-yup/1.0.1_yup@0.32.11:
|
||||
resolution: {integrity: sha512-lylJ5FlzZeUh3/NJJyPPF0uBlj4Fi4YmCdt3M7saPOrGZJsr09AD8o+fXQr4aUllwbIFbjN3z6zkSpYE1wYAqA==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
peerDependencies:
|
||||
yup: ^0.32.9
|
||||
dependencies:
|
||||
'@felte/common': 1.0.1
|
||||
yup: 0.32.11
|
||||
dev: true
|
||||
|
||||
/@humanwhocodes/config-array/0.5.0:
|
||||
resolution: {integrity: sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==}
|
||||
engines: {node: '>=10.10.0'}
|
||||
@@ -215,6 +256,10 @@ packages:
|
||||
resolution: {integrity: sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==}
|
||||
dev: true
|
||||
|
||||
/@types/lodash/4.14.179:
|
||||
resolution: {integrity: sha512-uwc1x90yCKqGcIOAT6DwOSuxnrAbpkdPsUOZtwrXb4D/6wZs+6qG7QnIawDuZWg0sWpxl+ltIKCaLoMlna678w==}
|
||||
dev: true
|
||||
|
||||
/@types/luxon/2.0.9:
|
||||
resolution: {integrity: sha512-ZuzIc7aN+i2ZDMWIiSmMdubR9EMMSTdEzF6R+FckP4p6xdnOYKqknTo/k+xXQvciSXlNGIwA4OPU5X7JIFzYdA==}
|
||||
dev: true
|
||||
@@ -237,6 +282,10 @@ packages:
|
||||
'@types/node': 17.0.21
|
||||
dev: true
|
||||
|
||||
/@types/yup/0.29.13:
|
||||
resolution: {integrity: sha512-qRyuv+P/1t1JK1rA+elmK1MmCL1BapEzKKfbEhDBV/LMMse4lmhZ/XbgETI39JveDJRpLjmToOI6uFtMW/WR2g==}
|
||||
dev: true
|
||||
|
||||
/@typescript-eslint/eslint-plugin/5.12.1_78ba2542c270c83b2a80bb1c125195b6:
|
||||
resolution: {integrity: sha512-M499lqa8rnNK7mUv74lSFFttuUsubIRdAbHcVaP93oFcKkEmHmLqy2n7jM9C8DVmFMYK61ExrZU6dLYhQZmUpw==}
|
||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||
@@ -590,6 +639,11 @@ packages:
|
||||
resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=}
|
||||
dev: true
|
||||
|
||||
/cookie/0.4.2:
|
||||
resolution: {integrity: sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==}
|
||||
engines: {node: '>= 0.6'}
|
||||
dev: true
|
||||
|
||||
/cosmiconfig/7.0.1:
|
||||
resolution: {integrity: sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -1122,6 +1176,16 @@ packages:
|
||||
reusify: 1.0.4
|
||||
dev: true
|
||||
|
||||
/felte/1.0.1_svelte@3.46.4:
|
||||
resolution: {integrity: sha512-fGz9KUBbBzv+QTgocHx2lGiRCNQXoXnBOfPvkVi4JWnofQCbKAYKQ80ytqAvqv+NphAZp6Zb/+luToIfqJ+Q2w==}
|
||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||
peerDependencies:
|
||||
svelte: ^3.31.0
|
||||
dependencies:
|
||||
'@felte/core': 1.0.1
|
||||
svelte: 3.46.4
|
||||
dev: true
|
||||
|
||||
/file-entry-cache/6.0.1:
|
||||
resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}
|
||||
engines: {node: ^10.12.0 || >=12.0.0}
|
||||
@@ -1326,6 +1390,11 @@ packages:
|
||||
resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=}
|
||||
dev: true
|
||||
|
||||
/js-cookie/3.0.1:
|
||||
resolution: {integrity: sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw==}
|
||||
engines: {node: '>=12'}
|
||||
dev: true
|
||||
|
||||
/js-tokens/4.0.0:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
dev: true
|
||||
@@ -1376,6 +1445,10 @@ packages:
|
||||
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
|
||||
dev: true
|
||||
|
||||
/lodash-es/4.17.21:
|
||||
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
|
||||
dev: true
|
||||
|
||||
/lodash.merge/4.6.2:
|
||||
resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==}
|
||||
dev: true
|
||||
@@ -1384,6 +1457,10 @@ packages:
|
||||
resolution: {integrity: sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=}
|
||||
dev: true
|
||||
|
||||
/lodash/4.17.21:
|
||||
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
|
||||
dev: true
|
||||
|
||||
/lru-cache/6.0.0:
|
||||
resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -1446,6 +1523,10 @@ packages:
|
||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||
dev: true
|
||||
|
||||
/nanoclone/0.2.1:
|
||||
resolution: {integrity: sha512-wynEP02LmIbLpcYw8uBKpcfF6dmg2vcpKqxeH5UcoKEYdExslsdUA4ugFauuaeYdTB76ez6gJW8XAZ6CgkXYxA==}
|
||||
dev: true
|
||||
|
||||
/nanoid/3.3.1:
|
||||
resolution: {integrity: sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw==}
|
||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||
@@ -1626,6 +1707,10 @@ packages:
|
||||
engines: {node: '>=0.4.0'}
|
||||
dev: true
|
||||
|
||||
/property-expr/2.0.5:
|
||||
resolution: {integrity: sha512-IJUkICM5dP5znhCckHSv30Q4b5/JA5enCtkRHYaOVOAocnH/1BQEYTC5NMfT3AVl/iXKdr3aqQbQn9DxyWknwA==}
|
||||
dev: true
|
||||
|
||||
/punycode/2.1.1:
|
||||
resolution: {integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==}
|
||||
engines: {node: '>=6'}
|
||||
@@ -1647,6 +1732,10 @@ packages:
|
||||
picomatch: 2.3.1
|
||||
dev: true
|
||||
|
||||
/regenerator-runtime/0.13.9:
|
||||
resolution: {integrity: sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==}
|
||||
dev: true
|
||||
|
||||
/regexpp/3.2.0:
|
||||
resolution: {integrity: sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -2012,6 +2101,10 @@ packages:
|
||||
is-number: 7.0.0
|
||||
dev: true
|
||||
|
||||
/toposort/2.0.2:
|
||||
resolution: {integrity: sha1-riF2gXXRVZ1IvvNUILL0li8JwzA=}
|
||||
dev: true
|
||||
|
||||
/tslib/1.14.1:
|
||||
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
|
||||
dev: true
|
||||
@@ -2138,3 +2231,16 @@ packages:
|
||||
/yeast/0.1.2:
|
||||
resolution: {integrity: sha1-AI4G2AlDIMNy28L47XagymyKxBk=}
|
||||
dev: true
|
||||
|
||||
/yup/0.32.11:
|
||||
resolution: {integrity: sha512-Z2Fe1bn+eLstG8DRR6FTavGD+MeAwyfmouhHsIUgaADz8jvFKbO/fXc2trJKZg+5EBjh4gGm3iU/t3onKlXHIg==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
'@babel/runtime': 7.17.2
|
||||
'@types/lodash': 4.14.179
|
||||
lodash: 4.17.21
|
||||
lodash-es: 4.17.21
|
||||
nanoclone: 0.2.1
|
||||
property-expr: 2.0.5
|
||||
toposort: 2.0.2
|
||||
dev: true
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
<!--<script context='module' lang='ts'>
|
||||
export async function load({ session }) {
|
||||
console.log(import.meta.env.VITE_BASE_ADDRESS);
|
||||
if (session.authenticated) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/'
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
</script>-->
|
||||
|
||||
<script lang='ts'>
|
||||
//import { rememberme } from '$lib/utils/clientAuth';
|
||||
import { browser } from '$app/env';
|
||||
|
||||
/*if (browser) {
|
||||
rememberme().then((res) => {
|
||||
if (res) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
|
||||
let loginData = {
|
||||
email: '',
|
||||
password: ''
|
||||
};
|
||||
let emailEmpty = true;
|
||||
let passwordEmpty = true;
|
||||
let responseData = {
|
||||
open: false,
|
||||
data: ''
|
||||
};
|
||||
let inputValid = false;
|
||||
let isSubmitting = false;
|
||||
|
||||
$: emailEmpty = loginData.email === '';
|
||||
$: passwordEmpty = loginData.password === '';
|
||||
$: inputValid = !emailEmpty && !passwordEmpty;
|
||||
|
||||
const login = async (): Promise<void> => {
|
||||
if (emailEmpty || passwordEmpty) {
|
||||
return;
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append('username', loginData.email);
|
||||
formData.append('password', loginData.password);
|
||||
const res = await fetch('/api/v1/users/token/cookie', {
|
||||
method: 'post',
|
||||
body: formData
|
||||
});
|
||||
isSubmitting = true;
|
||||
if (res.status === 200) {
|
||||
responseData.data = loginData.password === '' ? 'magic' : 'password';
|
||||
} else if (res.status === 404) {
|
||||
responseData.data = '404';
|
||||
} else {
|
||||
responseData.data = 'error';
|
||||
}
|
||||
responseData.open = true;
|
||||
isSubmitting = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class='flex items-center justify-center h-screen px-4'>
|
||||
<div>
|
||||
|
||||
<span class='p-4' />
|
||||
|
||||
<div
|
||||
class='w-full max-w-sm mx-auto overflow-hidden bg-white rounded-lg shadow-md dark:bg-gray-800'
|
||||
>
|
||||
<div class='px-6 py-4'>
|
||||
<h2 class='text-3xl font-bold text-center text-gray-700 dark:text-white'>ClassQuiz</h2>
|
||||
|
||||
<h3 class='mt-1 text-xl font-medium text-center text-gray-600 dark:text-gray-200'>
|
||||
Welcome Back
|
||||
</h3>
|
||||
|
||||
<p class='mt-1 text-center text-gray-500 dark:text-gray-400'>
|
||||
Login or create account
|
||||
</p>
|
||||
|
||||
<form on:submit|preventDefault={login}>
|
||||
<div class='w-full mt-4'>
|
||||
<div class='dark:bg-gray-800 bg-white p-4 rounded-lg'>
|
||||
<div class='relative bg-inherit w-full'>
|
||||
<input
|
||||
id='email'
|
||||
bind:value={loginData.email}
|
||||
name='email'
|
||||
type='email'
|
||||
class='w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600'
|
||||
placeholder='Email'
|
||||
/>
|
||||
<label
|
||||
for='email'
|
||||
class='absolute cursor-text left-0 -top-3 text-sm text-gray-700 dark:text-white bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all'
|
||||
>
|
||||
Email
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class='dark:bg-gray-800 bg-white p-4 rounded-lg'>
|
||||
<div
|
||||
class='relative bg-inherit w-full'
|
||||
|
||||
>
|
||||
<input
|
||||
id='password'
|
||||
name='password'
|
||||
type='password'
|
||||
bind:value={loginData.password}
|
||||
class='w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600'
|
||||
placeholder='Password'
|
||||
/>
|
||||
<label
|
||||
for='password'
|
||||
class='absolute cursor-text left-0 -top-3 text-sm text-gray-500 bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all'
|
||||
>
|
||||
Password
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='flex items-center justify-between mt-4'>
|
||||
<a
|
||||
href='/account/reset-password'
|
||||
class='text-sm text-gray-600 dark:text-gray-200 hover:text-gray-500'
|
||||
>Forgot Password?</a
|
||||
>
|
||||
|
||||
<button
|
||||
class='px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded hover:bg-gray-600 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50'
|
||||
disabled={!inputValid}
|
||||
type='submit'>
|
||||
{#if isSubmitting}
|
||||
<svg class='h-4 w-4 animate-spin' viewBox='3 3 18 18'>
|
||||
<path
|
||||
class='fill-blue-800'
|
||||
d='M12 5C8.13401 5 5 8.13401 5 12C5 15.866 8.13401 19 12 19C15.866 19 19 15.866 19 12C19 8.13401 15.866 5 12 5ZM3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12Z'
|
||||
/>
|
||||
<path
|
||||
class='fill-blue-100'
|
||||
d='M16.9497 7.05015C14.2161 4.31648 9.78392 4.31648 7.05025 7.05015C6.65973 7.44067 6.02656 7.44067 5.63604 7.05015C5.24551 6.65962 5.24551 6.02646 5.63604 5.63593C9.15076 2.12121 14.8492 2.12121 18.364 5.63593C18.7545 6.02646 18.7545 6.65962 18.364 7.05015C17.9734 7.44067 17.3403 7.44067 16.9497 7.05015Z'
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
Login
|
||||
{/if}
|
||||
</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class='flex items-center justify-center py-4 text-center bg-gray-50 dark:bg-gray-700'
|
||||
>
|
||||
<span class='text-sm text-gray-600 dark:text-gray-200'
|
||||
>Don't have an account?
|
||||
</span>
|
||||
|
||||
<a
|
||||
href='/account/register'
|
||||
class='mx-2 text-sm font-bold text-blue-500 dark:text-blue-400 hover:underline'
|
||||
>Register</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class='fixed z-10 inset-0 overflow-y-auto'
|
||||
aria-labelledby='modal-title'
|
||||
role='dialog'
|
||||
aria-modal='true'
|
||||
class:hidden={!responseData.open}
|
||||
>
|
||||
<div
|
||||
class='flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0'
|
||||
>
|
||||
<!--
|
||||
Background overlay, show/hide based on modal state.
|
||||
|
||||
Entering: "ease-out duration-300"
|
||||
From: "opacity-0"
|
||||
To: "opacity-100"
|
||||
Leaving: "ease-in duration-200"
|
||||
From: "opacity-100"
|
||||
To: "opacity-0"
|
||||
-->
|
||||
<div
|
||||
class='fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity'
|
||||
aria-hidden='true'
|
||||
/>
|
||||
|
||||
<!-- This element is to trick the browser into centering the modal contents. -->
|
||||
<span class='hidden sm:inline-block sm:align-middle sm:h-screen' aria-hidden='true'
|
||||
>​</span
|
||||
>
|
||||
|
||||
<!--
|
||||
Modal panel, show/hide based on modal state.
|
||||
|
||||
Entering: "ease-out duration-300"
|
||||
From: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
To: "opacity-100 translate-y-0 sm:scale-100"
|
||||
Leaving: "ease-in duration-200"
|
||||
From: "opacity-100 translate-y-0 sm:scale-100"
|
||||
To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
-->
|
||||
<div
|
||||
class='inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full'
|
||||
>
|
||||
<div class='bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4'>
|
||||
<div class='sm:flex sm:items-start'>
|
||||
<div
|
||||
class='mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10'
|
||||
>
|
||||
<!-- Heroicon name: outline/exclamation -->
|
||||
{#if responseData.data === '404' || responseData.data === 'error'}
|
||||
<svg
|
||||
class='h-6 w-6 text-red-600'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
fill='none'
|
||||
viewBox='0 0 24 24'
|
||||
stroke='currentColor'
|
||||
aria-hidden='true'
|
||||
>
|
||||
<path
|
||||
stroke-linecap='round'
|
||||
stroke-linejoin='round'
|
||||
stroke-width='2'
|
||||
d='M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z'
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg
|
||||
class='w-6 h-6 text-green-600'
|
||||
fill='none'
|
||||
stroke='currentColor'
|
||||
viewBox='0 0 24 24'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
>
|
||||
<path
|
||||
stroke-linecap='round'
|
||||
stroke-linejoin='round'
|
||||
stroke-width='2'
|
||||
d='M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z'
|
||||
/>
|
||||
</svg
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
<div class='mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left'>
|
||||
<h3 class='text-lg leading-6 font-medium text-gray-900' id='modal-title'>
|
||||
{#if responseData.data === 'magic'}
|
||||
Login Succeded! Check your mailbox!
|
||||
{:else if responseData.data === 'password'}
|
||||
Login Succeded!
|
||||
{:else if responseData.data === '404'}
|
||||
Wrong email or password!
|
||||
{:else if responseData.data === 'error'}
|
||||
unexpected error!
|
||||
{:else}
|
||||
You stupid Mawoka!
|
||||
{/if}
|
||||
</h3>
|
||||
<div class='mt-2'>
|
||||
<p class='text-sm text-gray-500'>
|
||||
{#if responseData.data === 'magic'}
|
||||
Please check your mailbox, since you should have received a
|
||||
Mail, with a link you can click to login.
|
||||
{:else if responseData.data === 'password'}
|
||||
You've successfully logged in!
|
||||
{:else if responseData.data === '404'}
|
||||
Please make sure that your password and your email are correct!
|
||||
{:else if responseData.data === 'error'}
|
||||
There was the good old unexpected error!
|
||||
{:else}
|
||||
You stupid Mawoka!
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse'>
|
||||
<button
|
||||
type='button'
|
||||
on:click={() => {
|
||||
responseData.open = false;
|
||||
if (responseData.data === 'magic' || responseData.data === 'password') {
|
||||
window.location.reload();
|
||||
}
|
||||
}}
|
||||
class='mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm'
|
||||
>Close
|
||||
</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,341 @@
|
||||
<script context='module' lang='ts'>
|
||||
export async function load({ session }) {
|
||||
if (session.authenticated) {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/'
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang='ts'>
|
||||
import { createForm } from 'felte';
|
||||
// import reporter from '@felte/reporter-tippy';
|
||||
import { validateSchema } from '@felte/validator-yup';
|
||||
import * as yup from 'yup';
|
||||
|
||||
const registerSchema = yup.object({
|
||||
email: yup.string().email().required(),
|
||||
password1: yup.string().required().min(8, 'must be at least 8 characters long'),
|
||||
password2: yup
|
||||
.string()
|
||||
.required()
|
||||
.test('equal', 'Passwords do not match!', function(v) {
|
||||
const ref = yup.ref('password1');
|
||||
return v === this.resolve(ref);
|
||||
}),
|
||||
username: yup.string().required().min(3, 'must be at least 3 characters long').max(20, 'must be at most 20 characters long')
|
||||
});
|
||||
|
||||
const { form, errors, touched, isValid, isSubmitting } = createForm<yup.InferType<typeof registerSchema>>({
|
||||
validate: validateSchema(registerSchema),
|
||||
onSubmit: async (values) => {
|
||||
const res = await fetch('/api/v1/users/create', {
|
||||
method: 'post',
|
||||
body: JSON.stringify({
|
||||
email: values.email,
|
||||
password: values.password1,
|
||||
username: values.username
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
if (res.status === 200) {
|
||||
responseData.data = '200';
|
||||
} else if (res.status === 409) {
|
||||
responseData.data = '409';
|
||||
} else if (res.status === 400) {
|
||||
responseData.data = '400';
|
||||
} else {
|
||||
responseData.data = 'error';
|
||||
}
|
||||
responseData.open = true;
|
||||
}
|
||||
});
|
||||
let responseData = {
|
||||
open: false,
|
||||
data: ''
|
||||
};
|
||||
</script>
|
||||
|
||||
<div class='flex items-center justify-center h-screen px-4'>
|
||||
<div>
|
||||
<div
|
||||
class='w-full max-w-sm mx-auto overflow-hidden bg-white rounded-lg shadow-md dark:bg-gray-800'
|
||||
>
|
||||
<div class='px-6 py-4'>
|
||||
<h2 class='text-3xl font-bold text-center text-gray-700 dark:text-white'>ImNote</h2>
|
||||
|
||||
<h3 class='mt-1 text-xl font-medium text-center text-gray-600 dark:text-gray-200'>
|
||||
Nice to meet you!
|
||||
</h3>
|
||||
|
||||
<p class='mt-1 text-center text-gray-500 dark:text-gray-400'>Create account</p>
|
||||
|
||||
<form use:form>
|
||||
<div class='w-full mt-4'>
|
||||
<div class='dark:bg-gray-800 bg-white p-4 rounded-lg'>
|
||||
<div class='relative bg-inherit w-full'>
|
||||
<input
|
||||
id='email'
|
||||
name='email'
|
||||
type='email'
|
||||
class='w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600'
|
||||
placeholder='Email'
|
||||
class:ring-red-700={$errors.email !== null}
|
||||
class:ring-green-600={$touched.email === true &&
|
||||
$errors.email === null}
|
||||
/>
|
||||
<label
|
||||
for='email'
|
||||
class='absolute cursor-text left-0 -top-3 text-sm text-gray-700 dark:text-white bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all'
|
||||
>
|
||||
Email
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class='dark:bg-gray-800 bg-white p-4 rounded-lg'>
|
||||
<div class='relative bg-inherit w-full'>
|
||||
<input
|
||||
id='username'
|
||||
name='username'
|
||||
type='text'
|
||||
class='w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600'
|
||||
placeholder='Username'
|
||||
class:ring-red-700={$errors.username !== null}
|
||||
class:ring-green-600={$touched.username === true &&
|
||||
$errors.username === null}
|
||||
/>
|
||||
<label
|
||||
for='username'
|
||||
class='absolute cursor-text left-0 -top-3 text-sm text-gray-700 dark:text-white bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all'
|
||||
>
|
||||
Username
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class='dark:bg-gray-800 bg-white p-4 rounded-lg'>
|
||||
<div class='relative bg-inherit w-full'>
|
||||
<input
|
||||
id='password1'
|
||||
name='password1'
|
||||
type='password'
|
||||
class:ring-red-700={$errors.password1 !== null}
|
||||
class:ring-green-600={$touched.password1 === true &&
|
||||
$errors.password1 === null}
|
||||
class='w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600'
|
||||
placeholder='Password'
|
||||
/>
|
||||
<label
|
||||
for='password1'
|
||||
class='absolute cursor-text left-0 -top-3 text-sm text-gray-500 bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all'
|
||||
>
|
||||
Password
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class='dark:bg-gray-800 bg-white p-4 rounded-lg'>
|
||||
<div class='relative bg-inherit w-full'>
|
||||
<input
|
||||
id='password2'
|
||||
name='password2'
|
||||
type='password'
|
||||
class='w-full peer bg-transparent h-10 rounded-lg text-gray-700 dark:text-white placeholder-transparent ring-2 px-2 ring-gray-500 focus:ring-sky-600 focus:outline-none focus:border-rose-600'
|
||||
placeholder='Password'
|
||||
class:ring-red-700={$errors.password2 !== null}
|
||||
class:ring-green-600={$touched.password2 === true &&
|
||||
$errors.password2 === null}
|
||||
/>
|
||||
<label
|
||||
for='password2'
|
||||
class='absolute cursor-text left-0 -top-3 text-sm text-gray-500 bg-inherit mx-1 px-1 peer-placeholder-shown:text-base peer-placeholder-shown:text-gray-500 peer-placeholder-shown:top-2 peer-focus:-top-3 peer-focus:text-sky-600 peer-focus:text-sm transition-all'
|
||||
>
|
||||
Password
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='flex items-center justify-between mt-4'>
|
||||
<a
|
||||
href='/account/reset-password'
|
||||
class='text-sm text-gray-600 dark:text-gray-200 hover:text-gray-500'
|
||||
>Forgot Password?</a
|
||||
>
|
||||
|
||||
<button
|
||||
class='px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded hover:bg-gray-600 focus:outline-none'
|
||||
disabled={!$isValid || $isSubmitting}
|
||||
class:cursor-not-allowed={!$isValid || $isSubmitting}
|
||||
class:opacity-50={!$isValid || $isSubmitting}
|
||||
type='submit'
|
||||
>
|
||||
{#if $isSubmitting}
|
||||
<svg class='h-4 w-4 animate-spin' viewBox='3 3 18 18'>
|
||||
<path
|
||||
class='fill-blue-800'
|
||||
d='M12 5C8.13401 5 5 8.13401 5 12C5 15.866 8.13401 19 12 19C15.866 19 19 15.866 19 12C19 8.13401 15.866 5 12 5ZM3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12Z'
|
||||
/>
|
||||
<path
|
||||
class='fill-blue-100'
|
||||
d='M16.9497 7.05015C14.2161 4.31648 9.78392 4.31648 7.05025 7.05015C6.65973 7.44067 6.02656 7.44067 5.63604 7.05015C5.24551 6.65962 5.24551 6.02646 5.63604 5.63593C9.15076 2.12121 14.8492 2.12121 18.364 5.63593C18.7545 6.02646 18.7545 6.65962 18.364 7.05015C17.9734 7.44067 17.3403 7.44067 16.9497 7.05015Z'
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
Register
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class='flex items-center justify-center py-4 text-center bg-gray-50 dark:bg-gray-700'
|
||||
>
|
||||
<span class='text-sm text-gray-600 dark:text-gray-200'
|
||||
>Already have an account?
|
||||
</span>
|
||||
|
||||
<a
|
||||
href='/account/login'
|
||||
class='mx-2 text-sm font-bold text-blue-500 dark:text-blue-400 hover:underline'
|
||||
>Login</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class='fixed z-10 inset-0 overflow-y-auto'
|
||||
aria-labelledby='modal-title'
|
||||
role='dialog'
|
||||
aria-modal='true'
|
||||
class:hidden={!responseData.open}
|
||||
>
|
||||
<div
|
||||
class='flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0'
|
||||
>
|
||||
<!--
|
||||
Background overlay, show/hide based on modal state.
|
||||
|
||||
Entering: "ease-out duration-300"
|
||||
From: "opacity-0"
|
||||
To: "opacity-100"
|
||||
Leaving: "ease-in duration-200"
|
||||
From: "opacity-100"
|
||||
To: "opacity-0"
|
||||
-->
|
||||
<div
|
||||
class='fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity'
|
||||
aria-hidden='true'
|
||||
/>
|
||||
|
||||
<!-- This element is to trick the browser into centering the modal contents. -->
|
||||
<span class='hidden sm:inline-block sm:align-middle sm:h-screen' aria-hidden='true'
|
||||
>​</span
|
||||
>
|
||||
|
||||
<!--
|
||||
Modal panel, show/hide based on modal state.
|
||||
|
||||
Entering: "ease-out duration-300"
|
||||
From: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
To: "opacity-100 translate-y-0 sm:scale-100"
|
||||
Leaving: "ease-in duration-200"
|
||||
From: "opacity-100 translate-y-0 sm:scale-100"
|
||||
To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
-->
|
||||
<div
|
||||
class='inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full'
|
||||
>
|
||||
<div class='bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4'>
|
||||
<div class='sm:flex sm:items-start'>
|
||||
<div
|
||||
class='mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10'
|
||||
>
|
||||
<!-- Heroicon name: outline/exclamation -->
|
||||
{#if responseData.data === '409' || responseData.data === 'error' || responseData.data === '400'}
|
||||
<svg
|
||||
class='h-6 w-6 text-red-600'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
fill='none'
|
||||
viewBox='0 0 24 24'
|
||||
stroke='currentColor'
|
||||
aria-hidden='true'
|
||||
>
|
||||
<path
|
||||
stroke-linecap='round'
|
||||
stroke-linejoin='round'
|
||||
stroke-width='2'
|
||||
d='M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z'
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg
|
||||
class='w-6 h-6 text-green-600'
|
||||
fill='none'
|
||||
stroke='currentColor'
|
||||
viewBox='0 0 24 24'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
>
|
||||
<path
|
||||
stroke-linecap='round'
|
||||
stroke-linejoin='round'
|
||||
stroke-width='2'
|
||||
d='M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z'
|
||||
/>
|
||||
</svg
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
<div class='mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left'>
|
||||
<h3 class='text-lg leading-6 font-medium text-gray-900' id='modal-title'>
|
||||
{#if responseData.data === '409'}
|
||||
Account already exists!
|
||||
{:else if responseData.data === 'error'}
|
||||
Unexpected error!
|
||||
{:else if responseData.data === '200'}
|
||||
Sign up successfully!
|
||||
{:else if responseData.data === '400'}
|
||||
Wrong email!
|
||||
{:else}
|
||||
You stupid Mawoka!
|
||||
{/if}
|
||||
</h3>
|
||||
<div class='mt-2'>
|
||||
<p class='text-sm text-gray-500'>
|
||||
{#if responseData.data === '200'}
|
||||
You signed up successfully! Please check your mailbox to confirm
|
||||
your email address!
|
||||
{:else if responseData.data === '409'}
|
||||
An account with that email-address already exists!
|
||||
{:else if responseData.data === '400'}
|
||||
This email-address doesn't exist!
|
||||
{:else if responseData.data === 'error'}
|
||||
There was the good old unexpected error!
|
||||
{:else}
|
||||
You stupid Mawoka!
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse'>
|
||||
<button
|
||||
type='button'
|
||||
on:click={() => {
|
||||
responseData.open = false;
|
||||
}}
|
||||
class='mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm'
|
||||
>Close
|
||||
</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user