5 @change="trySetEnterTime($event)"
9 data-checkbox="modalUser"
12 label.modal-close(for="modalUser")
13 h3.section {{ st.tr[stage] }}
14 form(@submit.prevent="onSubmit()" @keyup.enter="onSubmit()")
15 div(v-show="stage!='Login'")
17 label(for="username") {{ st.tr["User name"] }}
20 v-model="st.user.name"
23 label(for="useremail") {{ st.tr["Email"] }}
26 v-model="st.user.email"
29 label(for="notifyNew") {{ st.tr["Notifications by email"] }}
32 v-model="st.user.notify"
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
74 nameOrEmail: function(newValue) {
75 if (newValue.indexOf("@") >= 0) {
76 this.st.user.email = newValue;
77 this.st.user.name = "";
79 this.st.user.name = newValue;
80 this.st.user.email = "";
85 submitMessage: function() {
94 return "Never reached";
97 return this.st.user.id > 0 ? "Update" : this.logStage;
101 trySetEnterTime: function(event) {
102 if (event.target.checked) {
104 this.enterTime = Date.now();
107 toggleStage: function() {
108 // Loop login <--> register (update is for logged-in users)
109 this.logStage = this.logStage == "Login" ? "Register" : "Login";
111 ajaxUrl: function() {
112 switch (this.stage) {
120 return "Never reached";
122 ajaxMethod: function() {
123 switch (this.stage) {
131 return "Never reached";
133 infoMessage: function() {
134 switch (this.stage) {
136 return "Connection token sent. Check your emails!";
138 return "Registration complete! Please check your emails";
140 return "Modifications applied!";
142 return "Never reached";
144 onSubmit: function() {
145 // Basic anti-bot strategy:
146 const exitTime = Date.now();
147 if (this.stage == "Register" && exitTime - this.enterTime < 5000) return;
148 let error = undefined;
149 if (this.stage == "Login") {
150 const type = this.nameOrEmail.indexOf("@") >= 0 ? "email" : "name";
151 error = checkNameEmail({ [type]: this.nameOrEmail });
152 } else error = checkNameEmail(this.st.user);
157 this.infoMsg = "Processing... Please wait";
161 this.stage == "Login"
162 ? { nameOrEmail: this.nameOrEmail }
165 this.infoMsg = this.infoMessage();
166 if (this.stage != "Update") this.nameOrEmail = "";
174 doLogout: function() {
175 document.getElementById("modalUser").checked = false;
176 this.$router.push("/logout");
182 <style lang="sass" scoped>
183 [type="checkbox"].modal+div .card