正在显示
5 个修改的文件
包含
108 行增加
和
16 行删除
controller/meetingController.js
0 → 100644
| 1 | +var userModel = require('../model/userModel'); | ||
| 2 | +var saitMd5 = require('../util/saltMD5') | ||
| 3 | +var status = require('../util/resTemplate') | ||
| 4 | +const uuid = require('../util/UuidUtil') | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +var meetingController =function (){ | ||
| 8 | + | ||
| 9 | +}; | ||
| 10 | + | ||
| 11 | +meetingController.prototype.createMeeting = async(ctx,next)=>{ | ||
| 12 | + try { | ||
| 13 | + | ||
| 14 | + } catch (error) { | ||
| 15 | + | ||
| 16 | + } | ||
| 17 | +} |
| @@ -17,6 +17,7 @@ var userController =function (){ | @@ -17,6 +17,7 @@ var userController =function (){ | ||
| 17 | * @param {object} next | 17 | * @param {object} next |
| 18 | */ | 18 | */ |
| 19 | userController.prototype.addUser = async(ctx, next) =>{ | 19 | userController.prototype.addUser = async(ctx, next) =>{ |
| 20 | + try{ | ||
| 20 | var params = ctx.request.body; | 21 | var params = ctx.request.body; |
| 21 | const pw = saitMd5.md5AddSalt(params.password) | 22 | const pw = saitMd5.md5AddSalt(params.password) |
| 22 | 23 | ||
| @@ -31,16 +32,24 @@ userController.prototype.addUser = async(ctx, next) =>{ | @@ -31,16 +32,24 @@ userController.prototype.addUser = async(ctx, next) =>{ | ||
| 31 | var user = { | 32 | var user = { |
| 32 | loginName:params.loginName, | 33 | loginName:params.loginName, |
| 33 | password:pw.md5Pass, | 34 | password:pw.md5Pass, |
| 35 | + companyName:params.companyName, | ||
| 36 | + userName:params.userName, | ||
| 34 | salt:pw.salt, | 37 | salt:pw.salt, |
| 35 | - userType:params.type | 38 | + userType:params.userType, |
| 39 | + userRole:params.userRole, | ||
| 40 | + userEmail:params.userEmail, | ||
| 41 | + userMobile:params.userMobile, | ||
| 42 | + content:params.content, | ||
| 43 | + endTime:new Date(params.endTime), | ||
| 44 | + groupId:params.groupId | ||
| 36 | } | 45 | } |
| 37 | - | ||
| 38 | - try{ | ||
| 39 | - return await userService.addUser(user) | 46 | + return await userService.addUser(user) |
| 40 | }catch (e){ | 47 | }catch (e){ |
| 41 | throw new Error(e); | 48 | throw new Error(e); |
| 42 | } | 49 | } |
| 43 | } | 50 | } |
| 51 | + | ||
| 52 | + | ||
| 44 | /** | 53 | /** |
| 45 | * 用户登录 | 54 | * 用户登录 |
| 46 | */ | 55 | */ |
| @@ -62,7 +71,11 @@ userController.prototype.login = async(ctx, next) =>{ | @@ -62,7 +71,11 @@ userController.prototype.login = async(ctx, next) =>{ | ||
| 62 | token:userData.token, | 71 | token:userData.token, |
| 63 | createTime:userData.createTime | 72 | createTime:userData.createTime |
| 64 | } | 73 | } |
| 65 | - return userBack; | 74 | + if(!userData.code){ |
| 75 | + return userBack; | ||
| 76 | + }else{ | ||
| 77 | + return userData; | ||
| 78 | + } | ||
| 66 | }catch (we){ | 79 | }catch (we){ |
| 67 | throw new Error(we) | 80 | throw new Error(we) |
| 68 | } | 81 | } |
| @@ -116,4 +129,20 @@ userController.prototype.delUserByUserId = async(ctx,next) => { | @@ -116,4 +129,20 @@ userController.prototype.delUserByUserId = async(ctx,next) => { | ||
| 116 | } | 129 | } |
| 117 | } | 130 | } |
| 118 | 131 | ||
| 132 | + | ||
| 133 | +userController.prototype.resetPasswordByUserId = async(ctx,next) =>{ | ||
| 134 | + const userId = ctx.params.userId; | ||
| 135 | + const pw = saitMd5.md5AddSalt('123056') | ||
| 136 | + | ||
| 137 | + if(!userId){ | ||
| 138 | + return status.paramError('userId'); | ||
| 139 | + } | ||
| 140 | + try { | ||
| 141 | + let deluser = userService.resetPasswordByUserId(userId,pw); | ||
| 142 | + return deluser | ||
| 143 | + } catch (error) { | ||
| 144 | + throw new Error(error) | ||
| 145 | + } | ||
| 146 | +} | ||
| 147 | + | ||
| 119 | module.exports = new userController(); | 148 | module.exports = new userController(); |
routes/meeting.js
0 → 100644
| 1 | +const router = require('koa-router')() | ||
| 2 | +var userModel = require('../model/userModel'); | ||
| 3 | +var saitMd5 = require('../util/saltMD5') | ||
| 4 | +var meetingContoller = require('../controller/meetingController') | ||
| 5 | +var status = require('../util/resTemplate') | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +router.prefix('/meeting') | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +router.post('/createMeeting', async (ctx, next) => { | ||
| 12 | + try{ | ||
| 13 | + var data = await meetingContoller.createMeeting(ctx, next); | ||
| 14 | + status.successTemp(200,data); | ||
| 15 | + }catch(e){ | ||
| 16 | + const err = {code:0,msg:e.message} | ||
| 17 | + status.catchError(400,e.message); | ||
| 18 | + } | ||
| 19 | + }) | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + module.exports = router | ||
| 23 | + |
| @@ -7,9 +7,8 @@ router.prefix('/users') | @@ -7,9 +7,8 @@ router.prefix('/users') | ||
| 7 | router.post('/addUser',async (ctx, next) => { | 7 | router.post('/addUser',async (ctx, next) => { |
| 8 | try{ | 8 | try{ |
| 9 | var data = await userContoller.addUser(ctx, next); | 9 | var data = await userContoller.addUser(ctx, next); |
| 10 | - status.successTemp(200,data); | 10 | + status.successTemp(ctx,200,data); |
| 11 | }catch(e){ | 11 | }catch(e){ |
| 12 | - const err = {code:0,msg:e.message} | ||
| 13 | status.catchError(400,e.message); | 12 | status.catchError(400,e.message); |
| 14 | } | 13 | } |
| 15 | }) | 14 | }) |
| @@ -41,6 +40,16 @@ router.put('/updateUserByUserId/:userId',async(ctx, next)=>{ | @@ -41,6 +40,16 @@ router.put('/updateUserByUserId/:userId',async(ctx, next)=>{ | ||
| 41 | } | 40 | } |
| 42 | }) | 41 | }) |
| 43 | 42 | ||
| 43 | +router.put('/resetPasswordByUserId/:userId',async(ctx, next)=>{ | ||
| 44 | + try{ | ||
| 45 | + let updateBackData = await userContoller.resetPasswordByUserId(ctx, next); | ||
| 46 | + status.successTemp(ctx,200,updateBackData); | ||
| 47 | + }catch(e){ | ||
| 48 | + console.log(e) | ||
| 49 | + status.catchError(ctx,400,e.message); | ||
| 50 | + } | ||
| 51 | +}) | ||
| 52 | + | ||
| 44 | router.delete('/delUserByUserId/:userId',async(ctx, next)=>{ | 53 | router.delete('/delUserByUserId/:userId',async(ctx, next)=>{ |
| 45 | try{ | 54 | try{ |
| 46 | let delData = await userContoller.delUserByUserId(ctx, next); | 55 | let delData = await userContoller.delUserByUserId(ctx, next); |
| @@ -15,14 +15,8 @@ userService.prototype.addUser = async(data)=>{ | @@ -15,14 +15,8 @@ userService.prototype.addUser = async(data)=>{ | ||
| 15 | try{ | 15 | try{ |
| 16 | let oldUser = await userModel.find({where:{loginName:data.loginName}}) | 16 | let oldUser = await userModel.find({where:{loginName:data.loginName}}) |
| 17 | if(oldUser){ | 17 | if(oldUser){ |
| 18 | - return {code:0,msg:'用户已存在'} | 18 | + return {code:400,msg:'用户已存在'} |
| 19 | } | 19 | } |
| 20 | -}catch (err){ | ||
| 21 | - console.log(err) | ||
| 22 | - throw new Error(err); | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | -try{ | ||
| 26 | let newUser = await userModel.create(data) | 20 | let newUser = await userModel.create(data) |
| 27 | return newUser; | 21 | return newUser; |
| 28 | }catch (err){ | 22 | }catch (err){ |
| @@ -35,9 +29,9 @@ userService.prototype.login = async(name,pw) => { | @@ -35,9 +29,9 @@ userService.prototype.login = async(name,pw) => { | ||
| 35 | let User = await userModel.find({where:{loginName:name}}) | 29 | let User = await userModel.find({where:{loginName:name}}) |
| 36 | console.dir(User) | 30 | console.dir(User) |
| 37 | if(!User){ | 31 | if(!User){ |
| 38 | - return {code:0,msg:'用户不存在'} | 32 | + return {code:300,msg:'用户不存在'} |
| 39 | }else if(User.password != saitMd5.md5Salt(pw,User.salt)){ | 33 | }else if(User.password != saitMd5.md5Salt(pw,User.salt)){ |
| 40 | - return {code:0,msg:'密码不正确'} | 34 | + return {code:300,msg:'密码不正确'} |
| 41 | } | 35 | } |
| 42 | let token = await tokenUtil.getSession(User); | 36 | let token = await tokenUtil.getSession(User); |
| 43 | return token | 37 | return token |
| @@ -47,6 +41,8 @@ userService.prototype.login = async(name,pw) => { | @@ -47,6 +41,8 @@ userService.prototype.login = async(name,pw) => { | ||
| 47 | } | 41 | } |
| 48 | } | 42 | } |
| 49 | 43 | ||
| 44 | + | ||
| 45 | + | ||
| 50 | userService.prototype.getStu = async(type)=>{ | 46 | userService.prototype.getStu = async(type)=>{ |
| 51 | try { | 47 | try { |
| 52 | let User = await userModel.findAll({where:{userType:type}}); | 48 | let User = await userModel.findAll({where:{userType:type}}); |
| @@ -55,6 +51,24 @@ userService.prototype.getStu = async(type)=>{ | @@ -55,6 +51,24 @@ userService.prototype.getStu = async(type)=>{ | ||
| 55 | throw new Error(err); | 51 | throw new Error(err); |
| 56 | } | 52 | } |
| 57 | } | 53 | } |
| 54 | + | ||
| 55 | +userService.prototype.resetPasswordByUserId = async(userId,pw) => { | ||
| 56 | + try{ | ||
| 57 | + var t = await sequelize.transaction({ autocommit: true }) | ||
| 58 | + let User = await userModel.findOne({where:{id:userId}}) | ||
| 59 | + if(!User){ | ||
| 60 | + t.rollback | ||
| 61 | + return {code:0,msg:'用户不存在'} | ||
| 62 | + } | ||
| 63 | + let updateUser = await userModel.update({password:pw.md5Pass,salt:pw.salt},{where:{id:userId}}); | ||
| 64 | + t.commit(); | ||
| 65 | + return updateUser | ||
| 66 | + }catch (err){ | ||
| 67 | + t.rollback(); | ||
| 68 | + throw new Error(err); | ||
| 69 | + } | ||
| 70 | +} | ||
| 71 | + | ||
| 58 | userService.prototype.updateUserByUserId = async(userId,data)=>{ | 72 | userService.prototype.updateUserByUserId = async(userId,data)=>{ |
| 59 | try { | 73 | try { |
| 60 | var t = await sequelize.transaction({ autocommit: true }) | 74 | var t = await sequelize.transaction({ autocommit: true }) |
-
请 注册 或 登录 后发表评论