From d73ff6692a5a67cc0d6e341ac884ac2050172e78 Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Tue, 21 Nov 2023 19:23:51 +0100 Subject: [PATCH] Adding semi-opaque overlay to avoid interation with the app without login. --- js-src/conquer/login.ts | 13 ++++++++++++- public/css/styles.css | 10 ++++++++++ public/css/styles.scss | 4 ++++ public/js/bundle.js | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/js-src/conquer/login.ts b/js-src/conquer/login.ts index 6dbb65c..075a0a9 100644 --- a/js-src/conquer/login.ts +++ b/js-src/conquer/login.ts @@ -16,14 +16,23 @@ export default class Login { private conquerRegisterRepeatPassword: HTMLInputElement private conquerRegisterSubmit: HTMLButtonElement private conquerRegisterError: HTMLParagraphElement - + private conquerOverlayTransparent: HTMLDivElement public async enableLogIfNeeded() { + this.fillOverlay() this.fillConquerLogin() this.fillConquerRegister() this.checkLogin() } + private async fillOverlay() { + const conquerOverlayTransparent = document.querySelector('.conquer-overlay-transparent') + if (conquerOverlayTransparent === null || !(conquerOverlayTransparent instanceof HTMLDivElement)) { + Conquer.fail('No overlay found') + } + this.conquerOverlayTransparent = conquerOverlayTransparent + } + private async fillConquerLogin() { const conquerLogin = document.querySelector('.conquer-login') if (conquerLogin === null || !(conquerLogin instanceof HTMLDivElement)) { @@ -168,6 +177,7 @@ export default class Login { this.conquerRegisterError.classList.remove('conquer-display-none') } private async removeLoginRegisterCombo(): Promise { + this.conquerOverlayTransparent.classList.add('conquer-display-none') this.conquerLogin.classList.add('conquer-display-none') this.conquerRegister.classList.add('conquer-display-none') } @@ -176,6 +186,7 @@ export default class Login { const isLogged = await this.isLogged() if (!isLogged) { this.conquerLogin.classList.remove('conquer-display-none') + this.conquerOverlayTransparent.classList.remove('conquer-display-none') return } this.onLoginSuccess() diff --git a/public/css/styles.css b/public/css/styles.css index cee0294..a27a7d4 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -18,7 +18,17 @@ body { border: solid 1px black; } body p.conquer-login-success { color: green; } + body div.conquer-overlay-transparent { + background: black; + opacity: 50%; + width: 100%; + height: 100%; + position: fixed; + top: 0; + left: 0; + z-index: 1; } body div.conquer-login, body div.conquer-register { + border: 1px solid black; position: fixed; color: black; font-size: 1.5rem; diff --git a/public/css/styles.scss b/public/css/styles.scss index cb67827..149ff13 100644 --- a/public/css/styles.scss +++ b/public/css/styles.scss @@ -29,11 +29,14 @@ body { color: green; } div.conquer-overlay-transparent { + background: black; + opacity: 50%; width: 100%; height: 100%; position: fixed; top: 0; left: 0; + z-index: 1; } div.conquer-login,div.conquer-register { form { @@ -43,6 +46,7 @@ body { flex-direction: column; justify-content: center; } + border: 1px solid black; position: fixed; color: black; font-size: 1.5rem; diff --git a/public/js/bundle.js b/public/js/bundle.js index c551269..af3d6cb 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -68,7 +68,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Login)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\n\nclass Login {\n constructor() {\n this.callbacks = {};\n }\n async enableLogIfNeeded() {\n this.fillConquerLogin();\n this.fillConquerRegister();\n this.checkLogin();\n }\n async fillConquerLogin() {\n const conquerLogin = document.querySelector('.conquer-login');\n if (conquerLogin === null || !(conquerLogin instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('conquerLogin is invalid');\n }\n this.conquerLogin = conquerLogin;\n const conquerLoginGoToRegister = document.querySelector('.conquer-login-go-to-register');\n if (conquerLoginGoToRegister === null || !(conquerLoginGoToRegister instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to register from login is invalid.');\n }\n this.conquerLoginGoToRegister = conquerLoginGoToRegister;\n this.conquerLoginGoToRegister.addEventListener('click', () => {\n this.goToRegister();\n });\n const conquerLoginError = document.querySelector('.conquer-login-error');\n if (conquerLoginError === null || !(conquerLoginError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login error.');\n }\n this.conquerLoginError = conquerLoginError;\n const conquerLoginSuccess = document.querySelector('.conquer-login-success');\n if (conquerLoginSuccess === null || !(conquerLoginSuccess instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login success.');\n }\n this.conquerLoginSuccess = conquerLoginSuccess;\n const conquerLoginUsername = document.querySelector('.conquer-login-username');\n if (conquerLoginUsername === null || !(conquerLoginUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login username field.');\n }\n this.conquerLoginUsername = conquerLoginUsername;\n const conquerLoginPassword = document.querySelector('.conquer-login-password');\n if (conquerLoginPassword === null || !(conquerLoginPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login password field.');\n }\n this.conquerLoginPassword = conquerLoginPassword;\n const conquerLoginSubmit = document.querySelector('.conquer-login-submit');\n if (conquerLoginSubmit === null || !(conquerLoginSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the submit button for the login.');\n }\n this.conquerLoginSubmit = conquerLoginSubmit;\n this.conquerLoginSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n this.onLoginRequested();\n });\n }\n async fillConquerRegister() {\n const conquerRegister = document.querySelector('.conquer-register');\n if (conquerRegister === null || !(conquerRegister instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('conquerRegister is invalid');\n }\n this.conquerRegister = conquerRegister;\n const conquerRegisterGoToLogin = document.querySelector('.conquer-register-go-to-login');\n if (conquerRegisterGoToLogin === null || !(conquerRegisterGoToLogin instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to login from register is invalid.');\n }\n this.conquerRegisterGoToLogin = conquerRegisterGoToLogin;\n this.conquerRegisterGoToLogin.addEventListener('click', () => {\n this.goToLogin();\n });\n const conquerRegisterUsername = document.querySelector('.conquer-register-username');\n if (conquerRegisterUsername === null || !(conquerRegisterUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No username field in conquer register.');\n }\n this.conquerRegisterUsername = conquerRegisterUsername;\n const conquerRegisterPassword = document.querySelector('.conquer-register-password');\n if (conquerRegisterPassword === null || !(conquerRegisterPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No password field in conquer register.');\n }\n this.conquerRegisterPassword = conquerRegisterPassword;\n const conquerRegisterRepeatPassword = document.querySelector('.conquer-register-repeat-password');\n if (conquerRegisterRepeatPassword === null || !(conquerRegisterRepeatPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No repeat password field in conquer register.');\n }\n this.conquerRegisterRepeatPassword = conquerRegisterRepeatPassword;\n const conquerRegisterSubmit = document.querySelector('.conquer-register-submit');\n if (conquerRegisterSubmit === null || !(conquerRegisterSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No register submit button found.');\n }\n this.conquerRegisterSubmit = conquerRegisterSubmit;\n this.conquerRegisterSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n this.onRegisterRequest();\n });\n const conquerRegisterError = document.querySelector('.conquer-register-error');\n if (conquerRegisterError === null || !(conquerRegisterError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the conquer error element.');\n }\n this.conquerRegisterError = conquerRegisterError;\n }\n async unsetLoginAndRegisterErrors() {\n this.conquerRegisterError.classList.add('conquer-display-none');\n this.conquerLoginError.classList.add('conquer-display-none');\n }\n async onRegisterRequest() {\n const username = this.conquerRegisterUsername.value;\n const password = this.conquerRegisterPassword.value;\n const repeatPassword = this.conquerRegisterRepeatPassword.value;\n const urlUser = new URL('/conquer/user', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let responseJson;\n let status;\n try {\n const response = await fetch(urlUser, {\n method: 'PUT',\n body: JSON.stringify({\n username: username,\n password: password,\n repeat_password: repeatPassword\n })\n });\n responseJson = await response.json();\n status = response.status;\n }\n catch (e) {\n console.error(e);\n this.addNewRegisterError('El servidor ha enviado datos inesperados.');\n return;\n }\n if (status !== 200) {\n this.addNewRegisterError(responseJson.error);\n return;\n }\n this.addNewLoginSuccessText(`Usuario registrado ${username}.`);\n this.goToLogin();\n }\n async addNewLoginSuccessText(message) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.innerText = message;\n this.conquerLoginSuccess.classList.remove('conquer-display-none');\n }\n async addNewLoginError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerLoginError.innerText = error;\n this.conquerLoginError.classList.remove('conquer-display-none');\n }\n async addNewRegisterError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerRegisterError.innerText = error;\n this.conquerRegisterError.classList.remove('conquer-display-none');\n }\n async removeLoginRegisterCombo() {\n this.conquerLogin.classList.add('conquer-display-none');\n this.conquerRegister.classList.add('conquer-display-none');\n }\n async checkLogin() {\n const isLogged = await this.isLogged();\n if (!isLogged) {\n this.conquerLogin.classList.remove('conquer-display-none');\n return;\n }\n this.onLoginSuccess();\n }\n async on(name, callback) {\n if (this.callbacks[name] === undefined) {\n this.callbacks[name] = [];\n this.callbacks[name].push(callback);\n }\n }\n async onLoginSuccess() {\n await this.removeLoginRegisterCombo();\n for (const callback of this.callbacks.login) {\n callback();\n }\n }\n async goToRegister() {\n const isLogged = await this.isLogged();\n await this.removeLoginRegisterCombo();\n if (!isLogged) {\n this.conquerRegister.classList.remove('conquer-display-none');\n }\n else {\n this.onLoginSuccess();\n }\n }\n async goToLogin() {\n const isLogged = await this.isLogged();\n await this.removeLoginRegisterCombo();\n if (!isLogged) {\n this.conquerLogin.classList.remove('conquer-display-none');\n }\n else {\n this.onLoginSuccess();\n }\n }\n async onLoginRequested() {\n const username = this.conquerLoginUsername.value;\n const password = this.conquerLoginPassword.value;\n const urlUser = new URL('/conquer/user/login', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let responseJson;\n let status;\n try {\n const response = await fetch(urlUser, {\n method: 'POST',\n body: JSON.stringify({\n username: username,\n password: password,\n })\n });\n responseJson = await response.json();\n status = response.status;\n }\n catch (e) {\n console.error(e);\n this.addNewLoginError('El servidor ha enviado datos inesperados.');\n return;\n }\n if (status !== 200) {\n this.addNewLoginError(responseJson.error);\n return;\n }\n this.unsetLoginAndRegisterErrors();\n const isLogged = await this.isLogged();\n if (isLogged) {\n this.onLoginSuccess();\n }\n }\n async addNewLoginRegisterError(message) {\n this.addNewRegisterError(message);\n this.addNewLoginError(message);\n }\n async isLogged() {\n const urlUser = new URL('/conquer/user', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let status;\n try {\n const response = await fetch(urlUser);\n status = response.status;\n }\n catch {\n this.addNewLoginRegisterError('Error del servidor');\n return false;\n }\n return status === 200;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/login.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Login)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\n\nclass Login {\n constructor() {\n this.callbacks = {};\n }\n async enableLogIfNeeded() {\n this.fillOverlay();\n this.fillConquerLogin();\n this.fillConquerRegister();\n this.checkLogin();\n }\n async fillOverlay() {\n const conquerOverlayTransparent = document.querySelector('.conquer-overlay-transparent');\n if (conquerOverlayTransparent === null || !(conquerOverlayTransparent instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No overlay found');\n }\n this.conquerOverlayTransparent = conquerOverlayTransparent;\n }\n async fillConquerLogin() {\n const conquerLogin = document.querySelector('.conquer-login');\n if (conquerLogin === null || !(conquerLogin instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('conquerLogin is invalid');\n }\n this.conquerLogin = conquerLogin;\n const conquerLoginGoToRegister = document.querySelector('.conquer-login-go-to-register');\n if (conquerLoginGoToRegister === null || !(conquerLoginGoToRegister instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to register from login is invalid.');\n }\n this.conquerLoginGoToRegister = conquerLoginGoToRegister;\n this.conquerLoginGoToRegister.addEventListener('click', () => {\n this.goToRegister();\n });\n const conquerLoginError = document.querySelector('.conquer-login-error');\n if (conquerLoginError === null || !(conquerLoginError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login error.');\n }\n this.conquerLoginError = conquerLoginError;\n const conquerLoginSuccess = document.querySelector('.conquer-login-success');\n if (conquerLoginSuccess === null || !(conquerLoginSuccess instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login success.');\n }\n this.conquerLoginSuccess = conquerLoginSuccess;\n const conquerLoginUsername = document.querySelector('.conquer-login-username');\n if (conquerLoginUsername === null || !(conquerLoginUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login username field.');\n }\n this.conquerLoginUsername = conquerLoginUsername;\n const conquerLoginPassword = document.querySelector('.conquer-login-password');\n if (conquerLoginPassword === null || !(conquerLoginPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login password field.');\n }\n this.conquerLoginPassword = conquerLoginPassword;\n const conquerLoginSubmit = document.querySelector('.conquer-login-submit');\n if (conquerLoginSubmit === null || !(conquerLoginSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the submit button for the login.');\n }\n this.conquerLoginSubmit = conquerLoginSubmit;\n this.conquerLoginSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n this.onLoginRequested();\n });\n }\n async fillConquerRegister() {\n const conquerRegister = document.querySelector('.conquer-register');\n if (conquerRegister === null || !(conquerRegister instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('conquerRegister is invalid');\n }\n this.conquerRegister = conquerRegister;\n const conquerRegisterGoToLogin = document.querySelector('.conquer-register-go-to-login');\n if (conquerRegisterGoToLogin === null || !(conquerRegisterGoToLogin instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to login from register is invalid.');\n }\n this.conquerRegisterGoToLogin = conquerRegisterGoToLogin;\n this.conquerRegisterGoToLogin.addEventListener('click', () => {\n this.goToLogin();\n });\n const conquerRegisterUsername = document.querySelector('.conquer-register-username');\n if (conquerRegisterUsername === null || !(conquerRegisterUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No username field in conquer register.');\n }\n this.conquerRegisterUsername = conquerRegisterUsername;\n const conquerRegisterPassword = document.querySelector('.conquer-register-password');\n if (conquerRegisterPassword === null || !(conquerRegisterPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No password field in conquer register.');\n }\n this.conquerRegisterPassword = conquerRegisterPassword;\n const conquerRegisterRepeatPassword = document.querySelector('.conquer-register-repeat-password');\n if (conquerRegisterRepeatPassword === null || !(conquerRegisterRepeatPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No repeat password field in conquer register.');\n }\n this.conquerRegisterRepeatPassword = conquerRegisterRepeatPassword;\n const conquerRegisterSubmit = document.querySelector('.conquer-register-submit');\n if (conquerRegisterSubmit === null || !(conquerRegisterSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No register submit button found.');\n }\n this.conquerRegisterSubmit = conquerRegisterSubmit;\n this.conquerRegisterSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n this.onRegisterRequest();\n });\n const conquerRegisterError = document.querySelector('.conquer-register-error');\n if (conquerRegisterError === null || !(conquerRegisterError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the conquer error element.');\n }\n this.conquerRegisterError = conquerRegisterError;\n }\n async unsetLoginAndRegisterErrors() {\n this.conquerRegisterError.classList.add('conquer-display-none');\n this.conquerLoginError.classList.add('conquer-display-none');\n }\n async onRegisterRequest() {\n const username = this.conquerRegisterUsername.value;\n const password = this.conquerRegisterPassword.value;\n const repeatPassword = this.conquerRegisterRepeatPassword.value;\n const urlUser = new URL('/conquer/user', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let responseJson;\n let status;\n try {\n const response = await fetch(urlUser, {\n method: 'PUT',\n body: JSON.stringify({\n username: username,\n password: password,\n repeat_password: repeatPassword\n })\n });\n responseJson = await response.json();\n status = response.status;\n }\n catch (e) {\n console.error(e);\n this.addNewRegisterError('El servidor ha enviado datos inesperados.');\n return;\n }\n if (status !== 200) {\n this.addNewRegisterError(responseJson.error);\n return;\n }\n this.addNewLoginSuccessText(`Usuario registrado ${username}.`);\n this.goToLogin();\n }\n async addNewLoginSuccessText(message) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.innerText = message;\n this.conquerLoginSuccess.classList.remove('conquer-display-none');\n }\n async addNewLoginError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerLoginError.innerText = error;\n this.conquerLoginError.classList.remove('conquer-display-none');\n }\n async addNewRegisterError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerRegisterError.innerText = error;\n this.conquerRegisterError.classList.remove('conquer-display-none');\n }\n async removeLoginRegisterCombo() {\n this.conquerOverlayTransparent.classList.add('conquer-display-none');\n this.conquerLogin.classList.add('conquer-display-none');\n this.conquerRegister.classList.add('conquer-display-none');\n }\n async checkLogin() {\n const isLogged = await this.isLogged();\n if (!isLogged) {\n this.conquerLogin.classList.remove('conquer-display-none');\n this.conquerOverlayTransparent.classList.remove('conquer-display-none');\n return;\n }\n this.onLoginSuccess();\n }\n async on(name, callback) {\n if (this.callbacks[name] === undefined) {\n this.callbacks[name] = [];\n this.callbacks[name].push(callback);\n }\n }\n async onLoginSuccess() {\n await this.removeLoginRegisterCombo();\n for (const callback of this.callbacks.login) {\n callback();\n }\n }\n async goToRegister() {\n const isLogged = await this.isLogged();\n await this.removeLoginRegisterCombo();\n if (!isLogged) {\n this.conquerRegister.classList.remove('conquer-display-none');\n }\n else {\n this.onLoginSuccess();\n }\n }\n async goToLogin() {\n const isLogged = await this.isLogged();\n await this.removeLoginRegisterCombo();\n if (!isLogged) {\n this.conquerLogin.classList.remove('conquer-display-none');\n }\n else {\n this.onLoginSuccess();\n }\n }\n async onLoginRequested() {\n const username = this.conquerLoginUsername.value;\n const password = this.conquerLoginPassword.value;\n const urlUser = new URL('/conquer/user/login', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let responseJson;\n let status;\n try {\n const response = await fetch(urlUser, {\n method: 'POST',\n body: JSON.stringify({\n username: username,\n password: password,\n })\n });\n responseJson = await response.json();\n status = response.status;\n }\n catch (e) {\n console.error(e);\n this.addNewLoginError('El servidor ha enviado datos inesperados.');\n return;\n }\n if (status !== 200) {\n this.addNewLoginError(responseJson.error);\n return;\n }\n this.unsetLoginAndRegisterErrors();\n const isLogged = await this.isLogged();\n if (isLogged) {\n this.onLoginSuccess();\n }\n }\n async addNewLoginRegisterError(message) {\n this.addNewRegisterError(message);\n this.addNewLoginError(message);\n }\n async isLogged() {\n const urlUser = new URL('/conquer/user', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let status;\n try {\n const response = await fetch(urlUser);\n status = response.status;\n }\n catch {\n this.addNewLoginRegisterError('Error del servidor');\n return false;\n }\n return status === 200;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/login.ts?"); /***/ }),