提交 8d08d56a 编写于 作者: DCloud_JSON's avatar DCloud_JSON

1.0.0

上级 c3365ae6
## 1.0.0(2022-05-10)
1.0版发布
{
"id": "uni-id-pages",
"displayName": "hello uni-id-pages",
"version": "1.0.0",
"description": "云端一体简单、统一、可扩展的用户中心页面模版",
"keywords": [
"uniid",
"uni-id",
"用户管理",
"用户中心",
"短信验证码",
"登录模版"
],
"repository": "",
"engines": {
"HBuilderX": "^3.2.6"
},
"dcloudext": {
"category": [
"uniCloud",
"云端一体项目模板"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "y"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "y",
"IE": "n",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "y",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "u"
}
}
}
},
"dependencies": {}
}
"use strict";var e,n=(e=require("crypto"))&&"object"==typeof e&&"default"in e?e.default:e;const t={TOKEN_EXPIRED:"uni-id-token-expired",CHECK_TOKEN_FAILED:"uni-id-check-token-failed",PARAM_REQUIRED:"uni-id-param-required",ACCOUNT_EXISTS:"uni-id-account-exists",ACCOUNT_NOT_EXISTS:"uni-id-account-not-exists",ACCOUNT_CONFLICT:"uni-id-account-conflict",ACCOUNT_BANNED:"uni-id-account-banned",ACCOUNT_AUDITING:"uni-id-account-auditing",ACCOUNT_AUDIT_FAILED:"uni-id-account-audit-failed",ACCOUNT_CLOSED:"uni-id-account-closed"};function i(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}const r={"uni-id-token-expired":30203,"uni-id-check-token-failed":30202};function o(e){const{errCode:n,errMsgValue:t}=e;e.errMsg=this._t(n,t),n in r&&(e.code=r[n])}function c(e){return"object"===(i=e,Object.prototype.toString.call(i).slice(8,-1).toLowerCase())&&e.errCode&&(n=e.errCode,Object.values(t).includes(n))&&!!e.errCode;var n,i}let s={"zh-Hans":{"uni-id-token-expired":"状态失效,token已过期","uni-id-check-token-failed":"token校验未通过","uni-id-param-required":"缺少参数: {param}","uni-id-account-exists":"此账号已注册","uni-id-account-not-exists":"此账号未注册","uni-id-account-conflict":"用户账号冲突","uni-id-account-banned":"从账号已封禁","uni-id-account-auditing":"此账号正在审核中","uni-id-account-audit-failed":"此账号审核失败","uni-id-account-closed":"此账号已注销"},en:{"uni-id-token-expired":"The login status is invalid, token has expired","uni-id-check-token-failed":"Check token failed","uni-id-param-required":"Parameter required: {param}","uni-id-account-exists":"Account exists","uni-id-account-not-exists":"Account does not exists","uni-id-account-conflict":"User account conflict","uni-id-account-banned":"Account has been banned","uni-id-account-auditing":"Account audit in progress","uni-id-account-audit-failed":"Account audit failed","uni-id-account-closed":"Account has been closed"}};try{const e=require.resolve("uni-config-center/uni-id/lang/index.js");s=function(e,n){const t=Object.keys(e);t.push(...Object.keys(n));const i={};for(let r=0;r<t.length;r++){const o=t[r];i[o]=Object.assign({},e[o],n[o])}return i}(s,require(e))}catch(e){}var a=s;function u(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function d(e){return JSON.parse((n=function(e){var n=4-(e=e.toString()).length%4;if(4!==n)for(var t=0;t<n;++t)e+="=";return e.replace(/-/g,"+").replace(/_/g,"/")}(e),Buffer.from(n,"base64").toString("utf-8")));var n}function l(e){return u((n=JSON.stringify(e),Buffer.from(n,"utf-8").toString("base64")));var n}function f(e,t){return u(n.createHmac("sha256",t).update(e).digest("base64"))}const p=function(e,n){if("string"!=typeof e)throw new Error("Invalid token");const t=e.split(".");if(3!==t.length)throw new Error("Invalid token");const[i,r,o]=t;if(f(i+"."+r,n)!==o)throw new Error("Invalid token");const c=d(i);if("HS256"!==c.alg||"JWT"!==c.typ)throw new Error("Invalid token");const s=d(r);if(1e3*s.exp<Date.now()){const e=new Error("Token expired");throw e.name="TokenExpiredError",e}return s},h=function(e,n,t={}){const{expiresIn:i}=t;if(!i)throw new Error("expiresIn is required");const r=parseInt(Date.now()/1e3),o={...e,iat:r,exp:r+t.expiresIn},c=l({alg:"HS256",typ:"JWT"})+"."+l(o);return c+"."+f(c,n)},g=uniCloud.database(),C=g.command,E=g.collection("uni-id-users"),I=g.collection("uni-id-roles");async function _(e){const{tokenSecret:n,tokenExpiresIn:i,tokenExpiresThreshold:r}=this._getConfig();if(r>i)throw new Error("Config error, tokenExpiresThreshold should be less than tokenExpiresIn");let o;try{o=p(e,n)}catch(e){if("TokenExpiredError"===e.name)throw{errCode:t.TOKEN_EXPIRED};throw{errCode:t.CHECK_TOKEN_FAILED}}return o}async function k(e){const n=e.uid,i=(await E.doc(n).get()).data[0];if(!i)throw{errCode:t.CHECK_TOKEN_FAILED};if(i.valid_token_date&&i.valid_token_date>1e3*e.iat)throw{errCode:t.TOKEN_EXPIRED};const{role:r,permission:o}=await w(i);return T.call(this,{uid:n,role:r,permission:o})}async function w(e){if(!e)throw{errCode:t.ACCOUNT_NOT_EXISTS};!function(e){switch(e.status){case void 0:case 0:break;case 1:throw{errCode:t.ACCOUNT_BANNED};case 2:throw{errCode:t.ACCOUNT_AUDITING};case 3:throw{errCode:t.ACCOUNT_AUDIT_FAILED};case 4:throw{errCode:t.ACCOUNT_CLOSED}}}(e);const n=e.role||[];if(0===n.length)return{role:[],permission:[]};if(n.includes("admin"))return{role:["admin"],permission:[]};const i=await I.where({role_id:C.in(n)});var r;return{role:n,permission:(r=i.data.reduce((e,n)=>{n.permission&&e.push(...n.permission)},[]),Array.from(new Set(r)))}}async function m({uid:e,signContent:n,tokenSecret:t,tokenExpiresIn:i}={}){const r=Date.now(),o=h(n,t,{expiresIn:i});return await E.doc(e).update({last_login_ip:this._clientInfo.clientIP,last_login_date:r}),{token:o,tokenExpired:r+1e3*i}}async function T({uid:e,role:n,permission:i}={}){const{tokenSecret:r,tokenExpiresIn:o,tokenExpiresThreshold:c}=this._getConfig();if(!e)throw{errCode:t.PARAM_REQUIRED,errMsgValue:{param:"uid"}};if(c>o)throw new Error("Config error, tokenExpiresThreshold should be less than tokenExpiresIn");if(!n||!i){const t=(await E.doc(e).get()).data[0],r=await w(t);n=r.role,i=r.permission}if(!this.interceptorMap.has("customToken"))return m.call(this,{uid:e,signContent:{uid:e,role:n,permission:i},tokenSecret:r,tokenExpiresIn:o});const s=this.interceptorMap.get("customToken");if("function"==typeof s)throw new Error("Invalid custom token file");const a=await s({uid:e,role:n,permission:i});return m.call(this,{uid:e,signContent:a,tokenSecret:r,tokenExpiresIn:o})}var x=Object.freeze({__proto__:null,checkToken:async function(e,{autoRefresh:n=!0}={}){const t=await _.call(this,e),{tokenExpiresThreshold:i}=this._getConfig();if(!i||!n)return{code:0,errCode:0,...t};const r=Date.now();let o={};return 1e3*t.exp-r<1e3*i&&(o=await k.call(this,t)),{code:0,errCode:0,...t,...o}},createToken:async function({uid:e,role:n,permission:t}={}){return T.call(this,{uid:e,role:n,permission:t})},refreshToken:async function({token:e}={}){const n=await _.call(this,e);return{errCode:0,...await k.call(this,n)}}});const A=require("uni-config-center")({pluginId:"uni-id"});class O{constructor({context:e,clientInfo:n,config:t}={}){this._clientInfo=e?function(e){return{appId:e.APPID,platform:e.PLATFORM,locale:e.LOCALE,clientIP:e.CLIENTIP,deviceId:e.DEVICEID}}(e):n,this.config=t||this._getOriginConfig(),this.interceptorMap=new Map,A.hasFile("custom-token.js")&&this.setInterceptor("customToken",require(A.resolve("custom-token.js"))),this._i18n=uniCloud.initI18n({locale:this._clientInfo.locale,fallbackLocale:"zh-Hans",messages:a})}_t(...e){return this._i18n.t(...e)}_getOriginConfig(){if(A.hasFile("config.json")){let e;try{e=A.config()}catch(e){throw new Error("Invalid uni-id config file\n"+e.messages)}return Array.isArray(e)?e:e[0]?Object.values(e):e}throw new Error("Invalid uni-id config file")}_getAppConfig(){const e=this._getOriginConfig();return Array.isArray(e)?e.find(e=>e.dcloudAppid===this.clientInfo.appId)||e.find(e=>e.isDefaultConfig):e}_getPlatformConfig(){const e=this._getAppConfig();"app-plus"===this._clientInfo.platform&&(this._clientInfo.platform="app"),"h5"===this._clientInfo.platform&&(this._clientInfo.platform="web");const n=Object.assign({tokenExpiresIn:7200,tokenExpiresThreshold:1200,passwordErrorLimit:6,passwordErrorRetryTime:3600},e,e[this._clientInfo.platform]);return["tokenSecret","tokenExpiresIn"].forEach(e=>{if(!n||!n[e])throw new Error(`Config parameter missing, ${e} is required`)}),n}_getConfig(){return this._getPlatformConfig()}}for(const e in x)O.prototype[e]=x[e];function y(e){const n=new O(e);return new Proxy(n,{get(e,n){if(n in e&&0!==n.indexOf("_")){if("function"==typeof e[n])return(t=e[n],function(){let e;try{e=t.apply(this,arguments)}catch(e){if(c(e))return o.call(this,e),e;throw e}return i(e)?e.then(e=>(c(e)&&o.call(this,e),e),e=>{if(c(e))return o.call(this,e),e;throw e}):(c(e)&&o.call(this,e),e)}).bind(e);if("context"!==n&&"config"!==n)return e[n]}var t}})}O.prototype.createInstance=y;const N={createInstance:y};module.exports=N;
"use strict";var e,n=(e=require("crypto"))&&"object"==typeof e&&"default"in e?e.default:e;const t={TOKEN_EXPIRED:"uni-id-token-expired",CHECK_TOKEN_FAILED:"uni-id-check-token-failed",PARAM_REQUIRED:"uni-id-param-required",ACCOUNT_EXISTS:"uni-id-account-exists",ACCOUNT_NOT_EXISTS:"uni-id-account-not-exists",ACCOUNT_CONFLICT:"uni-id-account-conflict",ACCOUNT_BANNED:"uni-id-account-banned",ACCOUNT_AUDITING:"uni-id-account-auditing",ACCOUNT_AUDIT_FAILED:"uni-id-account-audit-failed",ACCOUNT_CLOSED:"uni-id-account-closed"};function i(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}const r={"uni-id-token-expired":30203,"uni-id-check-token-failed":30202};function o(e){const{errCode:n,errMsgValue:t}=e;e.errMsg=this._t(n,t),n in r&&(e.code=r[n])}function c(e){return"object"===(i=e,Object.prototype.toString.call(i).slice(8,-1).toLowerCase())&&e.errCode&&(n=e.errCode,Object.values(t).includes(n))&&!!e.errCode;var n,i}let s={"zh-Hans":{"uni-id-token-expired":"状态失效,token已过期","uni-id-check-token-failed":"token校验未通过","uni-id-param-required":"缺少参数: {param}","uni-id-account-exists":"此账号已注册","uni-id-account-not-exists":"此账号未注册","uni-id-account-conflict":"用户账号冲突","uni-id-account-banned":"从账号已封禁","uni-id-account-auditing":"此账号正在审核中","uni-id-account-audit-failed":"此账号审核失败","uni-id-account-closed":"此账号已注销"},en:{"uni-id-token-expired":"The login status is invalid, token has expired","uni-id-check-token-failed":"Check token failed","uni-id-param-required":"Parameter required: {param}","uni-id-account-exists":"Account exists","uni-id-account-not-exists":"Account does not exists","uni-id-account-conflict":"User account conflict","uni-id-account-banned":"Account has been banned","uni-id-account-auditing":"Account audit in progress","uni-id-account-audit-failed":"Account audit failed","uni-id-account-closed":"Account has been closed"}};try{const e=require.resolve("uni-config-center/uni-id/lang/index.js");s=function(e,n){const t=Object.keys(e);t.push(...Object.keys(n));const i={};for(let r=0;r<t.length;r++){const o=t[r];i[o]=Object.assign({},e[o],n[o])}return i}(s,require(e))}catch(e){}var a=s;function u(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function d(e){return JSON.parse((n=function(e){var n=4-(e=e.toString()).length%4;if(4!==n)for(var t=0;t<n;++t)e+="=";return e.replace(/-/g,"+").replace(/_/g,"/")}(e),Buffer.from(n,"base64").toString("utf-8")));var n}function l(e){return u((n=JSON.stringify(e),Buffer.from(n,"utf-8").toString("base64")));var n}function f(e,t){return u(n.createHmac("sha256",t).update(e).digest("base64"))}const p=function(e,n){if("string"!=typeof e)throw new Error("Invalid token");const t=e.split(".");if(3!==t.length)throw new Error("Invalid token");const[i,r,o]=t;if(f(i+"."+r,n)!==o)throw new Error("Invalid token");const c=d(i);if("HS256"!==c.alg||"JWT"!==c.typ)throw new Error("Invalid token");const s=d(r);if(1e3*s.exp<Date.now()){const e=new Error("Token expired");throw e.name="TokenExpiredError",e}return s},h=function(e,n,t={}){const{expiresIn:i}=t;if(!i)throw new Error("expiresIn is required");const r=parseInt(Date.now()/1e3),o={...e,iat:r,exp:r+t.expiresIn},c=l({alg:"HS256",typ:"JWT"})+"."+l(o);return c+"."+f(c,n)},g=uniCloud.database(),C=g.command,E=g.collection("uni-id-users"),I=g.collection("uni-id-roles");async function _(e){const{tokenSecret:n,tokenExpiresIn:i,tokenExpiresThreshold:r}=this._getConfig();if(r>i)throw new Error("Config error, tokenExpiresThreshold should be less than tokenExpiresIn");let o;try{o=p(e,n)}catch(e){if("TokenExpiredError"===e.name)throw{errCode:t.TOKEN_EXPIRED};throw{errCode:t.CHECK_TOKEN_FAILED}}return o}async function k(e){const n=e.uid,i=(await E.doc(n).get()).data[0];if(!i)throw{errCode:t.CHECK_TOKEN_FAILED};if(i.valid_token_date&&i.valid_token_date>1e3*e.iat)throw{errCode:t.TOKEN_EXPIRED};const{role:r,permission:o}=await w(i);return T.call(this,{uid:n,role:r,permission:o})}async function w(e){if(!e)throw{errCode:t.ACCOUNT_NOT_EXISTS};!function(e){switch(e.status){case void 0:case 0:break;case 1:throw{errCode:t.ACCOUNT_BANNED};case 2:throw{errCode:t.ACCOUNT_AUDITING};case 3:throw{errCode:t.ACCOUNT_AUDIT_FAILED};case 4:throw{errCode:t.ACCOUNT_CLOSED}}}(e);const n=e.role||[];if(0===n.length)return{role:[],permission:[]};if(n.includes("admin"))return{role:["admin"],permission:[]};const i=await I.where({role_id:C.in(n)});var r;return{role:n,permission:(r=i.data.reduce((e,n)=>{n.permission&&e.push(...n.permission)},[]),Array.from(new Set(r)))}}async function m({uid:e,signContent:n,tokenSecret:t,tokenExpiresIn:i}={}){const r=Date.now(),o=h(n,t,{expiresIn:i});return await E.doc(e).update({last_login_ip:this._clientInfo.clientIP,last_login_date:r}),{token:o,tokenExpired:r+1e3*i}}async function T({uid:e,role:n,permission:i}={}){const{tokenSecret:r,tokenExpiresIn:o,tokenExpiresThreshold:c}=this._getConfig();if(!e)throw{errCode:t.PARAM_REQUIRED,errMsgValue:{param:"uid"}};if(c>o)throw new Error("Config error, tokenExpiresThreshold should be less than tokenExpiresIn");if(!n||!i){const t=(await E.doc(e).get()).data[0],r=await w(t);n=r.role,i=r.permission}if(!this.interceptorMap.has("customToken"))return m.call(this,{uid:e,signContent:{uid:e,role:n,permission:i},tokenSecret:r,tokenExpiresIn:o});const s=this.interceptorMap.get("customToken");if("function"==typeof s)throw new Error("Invalid custom token file");const a=await s({uid:e,role:n,permission:i});return m.call(this,{uid:e,signContent:a,tokenSecret:r,tokenExpiresIn:o})}var x=Object.freeze({__proto__:null,checkToken:async function(e,{autoRefresh:n=!0}={}){const t=await _.call(this,e),{tokenExpiresThreshold:i}=this._getConfig();if(!i||!n)return{code:0,errCode:0,...t};const r=Date.now();let o={};return 1e3*t.exp-r<1e3*i&&(o=await k.call(this,t)),{code:0,errCode:0,...t,...o}},createToken:async function({uid:e,role:n,permission:t}={}){return T.call(this,{uid:e,role:n,permission:t})},refreshToken:async function({token:e}={}){const n=await _.call(this,e);return{errCode:0,...await k.call(this,n)}}});const A=require("uni-config-center")({pluginId:"uni-id"});class O{constructor({context:e,clientInfo:n,config:t}={}){this._clientInfo=e?function(e){return{appId:e.APPID,platform:e.PLATFORM,locale:e.LOCALE,clientIP:e.CLIENTIP,deviceId:e.DEVICEID}}(e):n,this.config=t||this._getOriginConfig(),this.interceptorMap=new Map,A.hasFile("custom-token.js")&&this.setInterceptor("customToken",require(A.resolve("custom-token.js"))),this._i18n=uniCloud.initI18n({locale:this._clientInfo.locale,fallbackLocale:"zh-Hans",messages:a})}_t(...e){return this._i18n.t(...e)}_getOriginConfig(){if(A.hasFile("config.json")){let e;try{e=A.config()}catch(e){throw new Error("Invalid uni-id config file\n"+e.messages)}return Array.isArray(e)?e:e[0]?Object.values(e):e}throw new Error("Invalid uni-id config file")}_getAppConfig(){const e=this._getOriginConfig();return Array.isArray(e)?e.find(e=>e.dcloudAppid===this.clientInfo.appId)||e.find(e=>e.isDefaultConfig):e}_getPlatformConfig(){const e=this._getAppConfig();"app-plus"===this._clientInfo.platform&&(this._clientInfo.platform="app"),"h5"===this._clientInfo.platform&&(this._clientInfo.platform="web");const n=Object.assign({tokenExpiresIn:7200,tokenExpiresThreshold:1200,passwordErrorLimit:6,passwordErrorRetryTime:3600},e,e[this._clientInfo.platform]);return["tokenSecret","tokenExpiresIn"].forEach(e=>{if(!n||!n[e])throw new Error(`Config parameter missing, ${e} is required`)}),n}_getConfig(){return this._getPlatformConfig()}}for(const e in x)O.prototype[e]=x[e];function y(e){const n=new O(e);return new Proxy(n,{get(e,n){if(n in e&&0!==n.indexOf("_")){if("function"==typeof e[n])return(t=e[n],function(){let e;try{e=t.apply(this,arguments)}catch(e){if(c(e))return o.call(this,e),e;throw e}return i(e)?e.then(e=>(c(e)&&o.call(this,e),e),e=>{if(c(e))return o.call(this,e),e;throw e}):(c(e)&&o.call(this,e),e)}).bind(e);if("context"!==n&&"config"!==n)return e[n]}var t}})}O.prototype.createInstance=y;const N={createInstance:y};module.exports=N;
## 1.0.1(2022-06-23)
新增,应用[pages_init](https://uniapp.dcloud.io/plugin/publish.html#pages-init)当导入插件到项目工程时,自动合并本插件的页面路由到项目的pages.json
## 1.0.0(2022-06-23)
正式版
......@@ -141,17 +141,17 @@
let servicesList = this.servicesList
let loginTypes = config.loginTypes
servicesList = servicesList.filter(item => {
servicesList = servicesList.filter(item => {
// #ifndef APP
//非app端去掉apple登
//非app端去掉apple登
if (item.id == 'apple') {
return false
}
// #endif
// #endif
// #ifdef APP
//去掉非ios系统上的apple登
//去掉非ios系统上的apple登
if (item.id == 'apple' && uni.getSystemInfoSync().osName != 'ios') {
return false
}
......@@ -220,9 +220,9 @@
console.log('出乎意料的情况,path:' + path);
}
},
async login_before(type, navigateBack = true) {
console.log(type);
async login_before(type, navigateBack = true) {
console.log(type);
//提示空实现
if (["qq",
"xiaomi",
......@@ -231,56 +231,56 @@
"facebook",
"google",
"alipay",
"douyin",
//H5端没有支持微信登
// #ifdef H5
"weixin"
"douyin",
//H5端没有支持微信登
// #ifdef H5
"weixin"
// #endif
].includes(type)) {
return uni.showToast({
title: '该登方式暂未实现,欢迎提交pr',
title: '该登方式暂未实现,欢迎提交pr',
icon: 'none'
});
}
}
//检查当前环境是否支持这种登录方式
// #ifdef APP
let isAppExist = true
await new Promise((callback) => {
plus.oauth.getServices(oauthServices => {
let index = oauthServices.findIndex(e => e.id == type)
if(index != -1){
isAppExist = oauthServices[index].nativeClient
callback()
}else{
return uni.showToast({
title: '当前设备不支持此登录,请选择其他登录方式',
icon: 'none'
});
}
}, err => {
throw new Error('获取服务供应商失败:' + JSON.stringify(err))
})
let isAppExist = true
await new Promise((callback) => {
plus.oauth.getServices(oauthServices => {
let index = oauthServices.findIndex(e => e.id == type)
if(index != -1){
isAppExist = oauthServices[index].nativeClient
callback()
}else{
return uni.showToast({
title: '当前设备不支持此登录,请选择其他登录方式',
icon: 'none'
});
}
}, err => {
throw new Error('获取服务供应商失败:' + JSON.stringify(err))
})
})
// #endif
if (
// #ifdef APP
!isAppExist
// #endif
//非app端使用了,app特有登录方式
// #ifndef APP
["univerify","apple"].includes(type)
// #endif
) {
return uni.showToast({
title: '当前设备不支持此登录,请选择其他登录方式',
icon: 'none'
});
}
// #endif
if (
// #ifdef APP
!isAppExist
// #endif
//非app端使用了,app特有登录方式
// #ifndef APP
["univerify","apple"].includes(type)
// #endif
) {
return uni.showToast({
title: '当前设备不支持此登录,请选择其他登录方式',
icon: 'none'
});
}
//判断是否需要弹出隐私协议授权框
console.log(type, this.agree);
let needAgreements = config.agreements.scope.includes('register')
......@@ -361,8 +361,8 @@
uni.login({
"provider": type,
"onlyAuthorize": true,
// #ifdef APP
"univerifyStyle": this.univerifyStyle,
// #ifdef APP
"univerifyStyle": this.univerifyStyle,
// #endif
success: async e => {
console.log(e);
......@@ -370,7 +370,7 @@
let res = await this.getUserInfo({
provider: "apple"
})
Object.assign(e.authResult, res.userInfo)
Object.assign(e.authResult, res.userInfo)
uni.hideLoading()
}
this.login(type == 'weixin' ? {
......@@ -378,7 +378,7 @@
} : e.authResult, type)
},
fail: async (err) => {
console.log(err);
console.log(err);
uni.hideLoading()
}
})
......@@ -390,17 +390,17 @@
});
//toLowerCase
let action = 'loginBy' + type.trim().toLowerCase().replace(type[0], type[0].toUpperCase())
const uniIdCo = uniCloud.importObject("uni-id-co",{
customUI:true
const uniIdCo = uniCloud.importObject("uni-id-co",{
customUI:true
})
uniIdCo[action](params).then(result => {
console.log("login-result", result);
uni.showToast({
title: '陆成功',
icon: 'none'
console.log("login-result", result);
uni.showToast({
title: '录成功',
icon: 'none'
});
// #ifdef MP-WEIXIN
//如果是微信小程序端的微信登陆,且为首次登陆,就弹出获取微信昵称+头像用于绑定资料
// #ifdef MP-WEIXIN
//如果是微信小程序端的微信登录,且为首次登录,就弹出获取微信昵称+头像用于绑定资料
if (type == 'weixin' && result.type == "register") {
loginSuccess({
...result,
......@@ -411,19 +411,19 @@
}
// #endif
loginSuccess(result)
})
})
.catch(e=>{
console.log(e);
uni.showModal({
content: e.message,
confirmText:"知道了",
showCancel: false
console.log(e);
uni.showModal({
content: e.message,
confirmText:"知道了",
showCancel: false
});
})
})
.finally(e => {
if (type == 'univerify') {
uni.closeAuthView()
}
}
uni.hideLoading()
})
},
......@@ -511,4 +511,4 @@
font-size: 10px;
width: 70px;
}
</style>
</style>
......@@ -5,16 +5,16 @@ export default {
登录类型 未列举到的或运行环境不支持的,将被自动隐藏。
如果需要在不同平台有不同的配置,直接用条件编译即可
*/
"loginTypes": [
// "qq",
// "xiaomi",
// "sinaweibo",
// "taobao",
// "facebook",
// "google",
// "alipay",
// "douyin",
"loginTypes": [
// "qq",
// "xiaomi",
// "sinaweibo",
// "taobao",
// "facebook",
// "google",
// "alipay",
// "douyin",
// #ifdef APP
"univerify",
// #endif
......@@ -31,7 +31,7 @@ export default {
"agreements": {
"serviceUrl": "https://xxx", //用户服务协议链接
"privacyUrl": "https://xxx", //隐私政策条款链接
// 哪些场景下显示,1.注册(包括登录并注册,如:微信登录、苹果登录、短信验证码登录)、2.登录(如:用户名密码登
// 哪些场景下显示,1.注册(包括登录并注册,如:微信登录、苹果登录、短信验证码登录)、2.登录(如:用户名密码登
"scope": ['register', 'login']
}
}
}
......@@ -15,12 +15,12 @@ export default async function() {
// 有打开调试模式的情况下
if (debug) {
// 1. 检查本地uni-id-pages中配置的登录方式,服务器端是否已经配置正确。否则提醒并引导去配置
//调用云对象,获取服务端已正确配置的登方式
//调用云对象,获取服务端已正确配置的登方式
let {
supportedLoginType
} = await uniIdCo.getSupportedLoginType()
console.log("supportedLoginType: " + JSON.stringify(supportedLoginType));
//登方式,服务端和客户端的映射关系
//登方式,服务端和客户端的映射关系
let data = {
smsCode: 'mobile-code',
univerify: 'univerify',
......@@ -32,10 +32,10 @@ export default async function() {
taobao: 'taobao',
facebook: 'facebook',
google: 'google',
alipay: 'alipay',
alipay: 'alipay',
apple:"apple"
}
//遍历客户端配置的登方式,与服务端比对。并在错误时抛出错误提示
//遍历客户端配置的登方式,与服务端比对。并在错误时抛出错误提示
let list = loginTypes.filter(type => !supportedLoginType.includes(data[type]))
if (list.length) {
console.error(
......@@ -45,7 +45,7 @@ export default async function() {
}
// #ifdef APP-PLUS
//如果uni-id-pages配置的登功能有一键登录,有则执行预登录(异步)
//如果uni-id-pages配置的登功能有一键登录,有则执行预登录(异步)
if (loginTypes.includes('univerify')) {
uni.preLogin({
provider: 'univerify',
......@@ -71,5 +71,5 @@ export default async function() {
});
}
// 解绑clientDB错误事件
//db.off('error', onDBError)
}
//db.off('error', onDBError)
}
{
"id": "uni-id-pages",
"displayName": "uni-id-pages",
"version": "1.0.1",
"version": "1.0.0",
"description": "云端一体简单、统一、可扩展的用户中心页面模版",
"keywords": [
"用户管理",
......
<!-- 短信验证码登页 -->
<!-- 短信验证码登页 -->
<template>
<view class="uni-content">
<!-- 顶部文字 -->
......
<!-- 免密登页 -->
<!-- 免密登页 -->
<template>
<view class="uni-content">
<!-- 顶部文字 -->
......
<!-- 账号密码登页 -->
<!-- 账号密码登页 -->
<template>
<view class="uni-content">
<!-- 顶部文字 -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册