From ad62ac800c4202b8ce9b2c78a5d1a9fabcc4775e Mon Sep 17 00:00:00 2001 From: LoveEevee Date: Fri, 13 Mar 2020 08:32:53 +0300 Subject: [PATCH] Some bug fixes --- app.py | 2 +- public/src/js/account.js | 26 +++++++++++--------- public/src/js/scorestorage.js | 9 ++++++- public/src/js/strings.js | 44 ++++++++++++++++++++++++++++++--- public/src/js/view.js | 46 +++++++++++++++++------------------ 5 files changed, 86 insertions(+), 41 deletions(-) diff --git a/app.py b/app.py index 663d1a6..a51e90f 100644 --- a/app.py +++ b/app.py @@ -205,7 +205,7 @@ def route_api_register(): return api_error('username_in_use') password = data.get('password', '').encode('utf-8') - if not 8 <= len(password) <= 5000: + if not 6 <= len(password) <= 5000: return api_error('invalid_password') salt = bcrypt.gensalt() diff --git a/public/src/js/account.js b/public/src/js/account.js index 35ea69d..8476d4a 100644 --- a/public/src/js/account.js +++ b/public/src/js/account.js @@ -256,7 +256,7 @@ class Account{ account.displayName = response.display_name var loadScores = scores => { scoreStorage.load(scores) - this.onEnd(false, true) + this.onEnd(false, true, true) pageEvents.send("login", account.username) } if(this.mode === "login"){ @@ -267,7 +267,7 @@ class Account{ }) }else{ scoreStorage.save().catch(() => {}).finally(() => { - this.onEnd(false, true) + this.onEnd(false, true, true) pageEvents.send("login", account.username) }) } @@ -294,7 +294,7 @@ class Account{ delete account.username delete account.displayName var loadScores = scores => { - Cookies.remove("token") + Cookies.remove("session") scoreStorage.load() this.onEnd(false, true) pageEvents.send("logout") @@ -341,7 +341,7 @@ class Account{ account.loggedIn = false delete account.username delete account.displayName - Cookies.remove("token") + Cookies.remove("session") scoreStorage.load() pageEvents.send("logout") return Promise.resolve @@ -351,6 +351,8 @@ class Account{ if(!noNameChange && newName !== account.displayName){ promises.push(this.request("account/display_name", { display_name: newName + }).then(() => { + account.displayName = newName })) } var error = false @@ -368,7 +370,7 @@ class Account{ this.onEnd(false, true) }, errorFunc).catch(errorFunc) } - onEnd(event, noSound){ + onEnd(event, noSound, noReset){ var touched = false if(event){ if(event.type === "touchstart"){ @@ -381,7 +383,7 @@ class Account{ if(this.locked){ return } - this.clean() + this.clean(false, noReset) assets.sounds["se_don"].play() setTimeout(() => { new SongSelect(false, false, touched) @@ -391,7 +393,7 @@ class Account{ this.lock(true) return new Promise((resolve, reject) => { var request = new XMLHttpRequest() - request.open(obj ? "POST" : "GET", "api/" + url) + request.open("POST", "api/" + url) pageEvents.load(request).then(() => { this.lock(false) if(request.status !== 200){ @@ -433,7 +435,7 @@ class Account{ } } } - clean(eventsOnly){ + clean(eventsOnly, noReset){ if(!eventsOnly){ cancelTouch = true this.keyboard.clean() @@ -447,8 +449,10 @@ class Account{ for(var i = 0; i < this.inputForms.length; i++){ pageEvents.remove(this.inputForms[i], ["keydown", "keyup", "keypress"]) } - this.accountPass.reset() - this.accountDel.reset() + if(!noReset){ + this.accountPass.reset() + this.accountDel.reset() + } delete this.displayname delete this.accountPassButton delete this.accountPass @@ -460,7 +464,7 @@ class Account{ delete this.saveButton delete this.inputForms }else if(this.mode === "login" || this.mode === "register"){ - if(!eventsOnly){ + if(!eventsOnly && !noReset){ this.form.reset() } pageEvents.remove(this.form, "submit") diff --git a/public/src/js/scorestorage.js b/public/src/js/scorestorage.js index e9db533..db919c6 100644 --- a/public/src/js/scorestorage.js +++ b/public/src/js/scorestorage.js @@ -9,7 +9,7 @@ class ScoreStorage{ load(strings){ this.scores = {} if(strings){ - this.scoreStrings = strings + this.scoreStrings = this.prepareStrings(strings) }else if(account.loggedIn){ return }else{ @@ -58,6 +58,13 @@ class ScoreStorage{ } return output } + prepareStrings(scores){ + var output = {} + for(var k in scores){ + output[scores[k].hash] = scores[k].score + } + return output + } save(localOnly){ for(var hash in this.scores){ this.writeString(hash) diff --git a/public/src/js/strings.js b/public/src/js/strings.js index 9a6c499..f4d0d75 100644 --- a/public/src/js/strings.js +++ b/public/src/js/strings.js @@ -202,7 +202,16 @@ logout: "ログアウト", back: "もどる", cancel: "Cancel", - save: "Save" + save: "Save", + displayName: "Displayed Name", + changePassword: "Change Password", + currentNewRepeat: [ + "Current Password", + "New Password", + "Repeat New Password" + ], + deleteAccount: "Delete Account", + verifyPassword: "Verify password to delete this account" } this.browserSupport = { browserWarning: "サポートされていないブラウザを実行しています (%s)", @@ -645,7 +654,16 @@ function StringsCn(){ logout: "登出", back: "返回", cancel: "Cancel", - save: "Save" + save: "Save", + displayName: "Displayed Name", + changePassword: "Change Password", + currentNewRepeat: [ + "Current Password", + "New Password", + "Repeat New Password" + ], + deleteAccount: "Delete Account", + verifyPassword: "Verify password to delete this account" } this.browserSupport = { browserWarning: "You are running an unsupported browser (%s)", @@ -862,7 +880,16 @@ function StringsTw(){ logout: "登出", back: "返回", cancel: "Cancel", - save: "Save" + save: "Save", + displayName: "Displayed Name", + changePassword: "Change Password", + currentNewRepeat: [ + "Current Password", + "New Password", + "Repeat New Password" + ], + deleteAccount: "Delete Account", + verifyPassword: "Verify password to delete this account" } this.browserSupport = { browserWarning: "You are running an unsupported browser (%s)", @@ -1079,7 +1106,16 @@ function StringsKo(){ logout: "로그 아웃", back: "돌아간다", cancel: "Cancel", - save: "Save" + save: "Save", + displayName: "Displayed Name", + changePassword: "Change Password", + currentNewRepeat: [ + "Current Password", + "New Password", + "Repeat New Password" + ], + deleteAccount: "Delete Account", + verifyPassword: "Verify password to delete this account" } this.browserSupport = { browserWarning: "You are running an unsupported browser (%s)", diff --git a/public/src/js/view.js b/public/src/js/view.js index a165b09..235b169 100644 --- a/public/src/js/view.js +++ b/public/src/js/view.js @@ -394,31 +394,29 @@ h: 130 } - if(this.multiplayer !== 2){ - this.nameplateCache.get({ + this.nameplateCache.get({ + ctx: ctx, + x: 167, + y: this.multiplayer === 2 ? 565 : 160, + w: 219, + h: 53, + id: "1p", + }, ctx => { + if(this.multiplayer === 2){ + var name = p2.name || strings.defaultName + }else{ + var name = account.loggedIn ? account.displayName : strings.defaultName + } + this.draw.nameplate({ ctx: ctx, - x: 167, - y: 160, - w: 219, - h: 53, - id: "1p", - }, ctx => { - if(this.multiplayer === 2){ - var name = p2.name || strings.defaultName - }else{ - var name = account.loggedIn ? account.displayName : strings.defaultName - } - this.draw.nameplate({ - ctx: ctx, - x: 3, - y: 3, - scale: 0.8, - name: name, - font: this.font, - blue: this.multiplayer === 2 - }) + x: 3, + y: 3, + scale: 0.8, + name: name, + font: this.font, + blue: this.multiplayer === 2 }) - } + }) ctx.fillStyle = "#000" ctx.fillRect( @@ -582,7 +580,7 @@ this.nameplateCache.get({ ctx: ctx, x: 320, - y: this.multiplayer === 2 ? frameTop + 305 : frameTop + 20, + y: this.multiplayer === 2 ? 460 : 20, w: 273, h: 66, id: "1p",