From ca5e3529eba543ab1903f1d6d2c63adbd4128b33 Mon Sep 17 00:00:00 2001 From: 付智勇 <fuzhiyong@efangtec.com> Date: Thu, 28 Sep 2017 16:51:15 +0800 Subject: [PATCH] no message --- controller/userController.js | 3 ++- routes/upload.js | 5 +++-- services/userService.js | 9 +++++++++ util/tokenUtil.js | 1 - views/index.html | 12 +++++++++--- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/controller/userController.js b/controller/userController.js index 0914fa6..7c3bf61 100644 --- a/controller/userController.js +++ b/controller/userController.js @@ -104,7 +104,8 @@ userController.prototype.login = async(ctx, next) =>{ userMobile:userData.userMobile, userEmail:userData.userEmail, token:userData.token, - createTime:userData.createTime + createTime:userData.createTime, + userPhoto:userData.userPhoto } if(!userData.code){ return userBack; diff --git a/routes/upload.js b/routes/upload.js index fe4cd71..59f1e64 100644 --- a/routes/upload.js +++ b/routes/upload.js @@ -47,12 +47,13 @@ router.post('/upLoadDoc',uploaddemo, async (ctx, next) => { } ctx.response.status= 200; ctx.body = { - fileUrl:'http://localhost:10000/'+ctx.req.file.originalname + code:200, + fileUrl:path+ctx.req.file.originalname } } catch (error) { console.log(error) ctx.response.status= 400; - ctx.body = {msg:error} + ctx.body = {code:400,msg:error} } }) diff --git a/services/userService.js b/services/userService.js index 71cee2c..2d20f09 100644 --- a/services/userService.js +++ b/services/userService.js @@ -5,6 +5,8 @@ var sequelize = require('../config'); var tokenUtil = require('../util/tokenUtil'); var co = require('co'); const emailUtil = require('../util/emailUtil') +const attachmentModel =require( '../model/attachmentModel') + function userService(){ @@ -45,12 +47,19 @@ userService.prototype.login = async(loginName,pw,userEmail) => { {loginName:loginName} ]; let User = await userModel.find({where:{$or:queryData}}) + let attachment = await attachmentModel.findOne({where:{businessId:User.id}}) if(!User){ return {code:300,msg:'用户不存在'} }else if(User.password != saitMd5.md5(pw)){ return {code:300,msg:'密码不正确'} } let token = await tokenUtil.getSession(User); + if(attachment){ + token.userPhoto = attachment.path + }else{ + token.userPhoto = null + } + console.dir(token) return token }catch (err){ console.log(err) diff --git a/util/tokenUtil.js b/util/tokenUtil.js index dc86122..ca60f63 100644 --- a/util/tokenUtil.js +++ b/util/tokenUtil.js @@ -15,7 +15,6 @@ module.exports = new JwtSession() ; * @param cb */ JwtSession.prototype.getSession = (users) =>{ - console.log(users) var expiresIn = 60 * 60 * 1000; var payload = {}; payload.id = users.id; diff --git a/views/index.html b/views/index.html index fe10011..2d92876 100644 --- a/views/index.html +++ b/views/index.html @@ -7,9 +7,8 @@ <script src="http://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script> </head> <body> - <form action="/upload/upLoadDoc?businessId=0aJeQOYgLAo5yB1mE14Rvzb69V7mpZKD&category=1" method="post" enctype="multipart/form-data"> + <form action="/upload/upLoadDoc?businessId=0aJeQOYgLAo5yB1mE14Rvzb69V7mpZKD&category=1" method="post" enctype="multipart/form-data" target="http://baidu.com"> <input type="file" name="file"/> - <input type="text" value="1212" name="class" > <input type="submit" value="ok"/> </form> <button onclick="window.open('/record')"> asdas </button> @@ -17,6 +16,13 @@ </body> <script> - + function saveReport() { +// jquery 表单提交 +$("#showDataForm").ajaxSubmit(function(message) { + console.log(message) +}); + +return false; // 必须返回false,否则表单会自己再做一次提交操作,并且页面跳转 +} </script> </html> \ No newline at end of file -- libgit2 0.24.0