// 获得用户列表 async getUserList() { const { ctx } = this; const query = ctx.request.body; const pageNo = query.pageNo; const pageSize = query.pageSize || this.app.config.pageSize; const userName = query.userName; const result = await ctx.service.user.getUserList(pageNo, pageSize, userName); ctx.body = this.app.result({ data: result, }); }
// 退出登录 async logout() { const { ctx } = this; const usertoken = ctx.cookies.get('usertoken', { encrypt: true, signed: true, }) || ''; if (!usertoken) throw new Error('退出登录:token不能为空'); await ctx.service.user.logout(usertoken); this.ctx.body = this.app.result({ data: {}, }); }
// 删除用户 async delete() { const { ctx } = this; const query = ctx.request.body; const id = query.id || ''; const usertoken = query.usertoken || ''; if (!id) throw new Error('删除用户:id不能为空'); const result = await ctx.service.user.delete(id, usertoken); ctx.body = this.app.result({ data: result, }); }
// 冻结解冻用户 async setIsUse() { const { ctx } = this; const query = ctx.request.body; const isUse = query.isUse || 0; const id = query.id || ''; const usertoken = query.usertoken || ''; if (!id) throw new Error('冻结解冻用户:id不能为空'); const result = await ctx.service.user.setIsUse(id, isUse, usertoken); ctx.body = this.app.result({ data: result, }); }
result.desc = '新浪微博权限验证失败, 请重试!'; } else { result = await ctx.service.user.githubRegister(getUserInfo.data.name, getUserInfo.data.idstr);
result.desc = 'github 权限验证失败, 请重试!'; } else { result = await ctx.service.user.githubRegister(userResult.data.login, userResult.data.node_id);
result.desc = '微信登录权限验证失败, 请重试!'; } else { result = await ctx.service.user.githubRegister(getUserMsg.data.nickname, getUserMsg.data.openid);
// 用户登录 async login() { const { ctx } = this; const query = ctx.request.body; const userName = query.userName; const passWord = query.passWord; if (!userName) throw new Error('用户登录:userName不能为空'); if (!passWord) throw new Error('用户登录:passWord不能为空'); const result = await ctx.service.user.login(userName, passWord); ctx.body = this.app.result({ data: result, }); }
/** * 设置用户默认地址 */ async setDefaultAddress() { const { ctx } = this; const uuid = await ctx.service.user.customer.address.setDefault(ctx.request.body); this.success(uuid); }
// destroy======================================================================================================> async destroy(_id) { const { ctx, service } = this const user = await ctx.service.user.find(_id) if (!user) { ctx.throw(404, 'user not found') } return ctx.model.User.findByIdAndRemove(_id) }
/** * 新增用户地址 */ async saveNewAddress() { const { ctx } = this; const rule = { address: 'object', }; ctx.validate(rule); const uuid = await ctx.service.user.customer.address.saveNew(ctx.request.body); this.success(uuid); }
/** * 根据uuid获取商家 */ async getMerchant() { const { ctx } = this; const { uuid } = ctx.query; const merchant = await ctx.service.user.merchant.get(uuid); this.success(merchant); }
// 更新头像 async resetAvatar(values) { const {ctx, service} = this await service.upload.create(values) // 获取当前用户 const _id = ctx.state.user.data._id const user = await service.user.find(_id) if (!user) { ctx.throw(404, 'user is not found') } return service.user.findByIdAndUpdate(_id, {avatar: values.url}) }
// 用户注册 async register() { const { ctx } = this; const query = ctx.request.body; const userName = query.userName; const passWord = query.passWord; if (!userName) throw new Error('用户登录:userName不能为空'); if (!passWord) throw new Error('用户登录:passWord不能为空'); const result = await ctx.service.user.register(userName, passWord); ctx.body = this.app.result({ data: result, }); }
// 删除所选用户(条件id[]) async removes() { const { ctx, service } = this // 组装参数 // const payload = ctx.queries.id const { id } = ctx.request.body const payload = id.split(',') || [] // 调用 Service 进行业务处理 const result = await service.user.removes(payload) // 设置响应内容和响应状态码 ctx.helper.success({ctx}) }