fixed registering
This commit is contained in:
parent
7556bec04d
commit
8a0cf95fde
2 changed files with 7 additions and 7 deletions
|
@ -19,7 +19,7 @@
|
||||||
</script>
|
</script>
|
||||||
<div class="content-main form">
|
<div class="content-main form">
|
||||||
<div>
|
<div>
|
||||||
{#if form?.success == 'login'}
|
{#if form == 'login'}
|
||||||
<p><i>Account successfully created. <a href='/login'>Log into an account to use it.</a></i></p>
|
<p><i>Account successfully created. <a href='/login'>Log into an account to use it.</a></i></p>
|
||||||
{:else if form == 'exists'}
|
{:else if form == 'exists'}
|
||||||
<p><i>Account already exists.</i></p>
|
<p><i>Account already exists.</i></p>
|
||||||
|
|
|
@ -18,9 +18,9 @@ export async function POST(event) {
|
||||||
|
|
||||||
if (rows.length == 0) {
|
if (rows.length == 0) {
|
||||||
var state = await register(data);
|
var state = await register(data);
|
||||||
return {success: state};
|
return state;
|
||||||
} else {
|
} else {
|
||||||
return {success: 'exists'};
|
return new Response('exists');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@ async function register(data) {
|
||||||
var email = data.get("email");
|
var email = data.get("email");
|
||||||
var password = data.get("password");
|
var password = data.get("password");
|
||||||
|
|
||||||
if (!password || !email || !user) return 'missing';
|
if (!password || !email || !user) return new Response('missing');
|
||||||
if (password.length > 256 || email.length > 64 || user.length > 32) return 'long';
|
if (password.length > 256 || email.length > 64 || user.length > 32) return new Response('long');
|
||||||
|
|
||||||
const userTest = new RegExp("^[A-Za-z0-9_-]+$");
|
const userTest = new RegExp("^[A-Za-z0-9_-]+$");
|
||||||
if (!userTest.test(user)) return 'invalid';
|
if (!userTest.test(user)) return new Response('invalid');
|
||||||
|
|
||||||
var passHash = await hash(password,saltRounds);
|
var passHash = await hash(password,saltRounds);
|
||||||
|
|
||||||
|
@ -42,5 +42,5 @@ async function register(data) {
|
||||||
[user,email,passHash]
|
[user,email,passHash]
|
||||||
);
|
);
|
||||||
|
|
||||||
return 'login';
|
return new Response('login');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue