提交 ce3348ac 编写于 作者: 雪洛's avatar 雪洛

fix: permission error

上级 f6e4ba76
...@@ -7,6 +7,9 @@ module.exports = { ...@@ -7,6 +7,9 @@ module.exports = {
// permission: [] // 允许进行此操作的权限,包含任一权限均可操作。 // permission: [] // 允许进行此操作的权限,包含任一权限均可操作。
// 权限角色均配置时,用户拥有任一权限或任一角色均可操作 // 权限角色均配置时,用户拥有任一权限或任一角色均可操作
}, },
updateUser: {
role: ['admin']
},
authorizeAppLogin: { authorizeAppLogin: {
role: ['admin'] role: ['admin']
}, },
......
...@@ -18,10 +18,10 @@ const PasswordUtils = require('../../lib/utils/password') ...@@ -18,10 +18,10 @@ const PasswordUtils = require('../../lib/utils/password')
* @param {String} params.nickname 昵称 * @param {String} params.nickname 昵称
* @param {Array} params.authorizedApp 允许登录的AppID列表 * @param {Array} params.authorizedApp 允许登录的AppID列表
* @param {Array} params.role 用户角色列表 * @param {Array} params.role 用户角色列表
* @param {String} params.mobile 手机号 * @param {String} params.mobile 手机号
* @param {String} params.email 邮箱 * @param {String} params.email 邮箱
* @param {Array} params.tags 用户标签 * @param {Array} params.tags 用户标签
* @param {Number} params.status 用户状态 * @param {Number} params.status 用户状态
* @returns * @returns
*/ */
module.exports = async function (params = {}) { module.exports = async function (params = {}) {
...@@ -71,7 +71,9 @@ module.exports = async function (params = {}) { ...@@ -71,7 +71,9 @@ module.exports = async function (params = {}) {
} = params } = params
const userMatched = await findUser({ const userMatched = await findUser({
userQuery: { userQuery: {
username username,
mobile,
email
}, },
authorizedApp authorizedApp
}) })
...@@ -89,8 +91,7 @@ module.exports = async function (params = {}) { ...@@ -89,8 +91,7 @@ module.exports = async function (params = {}) {
} = passwordUtils.generatePasswordHash({ } = passwordUtils.generatePasswordHash({
password password
}) })
const data = {
await userCollection.add({
username, username,
password: passwordHash, password: passwordHash,
password_secret_version: version, password_secret_version: version,
...@@ -101,9 +102,17 @@ module.exports = async function (params = {}) { ...@@ -101,9 +102,17 @@ module.exports = async function (params = {}) {
email, email,
tags: tags || [], tags: tags || [],
status status
}) }
if (email) {
data.email_confirmed = 1
}
if (mobile) {
data.mobile_confirmed = 1
}
await userCollection.add(data)
return { return {
errCode: 0 errCode: 0,
errMsg: ''
} }
} }
...@@ -13,20 +13,21 @@ const PasswordUtils = require('../../lib/utils/password') ...@@ -13,20 +13,21 @@ const PasswordUtils = require('../../lib/utils/password')
* 修改用户 * 修改用户
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#update-user * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#update-user
* @param {Object} params * @param {Object} params
* @param {String} params.id 要更新的用户id * @param {String} params.uid 要更新的用户id
* @param {String} params.username 用户名 * @param {String} params.username 用户名
* @param {String} params.password 密码 * @param {String} params.password 密码
* @param {String} params.nickname 昵称 * @param {String} params.nickname 昵称
* @param {Array} params.authorizedApp 允许登录的AppID列表 * @param {Array} params.authorizedApp 允许登录的AppID列表
* @param {Array} params.role 用户角色列表 * @param {Array} params.role 用户角色列表
* @param {String} params.mobile 手机号 * @param {String} params.mobile 手机号
* @param {String} params.email 邮箱 * @param {String} params.email 邮箱
* @param {Array} params.tags 用户标签 * @param {Array} params.tags 用户标签
* @param {Number} params.status 用户状态 * @param {Number} params.status 用户状态
* @returns * @returns
*/ */
module.exports = async function (params = {}) { module.exports = async function (params = {}) {
const schema = { const schema = {
uid: 'string',
username: 'username', username: 'username',
password: { password: {
required: false, required: false,
...@@ -65,7 +66,7 @@ module.exports = async function (params = {}) { ...@@ -65,7 +66,7 @@ module.exports = async function (params = {}) {
this.middleware.validate(params, schema) this.middleware.validate(params, schema)
const { const {
id, uid,
username, username,
password, password,
authorizedApp, authorizedApp,
...@@ -78,7 +79,7 @@ module.exports = async function (params = {}) { ...@@ -78,7 +79,7 @@ module.exports = async function (params = {}) {
} = params } = params
// 更新的用户数据字段 // 更新的用户数据字段
const collection = { const data = {
username, username,
dcloud_appid: authorizedApp || [], dcloud_appid: authorizedApp || [],
nickname, nickname,
...@@ -97,7 +98,7 @@ module.exports = async function (params = {}) { ...@@ -97,7 +98,7 @@ module.exports = async function (params = {}) {
}, },
authorizedApp authorizedApp
}) })
if (userMatched.filter(user => user._id !== id).length) { if (userMatched.filter(user => user._id !== uid).length) {
throw { throw {
errCode: ERROR.ACCOUNT_EXISTS errCode: ERROR.ACCOUNT_EXISTS
} }
...@@ -115,11 +116,11 @@ module.exports = async function (params = {}) { ...@@ -115,11 +116,11 @@ module.exports = async function (params = {}) {
password password
}) })
collection.passwordHash = passwordHash data.password = passwordHash
collection.password = password data.password_secret_version = version
} }
await userCollection.where({_id: id}).update(collection) await userCollection.doc(uid).update(data)
return { return {
errCode: 0 errCode: 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册