Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
4017f8e6
H
hello_uni-id-pages
项目概览
DCloud
/
hello_uni-id-pages
通知
1054
Star
31
Fork
43
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello_uni-id-pages
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4017f8e6
编写于
11月 23, 2022
作者:
C
chenruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(uni-id-co): 新增设置密码接口
上级
15c6de13
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
160 addition
and
34 deletion
+160
-34
pages.json
pages.json
+6
-0
uni_modules/uni-id-pages/common/store.js
uni_modules/uni-id-pages/common/store.js
+48
-30
uni_modules/uni-id-pages/config.js
uni_modules/uni-id-pages/config.js
+12
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/constants.js
...ges/uniCloud/cloudfunctions/uni-id-co/common/constants.js
+4
-2
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/config/permission.js
...es/uniCloud/cloudfunctions/uni-id-co/config/permission.js
+3
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+1
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
...s/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
+2
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/index.js
...uniCloud/cloudfunctions/uni-id-co/module/account/index.js
+1
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/set-pwd.js
...iCloud/cloudfunctions/uni-id-co/module/account/set-pwd.js
+83
-0
未找到文件。
pages.json
浏览文件 @
4017f8e6
...
...
@@ -91,6 +91,12 @@
"navigationBarTitleText"
:
"修改密码"
,
"enablePullDownRefresh"
:
false
}
},{
"path"
:
"uni_modules/uni-id-pages/pages/userinfo/set-pwd/set-pwd"
,
"style"
:
{
"navigationBarTitleText"
:
"设置密码"
,
"enablePullDownRefresh"
:
false
}
}
],
"globalStyle"
:
{
...
...
uni_modules/uni-id-pages/common/store.js
浏览文件 @
4017f8e6
import
pagesJson
from
'
@/pages.json
'
import
config
from
'
@/uni_modules/uni-id-pages/config.js
'
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
)
const
db
=
uniCloud
.
database
();
const
usersTable
=
db
.
collection
(
'
uni-id-users
'
)
...
...
@@ -69,9 +71,44 @@ export const mutations = {
uni.$emit('uni-id-pages-logout')
this.setUserInfo({},{cover:true})
},
loginBack (e = {}) {
const {uniIdRedirectUrl = ''} = e
let delta = 0; //判断需要返回几层
let pages = getCurrentPages();
// console.log(pages);
pages.forEach((page, index) => {
if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
delta++
}
})
// console.log('判断需要返回几层:', delta);
if (uniIdRedirectUrl) {
return uni.reLaunch({
url: uniIdRedirectUrl
})
}
// #ifdef H5
if (e.loginType == 'weixin') {
console.log('window.history', window.history);
return window.history.go(-3)
}
// #endif
if (delta) {
const page = pagesJson.pages[0]
return uni.reLaunch({
url: `
/
$
{
page
.
path
}
`
})
}
uni.navigateBack({
delta
})
},
loginSuccess(e = {}){
const {
showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
, passwordConfirmed
} = e
console.log({
toastText,
...
...
@@ -84,39 +121,20 @@ export const mutations = {
});
}
this.updateUserInfo()
uni.$emit('uni-id-pages-login-success')
if (autoBack) {
let delta = 0; //判断需要返回几层
let pages = getCurrentPages();
// console.log(pages);
pages.forEach((page, index) => {
if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
delta++
if (config.setPasswordAfterLogin && !passwordConfirmed) {
return uni.redirectTo({
url: uniIdRedirectUrl ? `
/
uni_modules
/
uni
-
id
-
pages
/
pages
/
userinfo
/
set
-
pwd
/
set
-
pwd
?
uniIdRedirectUrl
=
$
{
uniIdRedirectUrl
}
&
loginType
=
$
{
e
.
loginType
}
`: `
/
uni_modules
/
uni
-
id
-
pages
/
pages
/
userinfo
/
set
-
pwd
/
set
-
pwd
?
loginType
=
$
{
e
.
loginType
}
`,
fail: (err) => {
console.log(err)
}
})
// console.log('判断需要返回几层:', delta);
if (uniIdRedirectUrl) {
return uni.reLaunch({
url: uniIdRedirectUrl
})
}
// #ifdef H5
if (e.loginType == 'weixin') {
console.log('window.history', window.history);
return window.history.go(-3)
}
// #endif
if (delta) {
const page = pagesJson.pages[0]
return uni.reLaunch({
url: `
/
$
{
page
.
path
}
`
})
}
}
uni.navigateBack({
delta
})
if (autoBack) {
this.loginBack(uniIdRedirectUrl)
}
}
...
...
uni_modules/uni-id-pages/config.js
浏览文件 @
4017f8e6
...
...
@@ -52,5 +52,16 @@ export default {
* weak(弱:密码必须包含字母和数字,长度范围:6-16位之间)
* 为空或false则不验证密码强度
*/
"
passwordStrength
"
:
"
medium
"
"
passwordStrength
"
:
"
medium
"
,
/**
* 登录后允许用户设置密码(只针对未设置密码得用户)
* 开启此功能将 setPasswordAfterLogin 设置为 true 即可
* "setPasswordAfterLogin": false
*
* 如果允许用户跳过设置密码 将 allowSkip 设置为 true
* "setPasswordAfterLogin": {
* "allowSkip": true
* }
* */
"
setPasswordAfterLogin
"
:
false
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/constants.js
浏览文件 @
4017f8e6
...
...
@@ -41,7 +41,8 @@ const CAPTCHA_SCENE = {
RESET_PWD_BY_EMAIL
:
'
reset-pwd-by-email
'
,
SEND_SMS_CODE
:
'
send-sms-code
'
,
SEND_EMAIL_CODE
:
'
send-email-code
'
,
BIND_MOBILE_BY_SMS
:
'
bind-mobile-by-sms
'
BIND_MOBILE_BY_SMS
:
'
bind-mobile-by-sms
'
,
SET_PWD_BY_SMS
:
'
set-pwd-by-sms
'
}
const
LOG_TYPE
=
{
...
...
@@ -64,7 +65,8 @@ const LOG_TYPE = {
const
SMS_SCENE
=
{
LOGIN_BY_SMS
:
'
login-by-sms
'
,
RESET_PWD_BY_SMS
:
'
reset-pwd-by-sms
'
,
BIND_MOBILE_BY_SMS
:
'
bind-mobile-by-sms
'
BIND_MOBILE_BY_SMS
:
'
bind-mobile-by-sms
'
,
SET_PWD_BY_SMS
:
'
set-pwd-by-sms
'
}
const
EMAIL_SCENE
=
{
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/config/permission.js
浏览文件 @
4017f8e6
...
...
@@ -74,5 +74,8 @@ module.exports = {
},
unbindApple
:
{
auth
:
true
},
setPwd
:
{
auth
:
true
}
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
4017f8e6
...
...
@@ -50,6 +50,7 @@ const {
unbindApple
}
=
require
(
'
./module/relate/index
'
)
const
{
setPwd
,
updatePwd
,
resetPwdBySms
,
resetPwdByEmail
,
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js
浏览文件 @
4017f8e6
...
...
@@ -201,7 +201,8 @@ async function postRegister (params = {}) {
}
})
:
{}
)
),
passwordConfirmed
:
!!
userRecord
.
password
}
}
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/index.js
浏览文件 @
4017f8e6
module
.
exports
=
{
setPwd
:
require
(
'
./set-pwd
'
),
updatePwd
:
require
(
'
./update-pwd
'
),
resetPwdBySms
:
require
(
'
./reset-pwd-by-sms
'
),
resetPwdByEmail
:
require
(
'
./reset-pwd-by-email
'
),
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/set-pwd.js
0 → 100644
浏览文件 @
4017f8e6
const
{
userCollection
,
SMS_SCENE
,
LOG_TYPE
,
CAPTCHA_SCENE
}
=
require
(
'
../../common/constants
'
)
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
const
{
verifyMobileCode
}
=
require
(
'
../../lib/utils/verify-code
'
)
const
PasswordUtils
=
require
(
'
../../lib/utils/password
'
)
const
{
getNeedCaptcha
,
verifyCaptcha
}
=
require
(
'
../../lib/utils/captcha
'
)
module
.
exports
=
async
function
(
params
=
{})
{
const
schema
=
{
password
:
'
password
'
,
code
:
'
string
'
,
captcha
:
{
required
:
false
,
type
:
'
string
'
}
}
this
.
middleware
.
validate
(
params
,
schema
)
const
{
password
,
code
,
captcha
}
=
params
const
uid
=
this
.
authInfo
.
uid
const
getUserRes
=
await
userCollection
.
doc
(
uid
).
get
()
const
userRecord
=
getUserRes
.
data
[
0
]
if
(
!
userRecord
)
{
throw
{
errCode
:
ERROR
.
ACCOUNT_NOT_EXISTS
}
}
const
needCaptcha
=
await
getNeedCaptcha
.
call
(
this
,
{
mobile
:
userRecord
.
mobile
})
if
(
needCaptcha
)
{
await
verifyCaptcha
.
call
(
this
,
{
captcha
,
scene
:
CAPTCHA_SCENE
.
SET_PWD_BY_SMS
})
}
try
{
// 验证手机号验证码,验证不通过时写入失败日志
await
verifyMobileCode
({
mobile
:
userRecord
.
mobile
,
code
,
scene
:
SMS_SCENE
.
SET_PWD_BY_SMS
})
}
catch
(
error
)
{
await
this
.
middleware
.
uniIdLog
({
data
:
{
mobile
:
userRecord
.
mobile
},
type
:
LOG_TYPE
.
SET_PWD_BY_SMS
,
success
:
false
})
throw
error
}
const
{
passwordHash
,
version
}
=
new
PasswordUtils
({
clientInfo
:
this
.
getUniversalClientInfo
(),
passwordSecret
:
this
.
config
.
passwordSecret
}).
generatePasswordHash
({
password
})
// 更新用户密码
await
userCollection
.
doc
(
uid
).
update
({
password
:
passwordHash
,
password_secret_version
:
version
})
await
this
.
middleware
.
uniIdLog
({
data
:
{
mobile
:
userRecord
.
mobile
},
type
:
LOG_TYPE
.
SET_PWD_BY_SMS
})
return
{
errCode
:
0
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录