add site key form

This commit is contained in:
realaravinth
2021-05-03 20:24:03 +05:30
parent 0531a26274
commit 812b0ff2c9
49 changed files with 1253 additions and 597 deletions

View File

@@ -1,3 +1,20 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
@import '../reset';
@import '../vars';

View File

@@ -12,6 +12,7 @@
type="text"
name="username"
required=""
autofocus="true"
/>
</label>
@@ -30,9 +31,7 @@
>
-->
</label>
<button class="form__submit-button" type="submit">
Submit
</button>
<input type="submit" class="form__submit-button" value="Sign in" />
</form>
<div class="form__secondary-action">
<p class="form__secondary-action__banner">

View File

@@ -15,51 +15,51 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../api/v1/routes';
import VIEWS from '../../views/v1/routes';
import isBlankString from '../../utils/isBlankString';
import genJsonPayload from '../../utils/genJsonPayload';
import getFormUrl from '../../utils/getFormUrl';
//import '../forms.scss';
const login = (e: Event) => {
const login = async (e: Event) => {
e.preventDefault();
InputEvent
const usernameElement: HTMLInputElement = <HTMLInputElement>document.getElementById('username');
const usernameElement = <HTMLInputElement>document.getElementById('username');
if (usernameElement === null) {
console.debug("Username element is null");
console.debug('Username element is null');
return;
}
let username = usernameElement.value;
isBlankString(e, username, 'username');
// isBlankString(e);//, username, 'username');
const username = usernameElement.value;
isBlankString(username, 'username', e);
const passwordElement: HTMLInputElement = <HTMLInputElement>document.getElementById('password');
const passwordElement = <HTMLInputElement>document.getElementById('password');
if (passwordElement === null) {
console.debug("Password is null");
console.debug('Password is null');
return;
}
let password = passwordElement.value;
const password = passwordElement.value;
let payload = {
const payload = {
username,
password,
};
fetch(ROUTES.loginUser, genJsonPayload(payload)).then(res => {
if (res.ok) {
alert('success');
window.location.assign(VIEWS.panelHome);
} else {
res.json().then(err => alert(`error: ${err.error}`));
}
});
const formUrl = getFormUrl(null);
const res = await fetch(formUrl, genJsonPayload(payload));
if (res.ok) {
alert('success');
window.location.assign(VIEWS.panelHome);
} else {
const err = await res.json();
alert(`error: ${err.error}`);
}
};
export const index = () => {
let form = <HTMLFontElement>document.getElementById('form');
const form = <HTMLFontElement>document.getElementById('form');
form.addEventListener('submit', login, true);
};

View File

@@ -3,7 +3,7 @@
<img src="<.= crate::FILES.get("./static-assets/img/icon-trans.png").unwrap().>" class="form__logo" alt="" />
<h2 class="form__brand">Join mCaptcha</h2>
<form method="POST" action="<.= crate::V1_API_ROUTES.auth.register .> class="form__box" id="form">
<form method="POST" action="<.= crate::V1_API_ROUTES.auth.register .>" class="form__box" id="form">
<label class="form__in-group" for="username"
>Username
<input
@@ -13,6 +13,7 @@
name="username"
id="username"
required
autofocus="true"
/>
</label>
@@ -50,9 +51,7 @@
required
/>
</label>
<button class="form__submit-button" type="submit">
Submit
</button>
<input type="submit" class="form__submit-button" value="Sign up" />
</form>
<div class="form__secondary-action">
<p class="form__secondary-action__banner">

View File

@@ -15,7 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../api/v1/routes';
import VIEWS from '../../views/v1/routes';
import isBlankString from '../../utils/isBlankString';
@@ -23,6 +22,7 @@ import genJsonPayload from '../../utils/genJsonPayload';
import userExists from './userExists';
import {checkEmailExists} from './emailExists';
import getFormUrl from '../../utils/getFormUrl';
//import '../forms.scss';
@@ -33,15 +33,15 @@ const passwordElement = <HTMLInputElement>document.getElementById('password');
const registerUser = async (e: Event) => {
e.preventDefault();
let username = usernameElement.value;
isBlankString(e, username, 'username');
const username = usernameElement.value;
isBlankString(username, 'username', e);
//isBlankString(e);//, username, 'username');
let password = passwordElement.value;
const password = passwordElement.value;
const passwordCheckElement = <HTMLInputElement>(
document.getElementById('password-check')
);
let passwordCheck = passwordCheckElement.value;
const passwordCheck = passwordCheckElement.value;
if (password != passwordCheck) {
return alert("passwords don't match, check again!");
}
@@ -61,25 +61,26 @@ const registerUser = async (e: Event) => {
}
}
let payload = {
const payload = {
username,
password,
confirm_password: passwordCheck,
email,
};
const formUrl = getFormUrl(null);
let res = await fetch(ROUTES.registerUser, genJsonPayload(payload));
const res = await fetch(formUrl, genJsonPayload(payload));
if (res.ok) {
alert('success');
window.location.assign(VIEWS.loginUser);
} else {
let err = await res.json();
const err = await res.json();
alert(`error: ${err.error}`);
}
};
export const index = () => {
let form = <HTMLFontElement>document.getElementById('form');
const form = <HTMLFontElement>document.getElementById('form');
form.addEventListener('submit', registerUser, true);
usernameElement.addEventListener('input', userExists, false);
};