5 @change="trySetEnterTime($event)"
9 data-checkbox="modalUser"
12 label.modal-close(for="modalUser")
14 span.title {{ st.tr[stage] }}
17 v-if="stage!='Update'"
18 @click="toggleStage()"
20 | {{ st.tr[stage=="Login" ? "Register" : "Login"] }}
25 | {{ st.tr["Logout"] }}
26 img(src="/images/icons/rightArrow.svg")
28 div(@keyup.enter="onSubmit()")
29 div(v-show="stage!='Login'")
31 label(for="u_username") {{ st.tr["User name"] }}
37 label(for="u_useremail") {{ st.tr["Email"] }}
43 label(for="notifyNew") {{ st.tr["Notifications by email"] }}
48 div(v-show="stage=='Login'")
50 label(for="nameOrEmail") {{ st.tr["Name or Email"] }}
55 button#submitBtn(@click="onSubmit()")
56 | {{ st.tr[submitMessage] }}
57 #dialog.text-center {{ st.tr[infoMsg] }}
61 import { store } from "@/store";
62 import { checkNameEmail } from "@/data/userCheck";
63 import { ajax } from "@/utils/ajax";
64 import { processModalClick } from "@/utils/modalClick.js";
66 name: "my-upsert-user",
69 nameOrEmail: "", //for login
70 logStage: "Login", //or Register
72 enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
78 document.getElementById("upsertDiv")
79 .addEventListener("click", processModalClick);
82 nameOrEmail: function(newValue) {
83 if (newValue.indexOf("@") >= 0) {
84 this.user.email = newValue;
87 this.user.name = newValue;
93 submitMessage: function() {
102 return "Never reached";
105 return this.st.user.id > 0 ? "Update" : this.logStage;
109 trySetEnterTime: function(event) {
110 if (event.target.checked) {
112 this.enterTime = Date.now();
113 document.getElementById("u_username").focus();
115 name: this.st.user.name,
116 email: this.st.user.email,
117 notify: this.st.user.notify
121 toggleStage: function() {
122 // Loop login <--> register (update is for logged-in users)
123 this.logStage = this.logStage == "Login" ? "Register" : "Login";
125 ajaxUrl: function() {
126 switch (this.stage) {
134 return "Never reached";
136 ajaxMethod: function() {
137 switch (this.stage) {
145 return "Never reached";
147 infoMessage: function() {
148 switch (this.stage) {
150 return "Connection token sent. Check your emails!";
152 return "Registration complete! Please check your emails now";
154 return "Modifications applied!";
156 return "Never reached";
158 onSubmit: function() {
159 // Basic anti-bot strategy:
160 const exitTime = Date.now();
161 if (this.stage == "Register" && exitTime - this.enterTime < 5000) return;
162 let error = undefined;
163 if (this.stage == "Login") {
164 const type = this.nameOrEmail.indexOf("@") >= 0 ? "email" : "name";
165 error = checkNameEmail({ [type]: this.nameOrEmail });
167 else error = checkNameEmail(this.user);
169 alert(this.st.tr[error]);
172 this.infoMsg = "Processing... Please wait";
179 this.stage == "Login"
180 ? { nameOrEmail: this.nameOrEmail }
184 this.infoMsg = this.infoMessage();
185 if (this.stage != "Update") this.nameOrEmail = "";
187 this.st.user.name = this.user.name;
188 this.st.user.email = this.user.email;
189 this.st.user.notify = this.user.notify;
199 doLogout: function() {
200 document.getElementById("modalUser").checked = false;
201 this.$router.push("/logout");
207 <style lang="sass" scoped>
208 [type="checkbox"].modal+div .card
218 text-decoration: underline