Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-id-pages-x
提交
2d9d4bd1
H
hello uni-id-pages-x
项目概览
DCloud
/
hello uni-id-pages-x
通知
38
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-id-pages-x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2d9d4bd1
编写于
12月 27, 2023
作者:
A
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
退出登录redirectTo拦截处理
上级
a69f6c0c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
125 addition
and
109 deletion
+125
-109
uni_modules/uni-id-pages-x/common/common.uts
uni_modules/uni-id-pages-x/common/common.uts
+93
-92
uni_modules/uni-id-pages-x/init.uts
uni_modules/uni-id-pages-x/init.uts
+32
-17
未找到文件。
uni_modules/uni-id-pages-x/common/common.uts
浏览文件 @
2d9d4bd1
import { state, mutations } from '@/uni_modules/uni-id-pages-x/store.uts';
import config from '@/uni_modules/uni-id-pages-x/config.uts';
export const loginSuccess = (_ : UTSJSONObject) => {
// console.log('loginSuccess', e);
// console.log("新用户uid", e["uid"]);
// state.currentUserInfo = uniCloud.getCurrentUserInfo()
mutations.updateUserInfo(null)
// state.userInfo["_id"] = e["uid"]
state.isLogin = true
uni.$emit('uni-id-pages-x-login-success', '')
// console.log('loginSuccess', e);
// console.log("新用户uid", e["uid"]);
// state.currentUserInfo = uniCloud.getCurrentUserInfo()
mutations.updateUserInfo(null)
// state.userInfo["_id"] = e["uid"]
state.isLogin = true
uni.$emit('uni-id-pages-x-login-success', '')
// 登录后重定向设置
function loginAfterToPage() {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const uniIdRedirectUrl = currentPage.options.get("uniIdRedirectUrl");
if (uniIdRedirectUrl != null) {
// console.log('uniIdRedirectUrl', uniIdRedirectUrl);
uni.redirectTo({
url: uniIdRedirectUrl,
fail() {
console.error("uniIdRouter redirectTo fail");
uni.switchTab({
"url": uniIdRedirectUrl
})
},
success() {
// console.log('uniIdRouter redirectTo success');
}
})
} else if(currentPage.route == "uni_modules/uni-id-pages-x/pages/login/login") {
uni.navigateBack()
}
};
const toastDuration = 1500
uni.showToast({
title: '登录成功',
duration: toastDuration,
icon: 'none'
});
// 避免 showToast 还没结束就跳转引起的崩溃
setTimeout(() => loginAfterToPage(), toastDuration);
// 登录后重定向设置
function loginAfterToPage() {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const uniIdRedirectUrl = currentPage.options.get("uniIdRedirectUrl");
if (uniIdRedirectUrl != null) {
// console.log('uniIdRedirectUrl', uniIdRedirectUrl);
uni.redirectTo({
url: uniIdRedirectUrl,
fail() {
console.error("uniIdRouter redirectTo fail");
uni.switchTab({
"url": uniIdRedirectUrl
})
},
success() {
// console.log('uniIdRouter redirectTo success');
}
})
} else if (currentPage.route == "uni_modules/uni-id-pages-x/pages/login/login") {
uni.navigateBack()
}
};
const toastDuration = 1500
uni.showToast({
title: '登录成功',
duration: toastDuration,
icon: 'none'
});
// 避免 showToast 还没结束就跳转引起的崩溃
setTimeout(() => loginAfterToPage(), toastDuration);
}
export const logout = async () => {
// console.log("logout");
// 1. 已经过期就不需要调用服务端的注销接口 2.即使调用注销接口失败,不能阻塞客户端
if (uniCloud.getCurrentUserInfo().tokenExpired > Date.now()) {
const uniIdCo = uniCloud.importObject("uni-id-co", { customUI: false })
try{
await uniIdCo.logout()
}catch(_){
//TODO handle the exception
}
// 调完注销接口 跳转至登录页面
uni.redirectTo({
url: "/uni_modules/uni-id-pages-x/pages/login/login"
})
}
uni.removeStorageSync('uni_id_token');
uni.setStorageSync('uni_id_token_expired', 0)
console.log("logout");
// 1. 已经过期就不需要调用服务端的注销接口 2.即使调用注销接口失败,不能阻塞客户端
if (uniCloud.getCurrentUserInfo().tokenExpired > Date.now()) {
const uniIdCo = uniCloud.importObject("uni-id-co", { customUI: false })
try {
await uniIdCo.logout()
} catch (err) {
//TODO handle the exception
console.log('err: ', err);
}
}
uni.removeStorageSync('uni_id_token');
uni.setStorageSync('uni_id_token_expired', 0)
state.userInfo = {}
state.isLogin = false
uni.$emit('uni-id-pages-x-logout', '')
// 调完注销接口 跳转至登录页面
uni.redirectTo({
url: "/uni_modules/uni-id-pages-x/pages/login/login"
})
state.userInfo = {}
state.isLogin = false
uni.$emit('uni-id-pages-x-logout', '')
}
export const checkPassword = (password : string) : UTSJSONObject => {
let res : UTSJSONObject = {
"pass": true,
"errMsg": null
}
// console.log("checkPassword", password);
// 根据配置的密码强度校验
let passwordStrength = config.getString("passwordStrength")
if (passwordStrength == null) {
return res
}
// 密码强度表达式
const passwordRules : UTSJSONObject = {
"super": {
"rule": "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/])[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{8,16}$",
"errMsg": "密码必须包含大小写字母、数字和特殊符号,长度范围:8-16位之间"
},
"strong": {
"rule": "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/])[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{8,16}$",
"errMsg": "密密码必须包含字母、数字和特殊符号,长度范围:8-16位之间"
},
"medium": {
"rule": "^(?!.*[0-9]+$)(?!.*[a-zA-Z]+$)(?!.*[~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]+$)[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{8,16}$",
"errMsg": "密码必须为字母、数字和特殊符号任意两种的组合,长度范围:8-16位之间"
},
"weak": {
"rule": "^(?=.*[0-9])(?=.*[a-zA-Z])[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{6,16}$",
"errMsg": "密码必须包含字母和数字,长度范围:6-16位之间"
}
}
let passwordRule = passwordRules.getString(passwordStrength + '.rule');
let passwordRegExp = new RegExp(passwordRule as string);
res["pass"] = passwordRegExp.test(password);
res["errMsg"] = passwordRules.getString(passwordStrength + '.errMsg');
return res
export const checkPassword = (password : string) : UTSJSONObject => {
let res : UTSJSONObject = {
"pass": true,
"errMsg": null
}
// console.log("checkPassword", password);
// 根据配置的密码强度校验
let passwordStrength = config.getString("passwordStrength")
if (passwordStrength == null) {
return res
}
// 密码强度表达式
const passwordRules : UTSJSONObject = {
"super": {
"rule": "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/])[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{8,16}$",
"errMsg": "密码必须包含大小写字母、数字和特殊符号,长度范围:8-16位之间"
},
"strong": {
"rule": "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/])[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{8,16}$",
"errMsg": "密密码必须包含字母、数字和特殊符号,长度范围:8-16位之间"
},
"medium": {
"rule": "^(?!.*[0-9]+$)(?!.*[a-zA-Z]+$)(?!.*[~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]+$)[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{8,16}$",
"errMsg": "密码必须为字母、数字和特殊符号任意两种的组合,长度范围:8-16位之间"
},
"weak": {
"rule": "^(?=.*[0-9])(?=.*[a-zA-Z])[0-9a-zA-Z~!@#$%^&_\\-+=`|\\(){}\\[\\]:;\"'<>,.?/]{6,16}$",
"errMsg": "密码必须包含字母和数字,长度范围:6-16位之间"
}
}
let passwordRule = passwordRules.getString(passwordStrength + '.rule');
let passwordRegExp = new RegExp(passwordRule as string);
res["pass"] = passwordRegExp.test(password);
res["errMsg"] = passwordRules.getString(passwordStrength + '.errMsg');
return res
}
uni_modules/uni-id-pages-x/init.uts
浏览文件 @
2d9d4bd1
...
...
@@ -74,32 +74,47 @@ export default async function () {
} as PreLoginOptions);
uni.addInterceptor('navigateTo',{
invoke:(e:NavigateToOptions)=>{
if (e.url.indexOf("/uni_modules/uni-id-pages-x/pages/login/login") == 0) {
let url = decodeURIComponent(e.url)
let param:UTSJSONObject = {};
// 获取链接后面的参数部分
let keyValuePairs = url!.split('?')[1].split('&'); // 将参数按&分隔为键值对数组
const handleInterceptor = (geturl:string)=>{
if (geturl.indexOf("/uni_modules/uni-id-pages-x/pages/login/login") == 0) {
let url = decodeURIComponent(geturl)
let param:UTSJSONObject = {};
// 获取链接后面的参数部分
let urlSplit = url!.split('?')
let type = '';
if(urlSplit.length > 1){
let keyValuePairs = urlSplit[1].split('&'); // 将参数按&分隔为键值对数组
// console.log('keyValuePairs: ',keyValuePairs);
keyValuePairs.forEach(keyValuePair => {
let [key, value] = keyValuePair.split('='); // 将键值对按等号分隔为键和值
param[key] = value;
});
let type = param["type"]
if(type == null){
type = loginTypes[0];
if(typeof param["type"] == 'string'){
type = param["type"] as string
}
if(type == "univerify"){
myUniverify.verify(true)
throw Error('第一优先级是一键登录(且可用),就直接调用一键登录,不打开登录页面')
}
}
if(type == ''){
type = loginTypes[0];
}
if(type == "univerify"){
myUniverify.verify(true)
throw new Error('第一优先级是一键登录(且可用),就直接调用一键登录,不打开登录页面')
}
}
}
uni.addInterceptor('navigateTo',{
invoke:(e:NavigateToOptions)=>{
handleInterceptor(e.url)
}
})
uni.addInterceptor('redirectTo',{
invoke:(e:RedirectToOptions)=>{
handleInterceptor(e.url)
}
})
}
}
// #endif
// // 3. 绑定clientDB错误事件
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录