5 @change="trySetEnterTime($event)"
9 data-checkbox="modalUser"
12 label.modal-close(for="modalUser")
13 h3.section {{ st.tr[stage] }}
14 div(@keyup.enter="onSubmit()")
15 div(v-show="stage!='Login'")
17 label(for="u_username") {{ st.tr["User name"] }}
23 label(for="u_useremail") {{ st.tr["Email"] }}
29 label(for="notifyNew") {{ st.tr["Notifications by email"] }}
34 div(v-show="stage=='Login'")
36 label(for="nameOrEmail") {{ st.tr["Name or Email"] }}
42 button(@click="onSubmit()")
43 span {{ st.tr[submitMessage] }}
45 v-if="stage!='Update'"
47 @click="toggleStage()"
49 span {{ st.tr[stage=="Login" ? "Register" : "Login"] }}
54 span {{ st.tr["Logout"] }}
55 #dialog.text-center {{ st.tr[infoMsg] }}
59 import { store } from "@/store";
60 import { checkNameEmail } from "@/data/userCheck";
61 import { ajax } from "@/utils/ajax";
62 import { processModalClick } from "@/utils/modalClick.js";
64 name: "my-upsert-user",
67 nameOrEmail: "", //for login
68 logStage: "Login", //or Register
70 enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
76 document.getElementById("upsertDiv")
77 .addEventListener("click", processModalClick);
80 nameOrEmail: function(newValue) {
81 if (newValue.indexOf("@") >= 0) {
82 this.user.email = newValue;
85 this.user.name = newValue;
91 submitMessage: function() {
100 return "Never reached";
103 return this.st.user.id > 0 ? "Update" : this.logStage;
107 trySetEnterTime: function(event) {
108 if (event.target.checked) {
110 this.enterTime = Date.now();
111 document.getElementById("u_username").focus();
113 name: this.st.user.name,
114 email: this.st.user.email,
115 notify: this.st.user.notify
119 toggleStage: function() {
120 // Loop login <--> register (update is for logged-in users)
121 this.logStage = this.logStage == "Login" ? "Register" : "Login";
123 ajaxUrl: function() {
124 switch (this.stage) {
132 return "Never reached";
134 ajaxMethod: function() {
135 switch (this.stage) {
143 return "Never reached";
145 infoMessage: function() {
146 switch (this.stage) {
148 return "Connection token sent. Check your emails!";
150 return "Registration complete! Please check your emails now";
152 return "Modifications applied!";
154 return "Never reached";
156 onSubmit: function() {
157 // Basic anti-bot strategy:
158 const exitTime = Date.now();
159 if (this.stage == "Register" && exitTime - this.enterTime < 5000) return;
160 let error = undefined;
161 if (this.stage == "Login") {
162 const type = this.nameOrEmail.indexOf("@") >= 0 ? "email" : "name";
163 error = checkNameEmail({ [type]: this.nameOrEmail });
164 } else error = checkNameEmail(this.user);
166 alert(this.st.tr[error]);
169 this.infoMsg = "Processing... Please wait";
176 this.stage == "Login"
177 ? { nameOrEmail: this.nameOrEmail }
181 this.infoMsg = this.infoMessage();
182 if (this.stage != "Update") this.nameOrEmail = "";
184 this.st.user.name = this.user.name;
185 this.st.user.email = this.user.email;
186 this.st.user.notify = this.user.notify;
196 doLogout: function() {
197 document.getElementById("modalUser").checked = false;
198 this.$router.push("/logout");
204 <style lang="sass" scoped>
205 [type="checkbox"].modal+div .card