diff --git a/pages.json b/pages.json index dc3cc928b4a24f979f731b770c9098f76eb91e0f..bddae4bb0baa472ffdf3ee6cde29f93bb933fae4 100644 --- a/pages.json +++ b/pages.json @@ -187,6 +187,27 @@ "navigationBarBackgroundColor": "#FFFFFF", "backgroundColor": "#F8F8F8" }, + "condition": { + "list": [{ + "path": "uni_modules/uni-login-page/pages/index/index", + "style": { + "navigationBarTitleText": "", + "app-plus": { + "animationType": "none", + "popGesture": "none", + "titleNView": { + "buttons": [{ + "text": "帮助", + "type": "none", + "fontSize": "16px", + "width": "60px" + }] + } + } + } + }], + "current": 0 + }, "tabBar": { "color": "#7A7E83", "selectedColor": "#007AFF", diff --git a/pages/ucenter/edit/edit.nvue b/pages/ucenter/edit/edit.nvue index 2100f9d2372c83078c1f83481bf71d53157fce73..86530d24dbc80dc99888334aa362dc9cd1975983 100644 --- a/pages/ucenter/edit/edit.nvue +++ b/pages/ucenter/edit/edit.nvue @@ -20,6 +20,7 @@ } from 'vuex'; const db = uniCloud.database(); + const userTable = db.collection('uni-id-users') export default { data() { return { @@ -60,9 +61,7 @@ * value 更新后的用户字段值 */ uploadUserInfo(data){ - db.collection('uni-id-users').where({ - _id: this.userInfo._id - }) + userTable.doc(this.userInfo._id) .update(data) .then(res=>{ console.log(res); diff --git a/pages/ucenter/ucenter.vue b/pages/ucenter/ucenter.vue index 7bc252052b47d9b9877f205ce9afbcfa836fcce8..b469dc614a9caea237f7ac010e0dcf5ddf5a39cb 100644 --- a/pages/ucenter/ucenter.vue +++ b/pages/ucenter/ucenter.vue @@ -114,11 +114,10 @@ checkUpdate(); }, goLogin() { - uni.navigateTo({ - url: './edit/edit' - }) + // uni.navigateTo({ + // url: './edit/edit' + // }) - return; if (!this.login) { console.log('点击前往登录'); uni.navigateTo({ diff --git a/uniCloud-aliyun/cloudfunctions/user-center/package-lock.json b/uniCloud-aliyun/cloudfunctions/user-center/package-lock.json deleted file mode 100644 index e274744d735b315d437cf1ca8e6ccb2d640be3e7..0000000000000000000000000000000000000000 --- a/uniCloud-aliyun/cloudfunctions/user-center/package-lock.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "user-center", - "version": "1.0.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "uni-captcha": "file:../../../uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha", - "uni-id": "file:../../../uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id" - } - }, - "../../../uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha": { - "version": "0.1.0", - "license": "Apache-2.0" - }, - "../../../uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id": { - "version": "3.0.8", - "license": "Apache-2.0", - "dependencies": { - "uni-config-center": "file:../../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center" - } - }, - "node_modules/uni-captcha": { - "resolved": "../../../uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha", - "link": true - }, - "node_modules/uni-id": { - "resolved": "../../../uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id", - "link": true - } - }, - "dependencies": { - "uni-captcha": { - "version": "file:../../../uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha" - }, - "uni-id": { - "version": "file:../../../uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id", - "requires": { - "uni-config-center": "file:../../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center" - } - } - } -} diff --git a/uniCloud-aliyun/cloudfunctions/user-center/package.json b/uniCloud-aliyun/cloudfunctions/user-center/package.json deleted file mode 100644 index 7b569dc56655f160526dc2cc2d31c20849b0f6b4..0000000000000000000000000000000000000000 --- a/uniCloud-aliyun/cloudfunctions/user-center/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "user-center", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "uni-captcha": "file:../../../uni_modules/uni-captcha/uniCloud/cloudfunctions/common/uni-captcha", - "uni-id": "file:../../../uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id" - } -} diff --git a/uniCloud-aliyun/database/uni-id-users.schema.json b/uniCloud-aliyun/database/uni-id-users.schema.json index d990f78f1dd15c38f8ea75d7238f457698ce735a..cec2f1af52c4c2c581e4417eabbb646d0eef03ae 100644 --- a/uniCloud-aliyun/database/uni-id-users.schema.json +++ b/uniCloud-aliyun/database/uni-id-users.schema.json @@ -3,7 +3,7 @@ "permission": { "read": true, "create": false, - "update": "doc.uid == auth.uid", + "update": "doc._id == auth.uid", "delete": false }, "properties": { diff --git a/uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/config.json b/uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/config.json index e5cb04060ed8875d7d4e3055a5df6b07a1aa0344..ef6a18d6c6bfee95aaea1328f5ca986a4226b6ed 100644 --- a/uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/config.json +++ b/uni_modules/uni-id/uniCloud/cloudfunctions/common/uni-id/config.json @@ -44,13 +44,9 @@ "smsSecret": "d6c424b702d73baa3b6e1a1452469213" }, "univerify":{ - // "appid": "__UNI__GameCat", - // "apiKey":"c5f80ebad34aaf0ae22958d866287521", - // "apiSecret":"f921890ca9c248273eadaf9b4137cf5c" - - "appid": "__UNI__BC54A00", - "apiKey":"d1e36bcd497b3795434d900dcfdd44dc", - "apiSecret":"2feb378ff1114362b20ac179b572293e" + "appid": "__UNI__GameCat", + "apiKey":"c5f80ebad34aaf0ae22958d866287521", + "apiSecret":"f921890ca9c248273eadaf9b4137cf5c" } } } diff --git a/uni_modules/uni-quick-login/components/uni-quick-login/uni-quick-login.vue b/uni_modules/uni-quick-login/components/uni-quick-login/uni-quick-login.vue index cedba707f90767d2adfccd9a669efd3315e67067..4c20019f0fe834ce339c68f2b237eea5dfd528ff 100644 --- a/uni_modules/uni-quick-login/components/uni-quick-login/uni-quick-login.vue +++ b/uni_modules/uni-quick-login/components/uni-quick-login/uni-quick-login.vue @@ -1,8 +1,8 @@ @@ -14,37 +14,61 @@ config: { "weixin": { "text": "微信登陆", - "logo": "../../static/login/img/weixin.png" + "logo": "../../static/login/img/weixin.png", + "isChecked":true }, + "apple": { + "text": "苹果登陆", + "logo": "../../static/login/img/apple.png", + "isChecked":true + }, + "univerify": { + "text": "一键登陆", + "logo": "../../static/login/img/univerify.png", + "isChecked":true + }, "qq": { "text": "QQ登陆", - "logo": "../../static/login/img/qq.png" + "logo": "../../static/login/img/qq.png", + "isChecked":false //暂未提供该登陆方式的接口示例 }, "xiaomi": { "text": "小米登陆", - "logo": "../../static/login/img/qq.png" - }, - "apple": { - "text": "苹果登陆", - "logo": "../../static/login/img/apple.png" + "logo": "../../static/login/img/qq.png", + "isChecked":false //暂未提供该登陆方式的接口示例 }, "sinaweibo": { "text": "微博登录", - "logo": "../../static/login/img/sinaweibo.png" + "logo": "../../static/login/img/sinaweibo.png", + "isChecked":false //暂未提供该登陆方式的接口示例 }, - "univerify": { - "text": "一键登陆", - "logo": "../../static/login/img/univerify.png" - } + }, - providerList: [], + providerList: [], + oauthServices:[], univerifyStyle: { "fullScreen": true, // 是否全屏显示,true表示全屏模式,false表示非全屏模式,默认值为false。 "backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff } } }, - mounted() { + mounted() { + //获取当前环境能用的快捷登陆方式 + // #ifdef APP-PLUS + plus.oauth.getServices(oauthServices=>{ + this.oauthServices = oauthServices + console.log(oauthServices); + },err=>{ + uni.showModal({ + title: '获取服务供应商失败:' +JSON.stringify(err), + showCancel: false, + confirmText: '知道了' + }); + console.error('获取服务供应商失败:' + JSON.stringify(err)); + }) + // #endif + + /* uni.getProvider({ "service": "oauth", success: res => { @@ -57,11 +81,20 @@ console.error('获取服务供应商失败:' + JSON.stringify(err)); } }) + */ }, methods: { login(type) { - // #ifndef H5 + let oauthService = this.oauthServices.find((service) => service.id == type) + // #ifdef APP-PLUS uni.showLoading({mask: true}); + if(type=='weixin'){ + oauthService.authorize(({code})=>{ + console.log(code); + this.quickLogin({code},type) + }) + } + uni.login({ "provider": type, "univerifyStyle":this.univerifyStyle, @@ -77,21 +110,24 @@ uni.hideLoading() console.log(err); if(err.errCode===30002){ - console.log('你手动关闭了,一键登陆'); + console.log('在一键登陆界面,点击其他登陆方式'); + } + if(err.errCode===30003){ + uni.navigateBack() } } }) // #endif }, - quickLogin(authResult,type){ + quickLogin(params,type){ //请勿直接使用authResult中的unionid或openid直接用于登陆,前端的数据都是不可靠的 - console.log({...authResult,type}); + console.log({params,type}); uniCloud.callFunction({//联网验证登陆 - "name": "user", + "name": "user-center", "data": { - "action": "quickLogin", - "params": {...authResult,type} + "action": "login_by_"+type, + params }, success: (e) => { console.log(e.result); diff --git a/uniCloud-aliyun/cloudfunctions/user-center/index.js b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/index.js similarity index 80% rename from uniCloud-aliyun/cloudfunctions/user-center/index.js rename to uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/index.js index 2e71f92ecdf47557841e4ee55f4eb065f803b9ee..c743f944b237a6983c30cb2d9ca585766308feee 100644 --- a/uniCloud-aliyun/cloudfunctions/user-center/index.js +++ b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/index.js @@ -3,37 +3,17 @@ const uniID = require('uni-id') const uniCaptcha = require('uni-captcha') const db = uniCloud.database() const dbCmd = db.command -exports.main = async (event, context) => { - let params = event.params || {} - // 登录记录 - const loginLog = async (res = {}, type = 'login') => { - const now = Date.now() - const uniIdLogCollection = db.collection('uni-id-log') - let logData = { - deviceId: params.deviceId || context.DEVICEID, - ip: params.ip || context.CLIENTIP, - type, - ua: context.CLIENTUA, - create_date: now - }; - - Object.assign(logData, - res.code === 0 ? { - user_id: res.uid, - state: 1 - } : { - state: 0 - }) - - return uniIdLogCollection.add(logData) - } - - const getNeedCaptcha = async () => { - const now = Date.now() - // 查询是否在 {2小时} 内 {前2条} 有 {登录失败} 数据,来确定是否需要验证码 - const recordSize = 2; - const recordDate = 120 * 60 * 1000; - +exports.main = async (event, context) => { + //event为客户端上传的参数 + console.log('event : ' + event) + let params = event.params || {} + + //防止黑客恶意破解登陆,连续登陆失败一定次数后,需要用户提供验证码 + const getNeedCaptcha = async () => { + //当用户最近“2小时内(recordDate)”登陆失败达到2次(recordSize)时。要求用户提交验证码 + const now = Date.now(), + recordDate = 120 * 60 * 1000, + recordSize = 2; const uniIdLogCollection = db.collection('uni-id-log') let recentRecord = await uniIdLogCollection.where({ deviceId: params.deviceId || context.DEVICEID, @@ -43,38 +23,57 @@ exports.main = async (event, context) => { .orderBy('create_date', 'desc') .limit(recordSize) .get(); - return recentRecord.data.filter(item => item.state === 0).length === recordSize; } - - //event为客户端上传的参数 - console.log('event : ' + event) - - let payload = {} + + //设置某些模块不需要token(也就是登陆成功后)才能操作,如果需要token就获取当前操作账户的uid let noCheckAction = [ - 'register', 'loginByWeixin', 'checkToken', - 'login', 'logout', 'sendSmsCode', - 'loginBySms', 'inviteLogin', 'loginByUniverify', - 'loginByApple', 'createCaptcha', 'verifyCaptcha', - 'refreshCaptcha' - ] - - if (noCheckAction.indexOf(event.action) === -1) { + 'register', 'checkToken','login', 'logout', 'sendSmsCode', + 'createCaptcha', 'verifyCaptcha','refreshCaptcha', 'inviteLogin', + 'login_by_weixin','login_by_univerify','login_by_apple','loginBySms' + ] + console.log(event.action); + if (!noCheckAction.includes(event.action)) { if (!event.uniIdToken) { return { code: 403, msg: '缺少token' } - } - payload = await uniID.checkToken(event.uniIdToken) + } + let payload = await uniID.checkToken(event.uniIdToken) if (payload.code && payload.code > 0) { return payload } params.uid = payload.uid + } + + + //记录成功登陆的日志 + const loginLog = async (res = {}, type = 'login') => { + const now = Date.now() + const uniIdLogCollection = db.collection('uni-id-log') + let logData = { + deviceId: params.deviceId || context.DEVICEID, + ip: params.ip || context.CLIENTIP, + type, + ua: context.CLIENTUA, + create_date: now + }; + + Object.assign(logData, + res.code === 0 ? { + user_id: res.uid, + state: 1 + } : { + state: 0 + }) + + return uniIdLogCollection.add(logData) } + + let res = {} - switch (event.action) { case 'register': res = await uniID.register(params); @@ -95,10 +94,17 @@ exports.main = async (event, context) => { } res.needCaptcha = needCaptcha; - break; - case 'loginByWeixin': - res = await uniID.loginByWeixin(params); - loginLog(res) + break; + case 'login_by_weixin': + res = await uniID.loginByWeixin(params); + loginLog(res) + break; + case 'login_by_univerify': + res = await uniID.loginByUniverify(params) + break; + case 'login_by_apple': + res = await uniID.loginByApple(params) + loginLog(res) break; case 'checkToken': res = await uniID.checkToken(event.uniIdToken); @@ -175,13 +181,6 @@ exports.main = async (event, context) => { case 'getInvitedUser': res = await uniID.getInvitedUser(params) break; - case 'loginByUniverify': - res = await uniID.loginByUniverify(params) - break; - case 'loginByApple': - res = await uniID.loginByApple(params) - loginLog(res) - break; case 'updatePwd': res = await uniID.updatePwd({ uid: params.uid, diff --git a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/package-lock.json b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/package-lock.json similarity index 98% rename from uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/package-lock.json rename to uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/package-lock.json index 7e3037fa82ddad8ccaa8db9579840018c4cfb720..4b651534c38e4045b51eca7c345a208c3d49ac45 100644 --- a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/package-lock.json +++ b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/package-lock.json @@ -1,5 +1,5 @@ { - "name": "user", + "name": "user-center", "version": "1.0.0", "lockfileVersion": 2, "requires": true, diff --git a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/package.json b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/package.json similarity index 95% rename from uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/package.json rename to uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/package.json index 965bf274cb22107b31b692a78c0e33eaee48e095..0d50d88175e3e3b187d207dea4f3380a851e72af 100644 --- a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/package.json +++ b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user-center/package.json @@ -1,5 +1,5 @@ { - "name": "user", + "name": "user-center", "version": "1.0.0", "description": "", "main": "index.js", diff --git a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/index.js b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/index.js deleted file mode 100644 index f28594b7132ce2d8c353dd0e86206fd23f33019f..0000000000000000000000000000000000000000 --- a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/index.js +++ /dev/null @@ -1,82 +0,0 @@ -'use strict'; -const uniID = require('uni-id') -const uniCaptcha = require('uni-captcha') -const db = uniCloud.database() -const dbCmd = db.command -let params,context,res; -class User { - async quickLogin(){ - let {access_token,openid,type} = params - switch (type){ - case 'weixin': - let userinfo_res = await uniCloud.httpclient.request('https://api.weixin.qq.com/sns/userinfo', - { - method: 'GET', - dataType:"json", - data:{ access_token,openid} - }); - return userinfo_res.data//根据access_token,openid得到userinfo - //检查是否已经注册...待续... - break; - case 'univerify': - return uniID.loginByUniverify({access_token,openid}) - break; - case 'apple': - return await uniID.loginByApple(params) - break; - default: - return {"code":100,"msg":"暂不提供"+type+"登陆的云端接口演示"} - break; - } - } - async sendSmsCode(){ - // 简单限制一下客户端调用频率 - const ipLimit = await db.collection('uni-verify').where({ - ip: context.CLIENTIP, - created_at: dbCmd.gt(Date.now() - 60000) - }).get() - if (ipLimit.data.length > 0) { - return { - code: 429, - msg: '请求过于频繁' - } - } - const templateId = '11753' // 替换为自己申请的模板id - if (!templateId) { - return { - code: 500, - msg: 'sendSmsCode需要传入自己的templateId,参考https://uniapp.dcloud.net.cn/uniCloud/uni-id?id=sendsmscode' - } - } - const randomStr = '00000' + Math.floor(Math.random() * 1000000) - const code = randomStr.substring(randomStr.length - 6) - return await uniID.sendSmsCode({ - mobile: params.mobile, - code, - type: params.type, - templateId - }) - } -} -const userClass = new User(); -exports.main = async (event, ctx) => { - [{params},context] = [event,ctx] - //1.判断需要token的action是否有token - /*let noCheckAction = ['register', 'loginByWeixin', 'checkToken','login', 'logout', 'sendSmsCode','loginBySms', 'inviteLogin', 'loginByUniverify','loginByApple', 'createCaptcha', 'verifyCaptcha','refreshCaptcha'] - if(!noCheckAction.includes(event.action)) { - if (!event.uniIdToken) { - return {"code":403,"msg":"缺少token"} - } - let payload = {} - payload = await uniID.checkToken(event.uniIdToken) - if (payload.code && payload.code > 0) { - return payload - } - params.uid = payload.uid - }*/ - try{ - return await userClass[event.action]()||res; - }catch(err){ - return {"code":404,"msg":err} - } -} \ No newline at end of file diff --git a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/user.param.json b/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/user.param.json deleted file mode 100644 index 52bda1ee0c86991669653ab6a24175fbc11c08e5..0000000000000000000000000000000000000000 --- a/uni_modules/uni-quick-login/uniCloud/cloudfunctions/user/user.param.json +++ /dev/null @@ -1,9 +0,0 @@ -// 本文件中的json内容将在云函数【运行】时作为参数传给云函数。 -// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/quickstart?id=runparam -{ - "action": "sendSmsCode", - "params": { - "mobile":"17769516081", - "type":"register" - } -}