implement date of birth

This commit is contained in:
Elijah R 2024-04-05 17:26:24 -04:00
parent 54255cc118
commit d2206ff547
4 changed files with 12 additions and 2 deletions

View File

@ -17,6 +17,7 @@
"@hcaptcha/types": "^1.0.3",
"@popperjs/core": "^2.11.8",
"bootstrap": "^5.3.2",
"dayjs": "^1.11.10",
"nanoevents": "^7.0.1",
"simple-keyboard": "^3.7.53"
},

View File

@ -129,6 +129,8 @@
<input id="accountRegisterPassword" type="password" class="form-control bg-dark text-light" placeholder="Password" name="password" required><br>
<label for="accountRegisterConfirmPassword">Confirm Password</label><br/>
<input id="accountRegisterConfirmPassword" type="password" class="form-control bg-dark text-light" placeholder="Confirm Password" name="confirmpassword" required><br>
<label for="accountRegisterDateOfBirth">Date of Birth</label><br/>
<input id="accountRegisterDateOfBirth" type="date" class="form-control bg-dark text-light" name="dateofbirth" required><br/>
<div id="accountRegisterCaptcha"></div>
<button type="submit" class="btn btn-primary">Register</button>
</form>

View File

@ -1,3 +1,5 @@
import * as dayjs from 'dayjs';
export default class AuthManager {
apiEndpoint : string;
info : AuthServerInformation | null;
@ -67,7 +69,7 @@ export default class AuthManager {
})
}
register(username : string, password : string, email : string, captchaToken : string | undefined) : Promise<AccountRegisterResult> {
register(username : string, password : string, email : string, dateOfBirth : dayjs.Dayjs, captchaToken : string | undefined) : Promise<AccountRegisterResult> {
return new Promise(async (res, rej) => {
if (!this.info) throw new Error("Cannot login before fetching API information.");
if (!captchaToken && this.info.hcaptcha.required) throw new Error("This API requires a valid hCaptcha token.");
@ -80,6 +82,7 @@ export default class AuthManager {
username: username,
password: password,
email: email,
dateOfBirth: dateOfBirth.format("YYYY-MM-DD"),
captchatoken: captchaToken
})
});

View File

@ -14,6 +14,7 @@ import { Unsubscribe } from 'nanoevents';
import { I18nStringKey, TheI18n } from './i18n.js';
import { Format } from './format.js';
import AuthManager from './AuthManager.js';
import dayjs from 'dayjs';
// Elements
const w = window as any;
@ -95,6 +96,7 @@ const elements = {
accountRegisterUsername: document.getElementById("accountRegisterUsername") as HTMLInputElement,
accountRegisterPassword: document.getElementById("accountRegisterPassword") as HTMLInputElement,
accountRegisterConfirmPassword: document.getElementById("accountRegisterConfirmPassword") as HTMLInputElement,
accountRegisterDateOfBirth: document.getElementById("accountRegisterDateOfBirth") as HTMLInputElement,
accountVerifyEmailCode: document.getElementById("accountVerifyEmailCode") as HTMLInputElement,
accountVerifyEmailPassword: document.getElementById("accountVerifyEmailPassword") as HTMLInputElement,
@ -993,18 +995,20 @@ elements.accountRegisterForm.addEventListener('submit', async (e) => {
var username = elements.accountRegisterUsername.value;
var password = elements.accountRegisterPassword.value;
var email = elements.accountRegisterEmail.value;
var dob = dayjs(elements.accountRegisterDateOfBirth.valueAsDate);
if (password !== elements.accountRegisterConfirmPassword.value) {
elements.accountModalErrorText.innerHTML = TheI18n.GetString(I18nStringKey.kPasswordsMustMatch);
elements.accountModalError.style.display = "block";
return false;
}
var result = await auth!.register(username, password, email, hcaptchaToken);
var result = await auth!.register(username, password, email, dob, hcaptchaToken);
if (auth!.info!.hcaptcha.required) hcaptcha.reset(hcaptchaID);
if (result.success) {
elements.accountRegisterUsername.value = "";
elements.accountRegisterEmail.value = "";
elements.accountRegisterPassword.value = "";
elements.accountRegisterConfirmPassword.value = "";
elements.accountRegisterDateOfBirth.value = "";
if (result.verificationRequired) {
accountBeingVerified = result.username;
elements.accountVerifyEmailText.innerText = TheI18n.GetString(I18nStringKey.kAccountModal_VerifyText, result.email!);