implement date of birth
This commit is contained in:
parent
54255cc118
commit
d2206ff547
|
|
@ -17,6 +17,7 @@
|
||||||
"@hcaptcha/types": "^1.0.3",
|
"@hcaptcha/types": "^1.0.3",
|
||||||
"@popperjs/core": "^2.11.8",
|
"@popperjs/core": "^2.11.8",
|
||||||
"bootstrap": "^5.3.2",
|
"bootstrap": "^5.3.2",
|
||||||
|
"dayjs": "^1.11.10",
|
||||||
"nanoevents": "^7.0.1",
|
"nanoevents": "^7.0.1",
|
||||||
"simple-keyboard": "^3.7.53"
|
"simple-keyboard": "^3.7.53"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,8 @@
|
||||||
<input id="accountRegisterPassword" type="password" class="form-control bg-dark text-light" placeholder="Password" name="password" required><br>
|
<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/>
|
<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>
|
<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>
|
<div id="accountRegisterCaptcha"></div>
|
||||||
<button type="submit" class="btn btn-primary">Register</button>
|
<button type="submit" class="btn btn-primary">Register</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import * as dayjs from 'dayjs';
|
||||||
|
|
||||||
export default class AuthManager {
|
export default class AuthManager {
|
||||||
apiEndpoint : string;
|
apiEndpoint : string;
|
||||||
info : AuthServerInformation | null;
|
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) => {
|
return new Promise(async (res, rej) => {
|
||||||
if (!this.info) throw new Error("Cannot login before fetching API information.");
|
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.");
|
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,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
email: email,
|
email: email,
|
||||||
|
dateOfBirth: dateOfBirth.format("YYYY-MM-DD"),
|
||||||
captchatoken: captchaToken
|
captchatoken: captchaToken
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { Unsubscribe } from 'nanoevents';
|
||||||
import { I18nStringKey, TheI18n } from './i18n.js';
|
import { I18nStringKey, TheI18n } from './i18n.js';
|
||||||
import { Format } from './format.js';
|
import { Format } from './format.js';
|
||||||
import AuthManager from './AuthManager.js';
|
import AuthManager from './AuthManager.js';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
// Elements
|
// Elements
|
||||||
const w = window as any;
|
const w = window as any;
|
||||||
|
|
@ -95,6 +96,7 @@ const elements = {
|
||||||
accountRegisterUsername: document.getElementById("accountRegisterUsername") as HTMLInputElement,
|
accountRegisterUsername: document.getElementById("accountRegisterUsername") as HTMLInputElement,
|
||||||
accountRegisterPassword: document.getElementById("accountRegisterPassword") as HTMLInputElement,
|
accountRegisterPassword: document.getElementById("accountRegisterPassword") as HTMLInputElement,
|
||||||
accountRegisterConfirmPassword: document.getElementById("accountRegisterConfirmPassword") as HTMLInputElement,
|
accountRegisterConfirmPassword: document.getElementById("accountRegisterConfirmPassword") as HTMLInputElement,
|
||||||
|
accountRegisterDateOfBirth: document.getElementById("accountRegisterDateOfBirth") as HTMLInputElement,
|
||||||
accountVerifyEmailCode: document.getElementById("accountVerifyEmailCode") as HTMLInputElement,
|
accountVerifyEmailCode: document.getElementById("accountVerifyEmailCode") as HTMLInputElement,
|
||||||
accountVerifyEmailPassword: document.getElementById("accountVerifyEmailPassword") as HTMLInputElement,
|
accountVerifyEmailPassword: document.getElementById("accountVerifyEmailPassword") as HTMLInputElement,
|
||||||
|
|
||||||
|
|
@ -993,18 +995,20 @@ elements.accountRegisterForm.addEventListener('submit', async (e) => {
|
||||||
var username = elements.accountRegisterUsername.value;
|
var username = elements.accountRegisterUsername.value;
|
||||||
var password = elements.accountRegisterPassword.value;
|
var password = elements.accountRegisterPassword.value;
|
||||||
var email = elements.accountRegisterEmail.value;
|
var email = elements.accountRegisterEmail.value;
|
||||||
|
var dob = dayjs(elements.accountRegisterDateOfBirth.valueAsDate);
|
||||||
if (password !== elements.accountRegisterConfirmPassword.value) {
|
if (password !== elements.accountRegisterConfirmPassword.value) {
|
||||||
elements.accountModalErrorText.innerHTML = TheI18n.GetString(I18nStringKey.kPasswordsMustMatch);
|
elements.accountModalErrorText.innerHTML = TheI18n.GetString(I18nStringKey.kPasswordsMustMatch);
|
||||||
elements.accountModalError.style.display = "block";
|
elements.accountModalError.style.display = "block";
|
||||||
return false;
|
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 (auth!.info!.hcaptcha.required) hcaptcha.reset(hcaptchaID);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
elements.accountRegisterUsername.value = "";
|
elements.accountRegisterUsername.value = "";
|
||||||
elements.accountRegisterEmail.value = "";
|
elements.accountRegisterEmail.value = "";
|
||||||
elements.accountRegisterPassword.value = "";
|
elements.accountRegisterPassword.value = "";
|
||||||
elements.accountRegisterConfirmPassword.value = "";
|
elements.accountRegisterConfirmPassword.value = "";
|
||||||
|
elements.accountRegisterDateOfBirth.value = "";
|
||||||
if (result.verificationRequired) {
|
if (result.verificationRequired) {
|
||||||
accountBeingVerified = result.username;
|
accountBeingVerified = result.username;
|
||||||
elements.accountVerifyEmailText.innerText = TheI18n.GetString(I18nStringKey.kAccountModal_VerifyText, result.email!);
|
elements.accountVerifyEmailText.innerText = TheI18n.GetString(I18nStringKey.kAccountModal_VerifyText, result.email!);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user