3 input#modalUser.modal(type="checkbox" @change="trySetEnterTime($event)")
4 div(role="dialog" data-checkbox="modalUser")
6 label.modal-close(for="modalUser")
7 h3.section {{ st.tr[stage] }}
8 form(@submit.prevent="onSubmit()" @keyup.enter="onSubmit()")
9 div(v-show="stage!='Login'")
11 label(for="username") {{ st.tr["User name"] }}
12 input#username(type="text" v-model="st.user.name")
14 label(for="useremail") {{ st.tr["Email"] }}
15 input#useremail(type="email" v-model="st.user.email")
17 label(for="notifyNew") {{ st.tr["Notifications by email"] }}
18 input#notifyNew(type="checkbox" v-model="st.user.notify")
19 div(v-show="stage=='Login'")
21 label(for="nameOrEmail") {{ st.tr["Name or Email"] }}
22 input#nameOrEmail(type="text" v-model="nameOrEmail")
24 button(@click="onSubmit()")
25 span {{ st.tr[submitMessage] }}
26 button(v-if="stage!='Update'" type="button" @click="toggleStage()")
27 span {{ st.tr[stage=="Login" ? "Register" : "Login"] }}
28 button(v-else type="button" @click="doLogout()")
29 span {{ st.tr["Logout"] }}
30 #dialog.text-center {{ st.tr[infoMsg] }}
34 import { store } from "@/store";
35 import { checkNameEmail } from "@/data/userCheck";
36 import { ajax } from "@/utils/ajax";
38 name: "my-upsert-user",
41 nameOrEmail: "", //for login
42 logStage: "Login", //or Register
44 enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy
49 nameOrEmail: function(newValue) {
50 if (newValue.indexOf("@") >= 0) {
51 this.st.user.email = newValue;
52 this.st.user.name = "";
54 this.st.user.name = newValue;
55 this.st.user.email = "";
60 submitMessage: function() {
69 return "Never reached";
72 return this.st.user.id > 0 ? "Update" : this.logStage;
76 trySetEnterTime: function(event) {
77 if (event.target.checked) {
79 this.enterTime = Date.now();
82 toggleStage: function() {
83 // Loop login <--> register (update is for logged-in users)
84 this.logStage = this.logStage == "Login" ? "Register" : "Login";
95 return "Never reached";
97 ajaxMethod: function() {
106 return "Never reached";
108 infoMessage: function() {
109 switch (this.stage) {
111 return "Connection token sent. Check your emails!";
113 return "Registration complete! Please check your emails";
115 return "Modifications applied!";
117 return "Never reached";
119 onSubmit: function() {
120 // Basic anti-bot strategy:
121 const exitTime = Date.now();
122 if (this.stage == "Register" && exitTime - this.enterTime < 5000) return;
123 let error = undefined;
124 if (this.stage == "Login") {
125 const type = this.nameOrEmail.indexOf("@") >= 0 ? "email" : "name";
126 error = checkNameEmail({ [type]: this.nameOrEmail });
127 } else error = checkNameEmail(this.st.user);
132 this.infoMsg = "Processing... Please wait";
136 this.stage == "Login"
137 ? { nameOrEmail: this.nameOrEmail }
140 this.infoMsg = this.infoMessage();
141 if (this.stage != "Update") this.nameOrEmail = "";
149 doLogout: function() {
150 document.getElementById("modalUser").checked = false;
151 this.$router.push("/logout");
157 <style lang="sass" scoped>
158 [type="checkbox"].modal+div .card