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";
63 name: "my-upsert-user",
66 nameOrEmail: "", //for login
67 logStage: "Login", //or Register
69 enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
75 nameOrEmail: function(newValue) {
76 if (newValue.indexOf("@") >= 0) {
77 this.user.email = newValue;
80 this.user.name = newValue;
86 submitMessage: function() {
95 return "Never reached";
98 return this.st.user.id > 0 ? "Update" : this.logStage;
102 trySetEnterTime: function(event) {
103 if (event.target.checked) {
105 this.enterTime = Date.now();
106 document.getElementById("u_username").focus();
108 name: this.st.user.name,
109 email: this.st.user.email,
110 notify: this.st.user.notify
114 toggleStage: function() {
115 // Loop login <--> register (update is for logged-in users)
116 this.logStage = this.logStage == "Login" ? "Register" : "Login";
118 ajaxUrl: function() {
119 switch (this.stage) {
127 return "Never reached";
129 ajaxMethod: function() {
130 switch (this.stage) {
138 return "Never reached";
140 infoMessage: function() {
141 switch (this.stage) {
143 return "Connection token sent. Check your emails!";
145 return "Registration complete! Please check your emails now";
147 return "Modifications applied!";
149 return "Never reached";
151 onSubmit: function() {
152 // Basic anti-bot strategy:
153 const exitTime = Date.now();
154 if (this.stage == "Register" && exitTime - this.enterTime < 5000) return;
155 let error = undefined;
156 if (this.stage == "Login") {
157 const type = this.nameOrEmail.indexOf("@") >= 0 ? "email" : "name";
158 error = checkNameEmail({ [type]: this.nameOrEmail });
159 } else error = checkNameEmail(this.user);
161 alert(this.st.tr[error]);
164 this.infoMsg = "Processing... Please wait";
168 this.stage == "Login"
169 ? { nameOrEmail: this.nameOrEmail }
172 this.infoMsg = this.infoMessage();
173 if (this.stage != "Update") this.nameOrEmail = "";
175 this.st.user.name = this.user.name;
176 this.st.user.email = this.user.email;
177 this.st.user.notify = this.user.notify;
186 doLogout: function() {
187 document.getElementById("modalUser").checked = false;
188 this.$router.push("/logout");
194 <style lang="sass" scoped>
195 [type="checkbox"].modal+div .card