Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello_uni-id-pages
提交
d409b1d6
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看板
提交
d409b1d6
编写于
8月 23, 2022
作者:
JiaRongPing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: PC style advance
上级
0178f4f4
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
642 addition
and
22 deletion
+642
-22
uni_modules/uni-id-pages/components/uni-id-pages-email-form/uni-id-pages-email-form.vue
...nents/uni-id-pages-email-form/uni-id-pages-email-form.vue
+246
-0
uni_modules/uni-id-pages/pages/register/register-by-email.vue
...modules/uni-id-pages/pages/register/register-by-email.vue
+26
-8
uni_modules/uni-id-pages/pages/register/register.vue
uni_modules/uni-id-pages/pages/register/register.vue
+10
-3
uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email.vue
...modules/uni-id-pages/pages/retrieve/retrieve-by-email.vue
+29
-4
uni_modules/uni-id-pages/pages/retrieve/retrieve.vue
uni_modules/uni-id-pages/pages/retrieve/retrieve.vue
+24
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/constants.js
...ges/uniCloud/cloudfunctions/uni-id-co/common/constants.js
+12
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
...i-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
+36
-2
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/reset-pwd-by-email.js
...dfunctions/uni-id-co/module/account/reset-pwd-by-email.js
+119
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/register/index.js
...niCloud/cloudfunctions/uni-id-co/module/register/index.js
+2
-1
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/register/register-user-by-email.js
...tions/uni-id-co/module/register/register-user-by-email.js
+87
-0
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/verify/send-email-code.js
...cloudfunctions/uni-id-co/module/verify/send-email-code.js
+50
-2
未找到文件。
uni_modules/uni-id-pages/components/uni-id-pages-email-form/uni-id-pages-email-form.vue
0 → 100644
浏览文件 @
d409b1d6
<
template
>
<view>
<uni-captcha
:focus=
"focusCaptchaInput"
ref=
"captcha"
scene=
"send-email-code"
v-model=
"captcha"
/>
<view
class=
"box"
>
<uni-easyinput
:focus=
"focusEmailCodeInput"
@
blur=
"focusEmailCodeInput = false"
type=
"number"
class=
"input-box"
:inputBorder=
"false"
v-model=
"modelValue"
maxlength=
"6"
placeholder=
"请输入邮箱验证码"
>
</uni-easyinput>
<view
class=
"short-code-btn"
hover-class=
"hover"
@
click=
"start"
>
<text
class=
"inner-text"
:class=
"reverseNumber==0?'inner-text-active':''"
>
{{
innerText
}}
</text>
</view>
</view>
</view>
</
template
>
<
script
>
function
debounce
(
func
,
wait
)
{
let
timer
;
wait
=
wait
||
500
;
return
function
()
{
let
context
=
this
;
let
args
=
arguments
;
if
(
timer
)
clearTimeout
(
timer
);
let
callNow
=
!
timer
;
timer
=
setTimeout
(()
=>
{
timer
=
null
;
},
wait
)
if
(
callNow
)
func
.
apply
(
context
,
args
);
}
}
/**
* email-code-form
* @description 获取邮箱验证码组件
* @tutorial https://ext.dcloud.net.cn/plugin?id=
* @property {Number} count 倒计时时长 s
* @property {String} email 邮箱
* @property {String} type = [login-by-email-code|reset-pwd-by-email-code|bind-email] 验证码类型,用于防止不同功能的验证码混用,目前支持的类型login登录、register注册、bind绑定邮箱、unbind解绑邮箱
* @property {false} focusCaptchaInput = [true|false] 验证码输入框是否默认获取焦点
*/
export
default
{
name
:
"
uni-email-code-form
"
,
model
:
{
prop
:
'
modelValue
'
,
event
:
'
update:modelValue
'
},
props
:
{
event
:
[
'
update:modelValue
'
],
/**
* 倒计时时长 s
*/
count
:
{
type
:
[
String
,
Number
],
default
:
60
},
/**
* 邮箱
*/
email
:
{
type
:
[
String
],
default
:
''
},
/*
验证码类型,用于防止不同功能的验证码混用,目前支持的类型login登录、register注册、bind绑定邮箱、unbind解绑邮箱
*/
type
:
{
type
:
String
,
default
()
{
return
'
register
'
}
},
/*
验证码输入框是否默认获取焦点
*/
focusCaptchaInput
:
{
type
:
Boolean
,
default
()
{
return
false
}
},
},
data
()
{
return
{
captcha
:
""
,
reverseNumber
:
0
,
reverseTimer
:
null
,
modelValue
:
""
,
focusEmailCodeInput
:
false
};
},
watch
:
{
captcha
(
value
,
oldValue
)
{
if
(
value
.
length
==
4
&&
oldValue
.
length
!=
4
)
{
this
.
start
()
}
},
modelValue
(
value
)
{
// TODO 兼容 vue2
this
.
$emit
(
'
input
'
,
value
);
// TODO 兼容 vue3
this
.
$emit
(
'
update:modelValue
'
,
value
)
}
},
computed
:
{
innerText
()
{
if
(
this
.
reverseNumber
==
0
)
return
"
获取邮箱验证码
"
;
return
"
重新发送
"
+
'
(
'
+
this
.
reverseNumber
+
'
s)
'
;
}
},
created
()
{
this
.
initClick
();
},
methods
:
{
getImageCaptcha
(
focus
)
{
this
.
$refs
.
captcha
.
getImageCaptcha
(
focus
)
},
initClick
()
{
this
.
start
=
debounce
(()
=>
{
if
(
this
.
reverseNumber
!=
0
)
return
;
this
.
sendMsg
();
})
},
sendMsg
()
{
if
(
this
.
captcha
.
length
!=
4
)
{
this
.
$refs
.
captcha
.
focusCaptchaInput
=
true
return
uni
.
showToast
({
title
:
'
请先输入图形验证码
'
,
icon
:
'
none
'
});
}
if
(
!
this
.
email
)
return
uni
.
showToast
({
title
:
"
请输入邮箱
"
,
icon
:
'
none
'
});
let
reg_email
=
/@/
;
if
(
!
reg_email
.
test
(
this
.
email
))
return
uni
.
showToast
({
title
:
"
邮箱格式错误
"
,
icon
:
'
none
'
});
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,
{
customUI
:
true
})
console
.
log
(
'
uniIdCo
'
,
uniIdCo
)
console
.
log
(
'
sendEmailCode
'
,{
"
email
"
:
this
.
email
,
"
scene
"
:
this
.
type
,
"
captcha
"
:
this
.
captcha
});
uniIdCo
.
sendEmailCode
({
"
email
"
:
this
.
email
,
"
scene
"
:
this
.
type
,
"
captcha
"
:
this
.
captcha
}).
then
(
result
=>
{
console
.
log
(
result
.
code
);
uni
.
showToast
({
title
:
"
邮箱验证码发送成功
"
,
icon
:
'
none
'
});
this
.
reverseNumber
=
Number
(
this
.
count
);
this
.
getCode
();
}).
catch
(
e
=>
{
console
.
log
(
JSON
.
stringify
(
e
));
if
(
e
.
code
==
"
uni-id-invalid-mail-template
"
)
{
this
.
modelValue
=
"
123456
"
uni
.
showToast
({
title
:
'
已启动测试模式,详情【控制台信息】
'
,
icon
:
'
none
'
,
duration
:
3000
});
console
.
warn
(
e
.
message
);
}
else
{
this
.
getImageCaptcha
()
this
.
captcha
=
""
uni
.
showToast
({
title
:
e
.
message
,
icon
:
'
none
'
});
}
})
},
getCode
()
{
if
(
this
.
reverseNumber
==
0
)
{
clearTimeout
(
this
.
reverseTimer
);
this
.
reverseTimer
=
null
;
return
;
}
this
.
reverseNumber
--
;
this
.
reverseTimer
=
setTimeout
(()
=>
{
this
.
getCode
();
},
1000
)
}
}
}
</
script
>
<
style
lang=
"scss"
scoped
>
.box
{
position
:
relative
;
margin-top
:
10px
;
}
.short-code-btn
{
padding
:
0
;
position
:
absolute
;
top
:
0
;
right
:
8px
;
width
:
260rpx
;
max-width
:
130px
;
height
:
44px
;
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
justify-content
:
center
;
align-items
:
center
;
}
.inner-text
{
font-size
:
14px
;
color
:
#AAAAAA
;
}
.inner-text-active
{
color
:
#04498c
;
}
.captcha
{
width
:
350rpx
;
}
.input-box
{
margin
:
0
;
padding
:
4px
;
background-color
:
#F8F8F8
;
font-size
:
14px
;
}
.
box
:
:
v-deep
.
content-clear-icon
{
margin-right
:
100px
;
}
.box
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
flex-direction
:
row
;
}
</
style
>
uni_modules/uni-id-pages/pages/register/register-by-email.vue
浏览文件 @
d409b1d6
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<image
:src=
"logo"
></image>
<image
:src=
"logo"
></image>
</view>
</view>
<!-- 顶部文字 -->
<!-- 顶部文字 -->
<text
class=
"title title-box"
>
邮箱
密
码注册
</text>
<text
class=
"title title-box"
>
邮箱
验证
码注册
</text>
</match-media>
</match-media>
<uni-forms
ref=
"form"
:value=
"formData"
:rules=
"rules"
validate-trigger=
"submit"
err-show-type=
"toast"
>
<uni-forms
ref=
"form"
:value=
"formData"
:rules=
"rules"
validate-trigger=
"submit"
err-show-type=
"toast"
>
<uni-forms-item
name=
"email"
required
>
<uni-forms-item
name=
"email"
required
>
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
</uni-forms-item>
</uni-forms-item>
<uni-forms-item
name=
"password"
v-model=
"formData.password"
required
>
<uni-forms-item
name=
"password"
v-model=
"formData.password"
required
>
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
<uni-easyinput
:inputBorder=
"false"
:focus=
"focusPassword"
@
blur=
"focusPassword = false"
class=
"input-box"
maxlength=
"20"
placeholder=
"请输入6-20位密码
"
type=
"password"
class=
"input-box"
maxlength=
"20"
:placeholder=
"'请输入' + passwordLength[0] + '-' + passwordLength[1] + '位密码'
"
type=
"password"
v-model=
"formData.password"
trim=
"both"
/>
v-model=
"formData.password"
trim=
"both"
/>
</uni-forms-item>
</uni-forms-item>
<uni-forms-item
name=
"password2"
v-model=
"formData.password2"
required
>
<uni-forms-item
name=
"password2"
v-model=
"formData.password2"
required
>
...
@@ -33,10 +33,10 @@
...
@@ -33,10 +33,10 @@
</uni-forms-item>
</uni-forms-item>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
<uni-id-pages-agreements
scope=
"register"
ref=
"agreements"
></uni-id-pages-agreements>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"submit"
>
注册
</button>
<button
class=
"uni-btn"
type=
"primary"
@
click=
"submit"
>
注册
</button>
<button
@
click=
"navigateBack"
>
返回
</button>
<button
@
click=
"navigateBack"
class=
"register-back"
>
返回
</button>
<match-media
:min-width=
"690"
>
<match-media
:min-width=
"690"
>
<view
class=
"link-box"
>
<view
class=
"link-box"
>
<
view></view
>
<
text
class=
"link"
@
click=
"registerByUserName"
>
用户名密码注册
</text
>
<text
class=
"link"
@
click=
"toLogin"
>
已有账号?点此登录
</text>
<text
class=
"link"
@
click=
"toLogin"
>
已有账号?点此登录
</text>
</view>
</view>
</match-media>
</match-media>
...
@@ -47,7 +47,8 @@
...
@@ -47,7 +47,8 @@
<
script
>
<
script
>
import
rules
from
'
./validator.js
'
;
import
rules
from
'
./validator.js
'
;
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
// import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
import
config
from
'
@/uni_modules/uni-id-pages/config.js
'
import
passwordMod
from
'
@/uni_modules/uni-id-pages/common/password.js
'
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
)
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
)
export
default
{
export
default
{
mixins
:
[
mixin
],
mixins
:
[
mixin
],
...
@@ -95,7 +96,7 @@
...
@@ -95,7 +96,7 @@
],
],
label
:
"
昵称
"
label
:
"
昵称
"
},
},
//
...passwordMod.getPwdRules(),
...
passwordMod
.
getPwdRules
(),
code
:
{
code
:
{
rules
:
[{
rules
:
[{
required
:
true
,
required
:
true
,
...
@@ -111,7 +112,13 @@
...
@@ -111,7 +112,13 @@
focusEmail
:
false
,
focusEmail
:
false
,
focusNickname
:
false
,
focusNickname
:
false
,
focusPassword
:
false
,
focusPassword
:
false
,
focusPassword2
:
false
focusPassword2
:
false
,
logo
:
"
/static/logo.png
"
}
},
computed
:{
passwordLength
(){
return
config
.
password
.
length
}
}
},
},
onReady
()
{
onReady
()
{
...
@@ -163,6 +170,16 @@
...
@@ -163,6 +170,16 @@
},
},
navigateBack
()
{
navigateBack
()
{
uni
.
navigateBack
()
uni
.
navigateBack
()
},
toLogin
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/login/login-withpwd
'
})
},
registerByUserName
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/register/register
'
})
}
}
}
}
}
}
...
@@ -178,7 +195,8 @@
...
@@ -178,7 +195,8 @@
}
}
@media
screen
and
(
min-width
:
690px
)
{
@media
screen
and
(
min-width
:
690px
)
{
.uni-content
{
.uni-content
{
padding
:
30px
40px
60px
;
padding
:
30px
40px
;
max-height
:
550px
;
}
}
.link-box
{
.link-box
{
/* #ifndef APP-NVUE */
/* #ifndef APP-NVUE */
...
...
uni_modules/uni-id-pages/pages/register/register.vue
浏览文件 @
d409b1d6
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<image
:src=
"logo"
></image>
<image
:src=
"logo"
></image>
</view>
</view>
<!-- 顶部文字 -->
<!-- 顶部文字 -->
<text
class=
"title title-box"
>
账号
注册
</text>
<text
class=
"title title-box"
>
用户名密码
注册
</text>
</match-media>
</match-media>
<uni-forms
ref=
"form"
:value=
"formData"
:rules=
"rules"
validate-trigger=
"submit"
err-show-type=
"toast"
>
<uni-forms
ref=
"form"
:value=
"formData"
:rules=
"rules"
validate-trigger=
"submit"
err-show-type=
"toast"
>
<uni-forms-item
name=
"username"
required
>
<uni-forms-item
name=
"username"
required
>
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<button
@
click=
"navigateBack"
class=
"register-back"
>
返回
</button>
<button
@
click=
"navigateBack"
class=
"register-back"
>
返回
</button>
<match-media
:min-width=
"690"
>
<match-media
:min-width=
"690"
>
<view
class=
"link-box"
>
<view
class=
"link-box"
>
<
view></view
>
<
text
class=
"link"
@
click=
"registerByEmail"
>
邮箱验证码注册
</text
>
<text
class=
"link"
@
click=
"toLogin"
>
已有账号?点此登录
</text>
<text
class=
"link"
@
click=
"toLogin"
>
已有账号?点此登录
</text>
</view>
</view>
</match-media>
</match-media>
...
@@ -69,7 +69,7 @@
...
@@ -69,7 +69,7 @@
},
},
computed
:{
computed
:{
passwordLength
(){
passwordLength
(){
return
config
.
password
L
ength
return
config
.
password
.
l
ength
}
}
},
},
onReady
()
{
onReady
()
{
...
@@ -130,6 +130,11 @@
...
@@ -130,6 +130,11 @@
uni
.
navigateTo
({
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/login/login-withpwd
'
url
:
'
/uni_modules/uni-id-pages/pages/login/login-withpwd
'
})
})
},
registerByEmail
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/register/register-by-email
'
})
}
}
}
}
}
}
...
@@ -141,6 +146,8 @@
...
@@ -141,6 +146,8 @@
@media
screen
and
(
max-width
:
690px
)
{
@media
screen
and
(
max-width
:
690px
)
{
.uni-content
{
.uni-content
{
margin-top
:
15px
;
margin-top
:
15px
;
height
:
100%
;
background-color
:
#fff
;
}
}
}
}
@media
screen
and
(
min-width
:
690px
)
{
@media
screen
and
(
min-width
:
690px
)
{
...
...
uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email.vue
浏览文件 @
d409b1d6
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<image
:src=
"logo"
></image>
<image
:src=
"logo"
></image>
</view>
</view>
<!-- 顶部文字 -->
<!-- 顶部文字 -->
<text
class=
"title title-box"
>
通过邮箱找回密码
</text>
<text
class=
"title title-box"
>
通过邮箱
验证码
找回密码
</text>
</match-media>
</match-media>
<uni-forms
ref=
"form"
:value=
"formData"
err-show-type=
"toast"
>
<uni-forms
ref=
"form"
:value=
"formData"
err-show-type=
"toast"
>
<uni-forms-item
name=
"email"
>
<uni-forms-item
name=
"email"
>
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
placeholder=
"请再次输入新密码"
></uni-easyinput>
placeholder=
"请再次输入新密码"
></uni-easyinput>
</uni-forms-item>
</uni-forms-item>
<button
class=
"uni-btn send-btn-box"
type=
"primary"
@
click=
"submit"
>
提交
</button>
<button
class=
"uni-btn send-btn-box"
type=
"primary"
@
click=
"submit"
>
提交
</button>
<match-media
:min-width=
"690"
>
<view
class=
"link-box"
>
<text
class=
"link"
@
click=
"retrieveByPhone"
>
通过手机验证码找回密码
</text>
<view></view>
</view>
</match-media>
</uni-forms>
</uni-forms>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"formData.captcha"
scene=
"reset-pwd-by-sms"
ref=
"popup"
></uni-popup-captcha>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"formData.captcha"
scene=
"reset-pwd-by-sms"
ref=
"popup"
></uni-popup-captcha>
</view>
</view>
...
@@ -34,7 +40,7 @@
...
@@ -34,7 +40,7 @@
<
script
>
<
script
>
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
import
mixin
from
'
@/uni_modules/uni-id-pages/common/login-page.mixin.js
'
;
//
import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
import
passwordMod
from
'
@/uni_modules/uni-id-pages/common/password.js
'
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,{
const
uniIdCo
=
uniCloud
.
importObject
(
"
uni-id-co
"
,{
errorOptions
:{
errorOptions
:{
type
:
'
toast
'
type
:
'
toast
'
...
@@ -78,8 +84,9 @@
...
@@ -78,8 +84,9 @@
}
}
]
]
},
},
// ...passwordMod.getPwdRules()
...
passwordMod
.
getPwdRules
()
}
},
logo
:
"
/static/logo.png
"
}
}
},
},
computed
:
{
computed
:
{
...
@@ -170,6 +177,11 @@
...
@@ -170,6 +177,11 @@
console
.
log
(
key
,
'
focus
'
+
key
);
console
.
log
(
key
,
'
focus
'
+
key
);
this
[
'
focus
'
+
key
]
=
true
this
[
'
focus
'
+
key
]
=
true
})
})
},
retrieveByPhone
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/retrieve/retrieve
'
})
}
}
}
}
}
}
...
@@ -187,5 +199,18 @@
...
@@ -187,5 +199,18 @@
.uni-content
{
.uni-content
{
padding
:
30px
40px
40px
;
padding
:
30px
40px
40px
;
}
}
.link-box
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
flex-direction
:
row
;
justify-content
:
space-between
;
margin-top
:
10px
;
}
.link
{
font-size
:
12px
;
}
}
}
</
style
>
</
style
>
uni_modules/uni-id-pages/pages/retrieve/retrieve.vue
浏览文件 @
d409b1d6
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<image
:src=
"logo"
></image>
<image
:src=
"logo"
></image>
</view>
</view>
<!-- 顶部文字 -->
<!-- 顶部文字 -->
<text
class=
"title title-box"
>
找回密码
</text>
<text
class=
"title title-box"
>
通过手机验证码
找回密码
</text>
</match-media>
</match-media>
<uni-forms
ref=
"form"
:value=
"formData"
err-show-type=
"toast"
>
<uni-forms
ref=
"form"
:value=
"formData"
err-show-type=
"toast"
>
<uni-forms-item
name=
"phone"
>
<uni-forms-item
name=
"phone"
>
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
placeholder=
"请再次输入新密码"
></uni-easyinput>
placeholder=
"请再次输入新密码"
></uni-easyinput>
</uni-forms-item>
</uni-forms-item>
<button
class=
"uni-btn send-btn-box"
type=
"primary"
@
click=
"submit"
>
提交
</button>
<button
class=
"uni-btn send-btn-box"
type=
"primary"
@
click=
"submit"
>
提交
</button>
<match-media
:min-width=
"690"
>
<view
class=
"link-box"
>
<text
class=
"link"
@
click=
"retrieveByEmail"
>
通过邮箱验证码找回密码
</text>
<view></view>
</view>
</match-media>
</uni-forms>
</uni-forms>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"formData.captcha"
scene=
"reset-pwd-by-sms"
ref=
"popup"
></uni-popup-captcha>
<uni-popup-captcha
@
confirm=
"submit"
v-model=
"formData.captcha"
scene=
"reset-pwd-by-sms"
ref=
"popup"
></uni-popup-captcha>
</view>
</view>
...
@@ -195,6 +201,11 @@
...
@@ -195,6 +201,11 @@
console
.
log
(
key
,
'
focus
'
+
key
);
console
.
log
(
key
,
'
focus
'
+
key
);
this
[
'
focus
'
+
key
]
=
true
this
[
'
focus
'
+
key
]
=
true
})
})
},
retrieveByEmail
()
{
uni
.
navigateTo
({
url
:
'
/uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email
'
})
}
}
}
}
}
}
...
@@ -212,5 +223,17 @@
...
@@ -212,5 +223,17 @@
.uni-content
{
.uni-content
{
padding
:
30px
40px
40px
;
padding
:
30px
40px
40px
;
}
}
.link-box
{
/* #ifndef APP-NVUE */
display
:
flex
;
/* #endif */
flex-direction
:
row
;
justify-content
:
space-between
;
margin-top
:
10px
;
}
.link
{
font-size
:
12px
;
}
}
}
</
style
>
</
style
>
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/common/constants.js
浏览文件 @
d409b1d6
...
@@ -36,7 +36,9 @@ const CAPTCHA_SCENE = {
...
@@ -36,7 +36,9 @@ const CAPTCHA_SCENE = {
LOGIN_BY_PWD
:
'
login-by-pwd
'
,
LOGIN_BY_PWD
:
'
login-by-pwd
'
,
LOGIN_BY_SMS
:
'
login-by-sms
'
,
LOGIN_BY_SMS
:
'
login-by-sms
'
,
RESET_PWD_BY_SMS
:
'
reset-pwd-by-sms
'
,
RESET_PWD_BY_SMS
:
'
reset-pwd-by-sms
'
,
RESET_PWD_BY_EMAIL
:
'
reset-pwd-by-email
'
,
SEND_SMS_CODE
:
'
send-sms-code
'
,
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
'
}
}
...
@@ -45,6 +47,7 @@ const LOG_TYPE = {
...
@@ -45,6 +47,7 @@ const LOG_TYPE = {
LOGIN
:
'
login
'
,
LOGIN
:
'
login
'
,
REGISTER
:
'
register
'
,
REGISTER
:
'
register
'
,
RESET_PWD_BY_SMS
:
'
reset-pwd
'
,
RESET_PWD_BY_SMS
:
'
reset-pwd
'
,
RESET_PWD_BY_EMAIL
:
'
reset-pwd
'
,
BIND_MOBILE
:
'
bind-mobile
'
,
BIND_MOBILE
:
'
bind-mobile
'
,
BIND_WEIXIN
:
'
bind-weixin
'
,
BIND_WEIXIN
:
'
bind-weixin
'
,
BIND_QQ
:
'
bind-qq
'
,
BIND_QQ
:
'
bind-qq
'
,
...
@@ -58,6 +61,13 @@ const SMS_SCENE = {
...
@@ -58,6 +61,13 @@ const SMS_SCENE = {
BIND_MOBILE_BY_SMS
:
'
bind-mobile-by-sms
'
BIND_MOBILE_BY_SMS
:
'
bind-mobile-by-sms
'
}
}
const
EMAIL_SCENE
=
{
REGISTER
:
'
register
'
,
LOGIN_BY_EMAIL
:
'
login-by-email
'
,
RESET_PWD_BY_EMAIL
:
'
reset-pwd-by-email
'
,
BIND_EMAIL
:
'
bind-email
'
}
module
.
exports
=
{
module
.
exports
=
{
db
,
db
,
dbCmd
,
dbCmd
,
...
@@ -68,5 +78,6 @@ module.exports = {
...
@@ -68,5 +78,6 @@ module.exports = {
USER_STATUS
,
USER_STATUS
,
CAPTCHA_SCENE
,
CAPTCHA_SCENE
,
LOG_TYPE
,
LOG_TYPE
,
SMS_SCENE
SMS_SCENE
,
EMAIL_SCENE
}
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/index.obj.js
浏览文件 @
d409b1d6
...
@@ -15,7 +15,8 @@ const middleware = require('./middleware/index')
...
@@ -15,7 +15,8 @@ const middleware = require('./middleware/index')
const
{
const
{
registerAdmin
,
registerAdmin
,
registerUser
registerUser
,
registerUserByEmail
}
=
require
(
'
./module/register/index
'
)
}
=
require
(
'
./module/register/index
'
)
const
{
const
{
addUser
addUser
...
@@ -44,13 +45,15 @@ const {
...
@@ -44,13 +45,15 @@ const {
const
{
const
{
updatePwd
,
updatePwd
,
resetPwdBySms
,
resetPwdBySms
,
resetPwdByEmail
,
closeAccount
,
closeAccount
,
getAccountInfo
getAccountInfo
}
=
require
(
'
./module/account/index
'
)
}
=
require
(
'
./module/account/index
'
)
const
{
const
{
createCaptcha
,
createCaptcha
,
refreshCaptcha
,
refreshCaptcha
,
sendSmsCode
sendSmsCode
,
sendEmailCode
}
=
require
(
'
./module/verify/index
'
)
}
=
require
(
'
./module/verify/index
'
)
const
{
const
{
refreshToken
,
refreshToken
,
...
@@ -255,6 +258,17 @@ module.exports = {
...
@@ -255,6 +258,17 @@ module.exports = {
* @returns
* @returns
*/
*/
registerUser
,
registerUser
,
/**
* 通过邮箱+验证码注册用户
* @param {Object} params
* @param {String} params.email 邮箱
* @param {String} params.password 密码
* @param {String} params.nickname 昵称
* @param {String} params.code 邮箱验证码
* @param {String} params.inviteCode 邀请码
* @returns
*/
registerUserByEmail
,
/**
/**
* 用户名密码登录
* 用户名密码登录
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login
...
@@ -415,6 +429,16 @@ module.exports = {
...
@@ -415,6 +429,16 @@ module.exports = {
* @returns {object}
* @returns {object}
*/
*/
resetPwdBySms
,
resetPwdBySms
,
/**
* 通过邮箱验证码重置密码
* @param {object} params
* @param {string} params.email 邮箱
* @param {string} params.code 邮箱验证码
* @param {string} params.password 密码
* @param {string} params.captcha 图形验证码
* @returns {object}
*/
resetPwdByEmail
,
/**
/**
* 注销账户
* 注销账户
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#close-account
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#close-account
...
@@ -452,6 +476,16 @@ module.exports = {
...
@@ -452,6 +476,16 @@ module.exports = {
* @returns
* @returns
*/
*/
sendSmsCode
,
sendSmsCode
,
/**
* 发送邮箱验证码
* @tutorial 需自行实现功能
* @param {Object} params
* @param {String} params.email 邮箱
* @param {String} params.captcha 图形验证码
* @param {String} params.scene 短信验证码使用场景
* @returns
*/
sendEmailCode
,
/**
/**
* 刷新token
* 刷新token
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#refresh-token
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#refresh-token
...
...
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/index.js
浏览文件 @
d409b1d6
module
.
exports
=
{
module
.
exports
=
{
updatePwd
:
require
(
'
./update-pwd
'
),
updatePwd
:
require
(
'
./update-pwd
'
),
resetPwdBySms
:
require
(
'
./reset-pwd-by-sms
'
),
resetPwdBySms
:
require
(
'
./reset-pwd-by-sms
'
),
resetPwdByEmail
:
require
(
'
./reset-pwd-by-email
'
),
closeAccount
:
require
(
'
./close-account
'
),
closeAccount
:
require
(
'
./close-account
'
),
getAccountInfo
:
require
(
'
./get-account-info
'
)
getAccountInfo
:
require
(
'
./get-account-info
'
)
}
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/account/reset-pwd-by-email.js
0 → 100644
浏览文件 @
d409b1d6
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
const
{
getNeedCaptcha
,
verifyCaptcha
}
=
require
(
'
../../lib/utils/captcha
'
)
const
{
verifyEmailCode
}
=
require
(
'
../../lib/utils/verify-code
'
)
const
{
userCollection
,
EMAIL_SCENE
,
CAPTCHA_SCENE
,
LOG_TYPE
}
=
require
(
'
../../common/constants
'
)
const
{
findUser
}
=
require
(
'
../../lib/utils/account
'
)
const
PasswordUtils
=
require
(
'
../../lib/utils/password
'
)
/**
* 通过邮箱验证码重置密码
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#reset-pwd-by-email
* @param {object} params
* @param {string} params.email 邮箱
* @param {string} params.code 邮箱验证码
* @param {string} params.password 密码
* @param {string} params.captcha 图形验证码
* @returns {object}
*/
module
.
exports
=
async
function
(
params
=
{})
{
const
schema
=
{
email
:
'
email
'
,
code
:
'
string
'
,
password
:
'
password
'
,
captcha
:
{
required
:
false
,
type
:
'
string
'
}
}
this
.
middleware
.
validate
(
params
,
schema
)
const
{
email
,
code
,
password
,
captcha
}
=
params
const
needCaptcha
=
await
getNeedCaptcha
.
call
(
this
,
{
email
,
type
:
LOG_TYPE
.
RESET_PWD_BY_EMAIL
})
if
(
needCaptcha
)
{
await
verifyCaptcha
.
call
(
this
,
{
captcha
,
scene
:
CAPTCHA_SCENE
.
RESET_PWD_BY_EMAIL
})
}
try
{
// 验证手机号验证码,验证不通过时写入失败日志
await
verifyEmailCode
({
email
,
code
,
scene
:
EMAIL_SCENE
.
RESET_PWD_BY_EMAIL
})
}
catch
(
error
)
{
await
this
.
middleware
.
uniIdLog
({
data
:
{
email
},
type
:
LOG_TYPE
.
RESET_PWD_BY_EMAIL
,
success
:
false
})
throw
error
}
// 根据手机号查找匹配的用户
const
userMatched
=
await
findUser
.
call
(
this
,
{
userQuery
:
{
email
},
authorizedApp
:
[
this
.
getClientInfo
().
appId
]
})
if
(
userMatched
.
length
===
0
)
{
throw
{
errCode
:
ERROR
.
ACCOUNT_NOT_EXISTS
}
}
else
if
(
userMatched
.
length
>
1
)
{
throw
{
errCode
:
ERROR
.
ACCOUNT_CONFLICT
}
}
const
{
_id
:
uid
}
=
userMatched
[
0
]
const
{
passwordHash
,
version
}
=
new
PasswordUtils
({
passwordSecret
:
this
.
config
.
passwordSecret
}).
generatePasswordHash
({
password
})
// 更新用户密码
await
userCollection
.
doc
(
uid
).
update
({
password
:
passwordHash
,
password_secret_version
:
version
,
valid_token_date
:
Date
.
now
()
})
// 写入成功日志
await
this
.
middleware
.
uniIdLog
({
data
:
{
email
},
type
:
LOG_TYPE
.
RESET_PWD_BY_SMS
})
return
{
errCode
:
0
}
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/register/index.js
浏览文件 @
d409b1d6
module
.
exports
=
{
module
.
exports
=
{
registerUser
:
require
(
'
./register-user
'
),
registerUser
:
require
(
'
./register-user
'
),
registerAdmin
:
require
(
'
./register-admin
'
)
registerAdmin
:
require
(
'
./register-admin
'
),
registerUserByEmail
:
require
(
'
./register-user-by-email
'
)
}
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/register/register-user-by-email.js
0 → 100644
浏览文件 @
d409b1d6
const
{
postRegister
,
preRegisterWithPassword
}
=
require
(
'
../../lib/utils/register
'
)
const
{
verifyCaptcha
}
=
require
(
'
../../lib/utils/captcha
'
)
const
{
CAPTCHA_SCENE
,
EMAIL_SCENE
,
LOG_TYPE
}
=
require
(
'
../../common/constants
'
)
const
{
verifyEmailCode
}
=
require
(
'
../../lib/utils/verify-code
'
)
/**
* 通过邮箱+验证码注册普通用户
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#register-user-by-email
* @param {Object} params
* @param {String} params.email 邮箱
* @param {String} params.password 密码
* @param {String} params.nickname 昵称
* @param {String} params.code 邮箱验证码
* @param {String} params.inviteCode 邀请码
* @returns
*/
module
.
exports
=
async
function
(
params
=
{})
{
const
schema
=
{
email
:
'
email
'
,
password
:
'
password
'
,
nickname
:
{
required
:
false
,
type
:
'
nickname
'
},
code
:
'
string
'
,
inviteCode
:
{
required
:
false
,
type
:
'
string
'
}
}
this
.
middleware
.
validate
(
params
,
schema
)
const
{
email
,
password
,
nickname
,
code
,
inviteCode
}
=
params
try
{
// 验证邮箱验证码,验证不通过时写入失败日志
await
verifyEmailCode
({
email
,
code
,
scene
:
EMAIL_SCENE
.
REGISTER
})
}
catch
(
error
)
{
await
this
.
middleware
.
uniIdLog
({
data
:
{
email
},
type
:
LOG_TYPE
.
REGISTER
,
success
:
false
})
throw
error
}
const
{
user
,
extraData
}
=
await
preRegisterWithPassword
.
call
(
this
,
{
user
:
{
email
},
password
})
return
postRegister
.
call
(
this
,
{
user
,
extraData
:
{
...
extraData
,
nickname
,
email_confirmed
:
1
},
inviteCode
})
}
uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/verify/send-email-code.js
浏览文件 @
d409b1d6
const
{
verifyCaptcha
}
=
require
(
'
../../lib/utils/captcha
'
)
const
{
EMAIL_SCENE
}
=
require
(
'
../../common/constants
'
)
const
{
ERROR
}
=
require
(
'
../../common/error
'
)
/**
/**
* 发送邮箱验证码,可用于登录、注册、绑定邮箱、修改密码等操作
* 发送邮箱验证码,可用于登录、注册、绑定邮箱、修改密码等操作
* @tutorial
* @tutorial
* @param {Object} params
* @param {Object} params
* @param {String} params.email 邮箱
* @param {String} params.email 邮箱
* @param {String} params.captcha 图形验证码
* @param {String} params.scene 使用场景
* @param {String} params.scene 使用场景
* @returns
* @returns
*/
*/
module
.
exports
=
async
function
(
params
=
{})
{
module
.
exports
=
async
function
(
params
=
{})
{
// 此接口暂未实现,欢迎向我们提交pr
const
schema
=
{
throw
new
Error
(
'
api[sendEmailCode] is not yet implemented
'
)
email
:
'
email
'
,
captcha
:
'
string
'
,
scene
:
'
string
'
}
this
.
middleware
.
validate
(
params
,
schema
)
const
{
email
,
captcha
,
scene
}
=
params
if
(
!
(
Object
.
values
(
EMAIL_SCENE
).
includes
(
scene
)))
{
throw
{
errCode
:
ERROR
.
INVALID_PARAM
}
}
await
verifyCaptcha
.
call
(
this
,
{
scene
:
'
send-email-code
'
,
captcha
})
// -- 测试代码
require
(
'
../../lib/utils/verify-code
'
)
.
setEmailVerifyCode
.
call
(
this
,
{
email
,
code
:
'
123456
'
,
expiresIn
:
180
,
scene
})
return
{
errCode
:
'
uni-id-invalid-mail-template
'
,
errMsg
:
`已启动测试模式,直接使用:123456作为邮箱验证码即可。\n如果是正式项目,需自行实现发送邮件的相关功能`
}
// -- 测试代码
//发送邮件--需自行实现
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录