frontend: email optional

This commit is contained in:
realaravinth 2021-04-12 11:21:02 +05:30
parent d32350e2b6
commit 420ff75817
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
3 changed files with 11 additions and 10 deletions

View file

@ -186,7 +186,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"index\", function() { return index; });\n/* harmony import */ var _api_v1_routes__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../api/v1/routes */ \"./templates/api/v1/routes.js\");\n/* harmony import */ var _utils_genJsonPayload__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/genJsonPayload */ \"./templates/utils/genJsonPayload.js\");\n/* harmony import */ var _userExists__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./userExists */ \"./templates/auth/register/userExists.js\");\n/* harmony import */ var _emailExists__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./emailExists */ \"./templates/auth/register/emailExists.js\");\n/* harmony import */ var _forms_scss__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../forms.scss */ \"./templates/auth/forms.scss\");\n/* harmony import */ var _forms_scss__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_forms_scss__WEBPACK_IMPORTED_MODULE_4__);\n\n\n\n\n\n\n\n\n\n\nconst registerUser = async e => {\n e.preventDefault();\n\n let username = document.getElementById('username').value;\n Object(_utils_genJsonPayload__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(e, username, 'username');\n\n let password = document.getElementById('password').value;\n let passwordCheck = document.getElementById('password-check').value;\n if (password != passwordCheck) {\n return alert(\"passwords don't match, check again!\");\n }\n\n let email = document.getElementById('email').value;\n Object(_utils_genJsonPayload__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(e, email, 'email');\n\n let exists = await Object(_userExists__WEBPACK_IMPORTED_MODULE_2__[\"default\"])();\n if (exists) {\n return;\n }\n\n exists = await Object(_emailExists__WEBPACK_IMPORTED_MODULE_3__[\"checkEmailExists\"])();\n if (exists) {\n return;\n }\n\n let payload = {\n username,\n password,\n email,\n };\n\n let res = await fetch(_api_v1_routes__WEBPACK_IMPORTED_MODULE_0__[\"default\"].registerUser, Object(_utils_genJsonPayload__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(payload));\n if (res.ok) {\n alert('success');\n } else {\n let err = await res.json();\n alert(`error: ${err.error}`);\n }\n};\n\nconst index = () => {\n let form = document.getElementById('form');\n form.addEventListener('submit', registerUser, true);\n\n let username = document.getElementById('username');\n username.addEventListener('input', _userExists__WEBPACK_IMPORTED_MODULE_2__[\"default\"], false);\n}\n\n\n//# sourceURL=webpack:///./templates/auth/register/index.js?");
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"index\", function() { return index; });\n/* harmony import */ var _api_v1_routes__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../api/v1/routes */ \"./templates/api/v1/routes.js\");\n/* harmony import */ var _utils_genJsonPayload__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/genJsonPayload */ \"./templates/utils/genJsonPayload.js\");\n/* harmony import */ var _userExists__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./userExists */ \"./templates/auth/register/userExists.js\");\n/* harmony import */ var _emailExists__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./emailExists */ \"./templates/auth/register/emailExists.js\");\n/* harmony import */ var _forms_scss__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../forms.scss */ \"./templates/auth/forms.scss\");\n/* harmony import */ var _forms_scss__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_forms_scss__WEBPACK_IMPORTED_MODULE_4__);\n\n\n\n\n\n\n\n\n\n\nconst registerUser = async e => {\n e.preventDefault();\n\n let username = document.getElementById('username').value;\n Object(_utils_genJsonPayload__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(e, username, 'username');\n\n let password = document.getElementById('password').value;\n let passwordCheck = document.getElementById('password-check').value;\n if (password != passwordCheck) {\n return alert(\"passwords don't match, check again!\");\n }\n\n let exists = await Object(_userExists__WEBPACK_IMPORTED_MODULE_2__[\"default\"])();\n if (exists) {\n return;\n }\n\n let email = document.getElementById('email').value;\n if (!email.replace(/\\s/g, '').length) {\n email = null;\n } else {\n exists = await Object(_emailExists__WEBPACK_IMPORTED_MODULE_3__[\"checkEmailExists\"])();\n if (exists) {\n return;\n }\n }\n\n let payload = {\n username,\n password,\n email,\n };\n\n let res = await fetch(_api_v1_routes__WEBPACK_IMPORTED_MODULE_0__[\"default\"].registerUser, Object(_utils_genJsonPayload__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(payload));\n if (res.ok) {\n alert('success');\n } else {\n let err = await res.json();\n alert(`error: ${err.error}`);\n }\n};\n\nconst index = () => {\n let form = document.getElementById('form');\n form.addEventListener('submit', registerUser, true);\n\n let username = document.getElementById('username');\n username.addEventListener('input', _userExists__WEBPACK_IMPORTED_MODULE_2__[\"default\"], false);\n};\n\n\n//# sourceURL=webpack:///./templates/auth/register/index.js?");
/***/ }),

View file

@ -17,14 +17,13 @@
</label>
<label class="form__in-group" for="username"
>Email
>Email(optional)
<input
class="form__in-field"
id="email"
type="email"
name="email"
id="email"
required
/>
</label>

View file

@ -20,17 +20,19 @@ const registerUser = async e => {
return alert("passwords don't match, check again!");
}
let email = document.getElementById('email').value;
isBlankString(e, email, 'email');
let exists = await userExists();
if (exists) {
return;
}
exists = await checkEmailExists();
if (exists) {
return;
let email = document.getElementById('email').value;
if (!email.replace(/\s/g, '').length) {
email = null;
} else {
exists = await checkEmailExists();
if (exists) {
return;
}
}
let payload = {
@ -54,4 +56,4 @@ export const index = () => {
let username = document.getElementById('username');
username.addEventListener('input', userExists, false);
}
};