From b08a117e94aa4261412019eb148cdd5ec90d566f Mon Sep 17 00:00:00 2001 From: phoooob <1162762894@qq.com> Date: Thu, 30 Jul 2020 21:19:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=9C=89?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AF=86=E7=A0=81=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E5=88=99=E8=87=AA=E5=8A=A8=E5=8A=A0=E5=AF=86=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/update-user.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/update-user.js b/src/lib/update-user.js index ed7471c..af33239 100644 --- a/src/lib/update-user.js +++ b/src/lib/update-user.js @@ -1,3 +1,4 @@ +import encryptPwd from './encrypt-pwd' import { userCollection, log @@ -13,6 +14,11 @@ async function updateUser (params) { } delete params.uid try { + + if(!!params.password){ + params.password = encryptPwd(params.password) + } + const upRes = await userCollection.doc(uid).update(params) log('update -> upRes', upRes) -- Gitee From 8def5cbd0150b6afe43c74fc16aa882989289588 Mon Sep 17 00:00:00 2001 From: phoooob <1162762894@qq.com> Date: Thu, 30 Jul 2020 21:49:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AF=E4=BB=A5=E9=80=89=E6=8B=A9=E4=BD=BF?= =?UTF-8?q?=E7=94=A8token=E6=88=96=E8=80=85uid=EF=BC=88=E4=BA=8C=E9=80=89?= =?UTF-8?q?=E4=B8=80=EF=BC=89=E6=9D=A5=E6=9B=B4=E6=96=B0=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/reset-pwd.js | 8 ++++++++ src/lib/uni-token.js | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib/reset-pwd.js b/src/lib/reset-pwd.js index de5456a..79bc572 100644 --- a/src/lib/reset-pwd.js +++ b/src/lib/reset-pwd.js @@ -1,4 +1,5 @@ import encryptPwd from './encrypt-pwd' +import uniToken from './uni-token' import { userCollection, log @@ -6,9 +7,16 @@ import { async function resetPwd ({ uid, + token , password }) { try { + + uid = uniToken.resetUidByToken(uid , token); + if(!uid){ + throw "uid或token参数缺失" + } + const upRes = await userCollection.doc(uid).update({ password: encryptPwd(password), token: [] diff --git a/src/lib/uni-token.js b/src/lib/uni-token.js index dc989af..a02573b 100644 --- a/src/lib/uni-token.js +++ b/src/lib/uni-token.js @@ -103,7 +103,19 @@ const uniToken = { } }) return tokenExpired - } + }, + + /** + * 适用于使用uid的场景,如未获取到uid,可以通过该函数使用token换取uid + * @param {Object} uid + * @param {Object} token + */ + resetUidByToken : function(uid , token){ + if(!!uid) return uid + if(!token) return null + return checkToken(token).uid ; + }, + } export default uniToken -- Gitee