X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fcomponents%2FUpsertUser.vue;h=6461657412754d1655540ac8b09fe4f8112cde6e;hb=dcd68c4108412f45b8ce119ae80ce8f6e296800b;hp=46f3bfe8df9e0237f4703c0b63e2ea7bb08a7ef8;hpb=a7f9f050e44080e8caf888e3b230660abffa2400;p=vchess.git diff --git a/client/src/components/UpsertUser.vue b/client/src/components/UpsertUser.vue index 46f3bfe8..64616574 100644 --- a/client/src/components/UpsertUser.vue +++ b/client/src/components/UpsertUser.vue @@ -1,11 +1,11 @@ @@ -39,13 +39,27 @@ export default { name: 'my-upsert-user', data: function() { return { - user: Object.assign({}, store.state.user), + user: store.state.user, nameOrEmail: "", //for login - stage: (store.state.user.id > 0 ? "Update" : "Login"), //TODO? + logStage: "Login", //or Register infoMsg: "", enterTime: Number.MAX_SAFE_INTEGER, //for a basic anti-bot strategy }; }, + watch: { + nameOrEmail: function(newValue) { + if (newValue.indexOf('@') >= 0) + { + this.user.email = newValue; + this.user.name = ""; + } + else + { + this.user.name = newValue; + this.user.email = ""; + } + }, + }, computed: { submitMessage: function() { switch (this.stage) @@ -61,6 +75,9 @@ export default { displayInfo: function() { return (this.infoMsg.length > 0 ? "block" : "none"); }, + stage: function() { + return this.user.id > 0 ? "Update" : this.logStage; + }, }, methods: { trySetEnterTime: function(event) { @@ -69,7 +86,7 @@ export default { }, toggleStage: function() { // Loop login <--> register (update is for logged-in users) - this.stage = (this.stage == "Login" ? "Register" : "Login"); + this.logStage = (this.logStage == "Login" ? "Register" : "Login"); }, ajaxUrl: function() { switch (this.stage) @@ -137,6 +154,20 @@ export default { } ); }, + doLogout: function() { + ajax( + "/logout", + "GET", + () => { + this.user.id = 0; + this.user.name = ""; + this.user.email = ""; + this.user.notify = false; + delete localStorage["myid"]; + delete localStorage["myname"]; + } + ); + }, }, };