fix: fix some bug

This commit is contained in:
sean 2017-07-18 15:48:05 +08:00
parent d2d84857ab
commit 5d11a7b2d3
6 changed files with 423 additions and 252 deletions

102
doc/build/api.html vendored
View File

@ -555,7 +555,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#13" target="_blank">./server/controllers/user.js:13</a>
<a href="./static/server/controllers/user.js.html#14" target="_blank">./server/controllers/user.js:14</a>
</p>
@ -642,7 +642,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#57" target="_blank">./server/controllers/user.js:57</a>
<a href="./static/server/controllers/user.js.html#58" target="_blank">./server/controllers/user.js:58</a>
</p>
@ -675,7 +675,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#150" target="_blank">./server/controllers/user.js:150</a>
<a href="./static/server/controllers/user.js.html#151" target="_blank">./server/controllers/user.js:151</a>
</p>
@ -771,7 +771,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#214" target="_blank">./server/controllers/user.js:214</a>
<a href="./static/server/controllers/user.js.html#215" target="_blank">./server/controllers/user.js:215</a>
</p>
@ -868,7 +868,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#276" target="_blank">./server/controllers/user.js:276</a>
<a href="./static/server/controllers/user.js.html#277" target="_blank">./server/controllers/user.js:277</a>
</p>
@ -938,7 +938,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#314" target="_blank">./server/controllers/user.js:314</a>
<a href="./static/server/controllers/user.js.html#315" target="_blank">./server/controllers/user.js:315</a>
</p>
@ -1000,7 +1000,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#343" target="_blank">./server/controllers/user.js:343</a>
<a href="./static/server/controllers/user.js.html#344" target="_blank">./server/controllers/user.js:344</a>
</p>
@ -1062,7 +1062,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#367" target="_blank">./server/controllers/user.js:367</a>
<a href="./static/server/controllers/user.js.html#368" target="_blank">./server/controllers/user.js:368</a>
</p>
@ -1154,7 +1154,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/user.js.html#412" target="_blank">./server/controllers/user.js:412</a>
<a href="./static/server/controllers/user.js.html#421" target="_blank">./server/controllers/user.js:421</a>
</p>
@ -1201,14 +1201,11 @@
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"ok"</span><span class="token punctuation">,</span>
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
<span class="token string">"email"</span><span class="token punctuation">:</span> <span class="token string">"admin@admin.com"</span><span class="token punctuation">,</span>
<span class="token string">"password"</span><span class="token punctuation">:</span> <span class="token string">"3d078af947521bb4a99c93f5e089fc2ac601fa09"</span><span class="token punctuation">,</span>
<span class="token string">"passsalt"</span><span class="token punctuation">:</span> <span class="token string">"qc8lnjpnbs9z1vodz4ynfjemi"</span><span class="token punctuation">,</span>
<span class="token string">"role"</span><span class="token punctuation">:</span> <span class="token string">"admin"</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1499936103</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1499936103</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span>
<span class="token string">"addTime"</span><span class="token punctuation">:</span> <span class="token number">1499936103</span><span class="token punctuation">,</span>
<span class="token string">"upTime"</span><span class="token punctuation">:</span> <span class="token number">1499936103</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span></code></pre>
@ -1361,7 +1358,7 @@
</blockquote>
<p>
<small class="text-muted">描述:</small>
添加项目成员
添加项目
</p>
<p>
@ -1445,7 +1442,7 @@
</blockquote>
<p>
<small class="text-muted">描述:</small>
删除项目成员
添加项目
</p>
<p>
@ -1534,7 +1531,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#142" target="_blank">./server/controllers/project.js:142</a>
<a href="./static/server/controllers/project.js.html#144" target="_blank">./server/controllers/project.js:144</a>
</p>
@ -1612,7 +1609,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#182" target="_blank">./server/controllers/project.js:182</a>
<a href="./static/server/controllers/project.js.html#185" target="_blank">./server/controllers/project.js:185</a>
</p>
@ -1695,7 +1692,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#206" target="_blank">./server/controllers/project.js:206</a>
<a href="./static/server/controllers/project.js.html#209" target="_blank">./server/controllers/project.js:209</a>
</p>
@ -1814,7 +1811,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#244" target="_blank">./server/controllers/project.js:244</a>
<a href="./static/server/controllers/project.js.html#247" target="_blank">./server/controllers/project.js:247</a>
</p>
@ -1886,7 +1883,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#277" target="_blank">./server/controllers/project.js:277</a>
<a href="./static/server/controllers/project.js.html#280" target="_blank">./server/controllers/project.js:280</a>
</p>
@ -2046,7 +2043,7 @@
<p>
<small class="text-muted">源码位置:</small>
<a href="./static/server/controllers/project.js.html#338" target="_blank">./server/controllers/project.js:338</a>
<a href="./static/server/controllers/project.js.html#341" target="_blank">./server/controllers/project.js:341</a>
</p>
@ -2089,38 +2086,35 @@
<div>示例:</div>
<pre class="ydoc-example" data-foldnumber=10><code><span class="token punctuation">{</span>
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">200</span><span class="token punctuation">,</span>
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"ok"</span><span class="token punctuation">,</span>
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">"project"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"project yapi"</span><span class="token punctuation">,</span>
<span class="token string">"prd_host"</span><span class="token punctuation">:</span> <span class="token string">"yapi.qunar.com"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"/yapi/"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
<span class="token string">"group_id"</span><span class="token punctuation">:</span> <span class="token number">193</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500013365</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500013365</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"101"</span>
<span class="token string">"errcode"</span><span class="token punctuation">:</span> <span class="token number">200</span><span class="token punctuation">,</span>
<span class="token string">"errmsg"</span><span class="token punctuation">:</span> <span class="token string">"ok"</span><span class="token punctuation">,</span>
<span class="token string">"data"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
<span class="token string">"project"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
<span class="token string">"name"</span><span class="token punctuation">:</span> <span class="token string">"qav_project"</span><span class="token punctuation">,</span>
<span class="token string">"prdHost"</span><span class="token punctuation">:</span> <span class="token string">"xxx.qunar.com:8080"</span><span class="token punctuation">,</span>
<span class="token string">"basepath"</span><span class="token punctuation">:</span> <span class="token string">"/qav/"</span><span class="token punctuation">,</span>
<span class="token string">"addTime"</span><span class="token punctuation">:</span> <span class="token number">1500013365</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">101</span><span class="token punctuation">,</span>
<span class="token string">"upTime"</span><span class="token punctuation">:</span> <span class="token number">1500013365</span><span class="token punctuation">,</span>
<span class="token string">"env"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"members"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token string">"101"</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"group"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">193</span><span class="token punctuation">,</span>
<span class="token string">"groupName"</span><span class="token punctuation">:</span> <span class="token string">"qav"</span><span class="token punctuation">,</span>
<span class="token string">"groupDesc"</span><span class="token punctuation">:</span> <span class="token string">"project qav"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"addTime"</span><span class="token punctuation">:</span> <span class="token number">1500013066</span><span class="token punctuation">,</span>
<span class="token string">"upTime"</span><span class="token punctuation">:</span> <span class="token number">1500013066</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token string">"group"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
<span class="token punctuation">{</span>
<span class="token string">"_id"</span><span class="token punctuation">:</span> <span class="token number">193</span><span class="token punctuation">,</span>
<span class="token string">"group_name"</span><span class="token punctuation">:</span> <span class="token string">"yapi"</span><span class="token punctuation">,</span>
<span class="token string">"group_desc"</span><span class="token punctuation">:</span> <span class="token string">"group yapi"</span><span class="token punctuation">,</span>
<span class="token string">"uid"</span><span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
<span class="token string">"add_time"</span><span class="token punctuation">:</span> <span class="token number">1500013066</span><span class="token punctuation">,</span>
<span class="token string">"up_time"</span><span class="token punctuation">:</span> <span class="token number">1500013066</span><span class="token punctuation">,</span>
<span class="token string">"__v"</span><span class="token punctuation">:</span> <span class="token number">0</span>
<span class="token punctuation">}</span>
<span class="token punctuation">]</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span></code></pre>

View File

@ -29,8 +29,8 @@
import yapi from '../yapi.js'
import baseController from './base.js'
import interfaceModel from '../models/interface.js'
import userModel from '../models/user.js'
import groupModel from '../models/group'
import commons from '../utils/commons.js'
class projectController extends baseController {
@ -103,7 +103,7 @@ class projectController extends baseController {
}
/**
* 添加项目成员
* 添加项目
* @interface /project/add_member
* @method POST
* @category project
@ -135,7 +135,7 @@ class projectController extends baseController {
}
/**
* 删除项目成员
* 添加项目
* @interface /project/del_member
* @method POST
* @category project
@ -166,6 +166,8 @@ class projectController extends baseController {
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
<<<<<<< HEAD
=======
/**
* 获取项目成员列表
@ -207,6 +209,7 @@ class projectController extends baseController {
}
>>>>>>> 2467556d35eca929c40a1ffd1e5d64d047a9fc77
/**
* 添加项目
* @interface /project/get
@ -384,10 +387,36 @@ class projectController extends baseController {
return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.')
}
let projectList = await this.Model.search(q);
let groupList = await this.groupModel.search(q);
let projectRules = [
'_id',
'name',
'basepath',
'uid',
'env',
'members',
{ key: 'group_id', alias: 'groupId' },
{ key: 'up_time', alias: 'upTime' },
{ key: 'prd_host', alias: 'prdHost' },
{ key: 'add_time', alias: 'addTime' }
];
let groupRules = [
'_id',
'uid',
{ key: 'group_name', alias: 'groupName'},
{ key: 'group_desc', alias: 'groupDesc' },
{ key: 'add_time', alias: 'addTime' },
{ key: 'up_time', alias: 'upTime' }
];
projectList = commons.filterRes(projectList, projectRules);
groupList = commons.filterRes(groupList, groupRules);
let queryList = {
project: await this.Model.search(q),
group: await this.groupModel.search(q)
}
project: projectList,
group: groupList
};
return ctx.body = yapi.commons.resReturn(queryList, 200, 'ok')
}

View File

@ -30,11 +30,12 @@ import yapi from '../yapi.js'
import baseController from './base.js'
import mongoose from 'mongoose'
import request from 'request'
import common from '../utils/commons.js'
const jwt = require('jsonwebtoken');
class userController extends baseController{
constructor(ctx){
class userController extends baseController {
constructor(ctx) {
super(ctx)
this.Model = yapi.getInst(userModel);
}
@ -49,26 +50,26 @@ class userController extends baseController{
* @returns {Object}
* @example ./api/user/login.json
*/
async login(ctx){ //登录
async login(ctx) { //登录
let userInst = yapi.getInst(userModel); //创建user实体
let email = ctx.request.body.email;
let password = ctx.request.body.password;
if(!email){
return ctx.body = yapi.commons.resReturn(null,400,'email不能为空');
if (!email) {
return ctx.body = yapi.commons.resReturn(null, 400, 'email不能为空');
}
if(!password){
return ctx.body = yapi.commons.resReturn(null,400,'密码不能为空');
if (!password) {
return ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空');
}
let result = await userInst.findByEmail(email);
if(!result){
return ctx.body = yapi.commons.resReturn(null,404,'该用户不存在');
}else if(yapi.commons.generatePassword(password, result.passsalt) === result.password){
if (!result) {
return ctx.body = yapi.commons.resReturn(null, 404, '该用户不存在');
} else if (yapi.commons.generatePassword(password, result.passsalt) === result.password) {
this.setLoginCookie(result._id, result.passsalt)
return ctx.body = yapi.commons.resReturn({
username: result.username,
uid: result._id,
@ -76,8 +77,8 @@ class userController extends baseController{
add_time: result.add_time,
up_time: result.up_time
}, 0, 'logout success...');
}else{
}, 0, 'logout success...');
} else {
return ctx.body = yapi.commons.resReturn(null, 405, '密码错误');
}
}
@ -92,7 +93,7 @@ class userController extends baseController{
* @example ./api/user/logout.json
*/
async logout(ctx){
async logout(ctx) {
ctx.cookies.set('_yapi_token', null);
ctx.cookies.set('_yapi_uid', null);
ctx.body = yapi.commons.resReturn('ok');
@ -103,22 +104,22 @@ class userController extends baseController{
* 第三方登录需要提供一个request方法和 token字段暂时只支持qunar第三方
* @return {email: String, username: String}
*/
thirdQunarLogin(){
thirdQunarLogin() {
return {
request: (token) => {
return new Promise((resolve, reject) =>{
request('http://qsso.corp.qunar.com/api/verifytoken.php?token=' + token ,function (error, response, body) {
return new Promise((resolve, reject) => {
request('http://qsso.corp.qunar.com/api/verifytoken.php?token=' + token, function (error, response, body) {
if (!error && response.statusCode == 200) {
let result = JSON.parse(body);
if(result && result.ret === true){
if (result && result.ret === true) {
let ret = {
email: result.userId + '@qunar.com',
username: result.data.userInfo.name
}
resolve(ret)
}else{
resolve(ret)
} else {
reject(result)
}
}
}
reject(error)
})
@ -130,30 +131,30 @@ class userController extends baseController{
async loginByToken(ctx){
async loginByToken(ctx) {
let config = this.thirdQunarLogin();
let token = ctx.request.body[config.tokenField] || ctx.request.query[config.tokenField];
try{
try {
let ret = await config.request(token);
let login = await this.handleThirdLogin(ret.email, ret.username);
if(login === true){
if (login === true) {
yapi.commons.log('login success');
ctx.redirect('/')
}
}catch(e){
} catch (e) {
yapi.commons.log(e.message, 'error')
ctx.redirect('/')
}
}
async handleThirdLogin(email, username){
let user, data, passsalt;
var userInst = yapi.getInst(userModel);
try{
async handleThirdLogin(email, username) {
let user, data, passsalt;
var userInst = yapi.getInst(userModel);
try {
user = await userInst.findByEmail(email);
if(!user || !user._id){
if (!user || !user._id) {
passsalt = yapi.commons.randStr();
data = {
username: username,
@ -166,10 +167,10 @@ class userController extends baseController{
}
user = await userInst.save(data);
}
this.setLoginCookie(user._id, user.passsalt)
return true;
}catch(e){
} catch (e) {
console.error(e.message)
return false;
}
@ -186,20 +187,20 @@ class userController extends baseController{
* @return {Object}
* @example ./api/user/change_password.json
*/
async changePassword(ctx){
async changePassword(ctx) {
let params = ctx.request.body;
let userInst = yapi.getInst(userModel);
if(this.getRole() !== 'admin' && params.uid != this.getUid()){
if (this.getRole() !== 'admin' && params.uid != this.getUid()) {
console.log(this.getRole(), this.getUid());
return ctx.body = yapi.commons.resReturn(null, 402, '没有权限');
}
if(this.getRole() !== 'admin') {
if(!params.old_password) {
if (this.getRole() !== 'admin') {
if (!params.old_password) {
return ctx.body = yapi.commons.resReturn(null, 400, '旧密码不能为空');
}
let user = await userInst.findById(params.uid);
if(yapi.commons.generatePassword(params.old_password, user.passsalt) !== user.password) {
if (yapi.commons.generatePassword(params.old_password, user.passsalt) !== user.password) {
return ctx.body = yapi.commons.resReturn(null, 402, '旧密码错误');
}
}
@ -210,24 +211,24 @@ class userController extends baseController{
password: yapi.commons.generatePassword(params.password, passsalt),
passsalt: passsalt
};
try{
try {
let result = await userInst.update(params.uid, data);
ctx.body = yapi.commons.resReturn(result);
}catch(e){
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 401, e.message);
}
}
async forgetPassword(ctx){
}
async resetPassword(ctx){
async forgetPassword(ctx) {
}
setLoginCookie(uid, passsalt){
let token = jwt.sign({uid: uid},passsalt,{expiresIn: '7 days'});
async resetPassword(ctx) {
}
setLoginCookie(uid, passsalt) {
let token = jwt.sign({ uid: uid }, passsalt, { expiresIn: '7 days' });
this.ctx.cookies.set('_yapi_token', token, {
expires: yapi.commons.expireDate(7),
httpOnly: true
@ -251,19 +252,19 @@ class userController extends baseController{
* @returns {Object}
* @example ./api/user/login.json
*/
async reg(ctx){ //注册
var userInst = yapi.getInst(userModel);
async reg(ctx) { //注册
var userInst = yapi.getInst(userModel);
let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
if(!params.email){
return ctx.body = yapi.commons.resReturn(null,400,'邮箱不能为空');
if (!params.email) {
return ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空');
}
if(!params.password){
return ctx.body = yapi.commons.resReturn(null,400,'密码不能为空');
if (!params.password) {
return ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空');
}
var checkRepeat = await userInst.checkRepeat(params.email);//然后检查是否已经存在该用户
if(checkRepeat>0){
return ctx.body = yapi.commons.resReturn(null,401,'该email已经注册');
if (checkRepeat > 0) {
return ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册');
}
let passsalt = yapi.commons.randStr();
@ -276,13 +277,13 @@ class userController extends baseController{
add_time: yapi.commons.time(),
up_time: yapi.commons.time()
}
if(!data.username){
if (!data.username) {
data.username = data.email.substr(0, data.email.indexOf('@'));
}
try{
try {
let user = await userInst.save(data);
this.setLoginCookie(user._id, user.passsalt)
ctx.body = yapi.commons.resReturn({
uid: user._id,
email: user.email,
@ -295,7 +296,7 @@ class userController extends baseController{
to: params.email,
contents: `欢迎注册,您的账号 ${params.email} 已经注册成功`
})
}catch(e){
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 401, e.message);
}
}
@ -350,8 +351,8 @@ class userController extends baseController{
* @example
*/
async findById(ctx){ //根据id获取用户信息
try{
async findById(ctx) { //根据id获取用户信息
try {
var userInst = yapi.getInst(userModel);
let id = ctx.request.query.id;
let result = await userInst.findById(id);
@ -378,17 +379,17 @@ class userController extends baseController{
* @returns {Object}
* @example
*/
async del(ctx){ //根据id删除一个用户
try{
if(this.getRole() !== 'admin'){
async del(ctx) { //根据id删除一个用户
try {
if (this.getRole() !== 'admin') {
return ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.');
}
var userInst = yapi.getInst(userModel);
let id = ctx.request.body.id;
let result = await userInst.del(id);
ctx.body = yapi.commons.resReturn(result);
}catch(e){
ctx.body = yapi.commons.resReturn(null,402,e.message);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
@ -405,6 +406,7 @@ class userController extends baseController{
* @returns {Object}
* @example
*/
<<<<<<< HEAD
async update(ctx){ //更新用户信息
try{
let params = ctx.request.body;
@ -414,6 +416,13 @@ class userController extends baseController{
var userInst = yapi.getInst(userModel);
let id = params.uid;
let data ={
=======
async update(ctx) { //更新用户信息
try {
var userInst = yapi.getInst(userModel);
let id = this.getUid();
let data = {
>>>>>>> 0eba4c285454eb4e4175c228d959f917a3685aac
up_time: yapi.commons.time()
};
if(this.getRole() === 'admin'){
@ -422,18 +431,18 @@ class userController extends baseController{
params.username && (data.username = params.username)
params.email && (data.email = params.email)
if(data.email){
if (data.email) {
var checkRepeat = await userInst.checkRepeat(data.email);//然后检查是否已经存在该用户
if(checkRepeat>0){
return ctx.body = yapi.commons.resReturn(null,401,'该email已经注册');
if (checkRepeat > 0) {
return ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册');
}
}
let result = await userInst.update(id, data);
ctx.body = yapi.commons.resReturn(result);
}catch(e){
ctx.body = yapi.commons.resReturn(null,402,e.message);
} catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message);
}
}
@ -451,19 +460,39 @@ class userController extends baseController{
const { q } = ctx.request.query;
if (!q) {
return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.')
return ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.');
}
if (!yapi.commons.validateSearchKeyword(q)) {
return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.')
return ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.');
}
let queryList = await this.Model.search(q);
return ctx.body = yapi.commons.resReturn(queryList, 200, 'ok')
let rules = [
{
key: '_id',
alias: 'uid'
},
'email',
'role',
{
key: 'add_time',
alias: 'addTime'
},
{
key: 'up_time',
alias: 'upTime'
}
];
let filteredRes = common.filterRes(queryList, rules);
console.log(queryList)
return ctx.body = yapi.commons.resReturn(filteredRes, 200, 'ok');
}
}
module.exports = userController
module.exports = userController;
</pre>
</div>
</div>

View File

@ -139,8 +139,7 @@ class projectController extends baseController {
ctx.body = yapi.commons.resReturn(null, 402, e.message)
}
}
<<<<<<< HEAD
=======
/**
* 获取项目成员列表
@ -181,8 +180,6 @@ class projectController extends baseController {
}
}
>>>>>>> 2467556d35eca929c40a1ffd1e5d64d047a9fc77
/**
* 添加项目
* @interface /project/get
@ -281,7 +278,7 @@ class projectController extends baseController {
/**
* 编辑项目
* @interface /project/up
* @method GET
* @method POST
* @category project
* @foldnumber 10
* @param {Number} id 项目id不能为空

View File

@ -379,7 +379,7 @@ class userController extends baseController {
* @returns {Object}
* @example
*/
<<<<<<< HEAD
async update(ctx){ //更新用户信息
try{
let params = ctx.request.body;
@ -389,13 +389,6 @@ class userController extends baseController {
var userInst = yapi.getInst(userModel);
let id = params.uid;
let data ={
=======
async update(ctx) { //更新用户信息
try {
var userInst = yapi.getInst(userModel);
let id = this.getUid();
let data = {
>>>>>>> 0eba4c285454eb4e4175c228d959f917a3685aac
up_time: yapi.commons.time()
};
if(this.getRole() === 'admin'){

View File

@ -1,5 +1,9 @@
'use strict';
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
@ -367,7 +371,7 @@ var projectController = function (_baseController) {
/**
* 获取项目成员列表
* @interface /project/get_member_list.json
* @interface /project/get_member_list
* @method GET
* @category project
* @foldnumber 10
@ -377,10 +381,11 @@ var projectController = function (_baseController) {
*/
}, {
key: 'get',
key: 'getMemberList',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
var params, result;
var params, project, userInst, result, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, i, user;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
@ -400,37 +405,161 @@ var projectController = function (_baseController) {
return this.Model.get(params.id);
case 6:
result = _context4.sent;
project = _context4.sent;
userInst = _yapi2.default.getInst(userModel);
result = [];
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context4.prev = 12;
_iterator = (0, _getIterator3.default)(project.members);
result.push(user);
case 14:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context4.next = 23;
break;
}
i = _step.value;
_context4.next = 18;
return userInst.findById(i);
case 18:
user = _context4.sent;
result.push({
_id: user._id,
email: user.email,
role: user.role,
add_time: user.add_time,
up_time: user.up_time
});
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 13;
case 20:
_iteratorNormalCompletion = true;
_context4.next = 14;
break;
case 10:
_context4.prev = 10;
_context4.t0 = _context4['catch'](3);
case 23:
_context4.next = 29;
break;
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
case 25:
_context4.prev = 25;
_context4.t0 = _context4['catch'](12);
_didIteratorError = true;
_iteratorError = _context4.t0;
case 13:
case 29:
_context4.prev = 29;
_context4.prev = 30;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 32:
_context4.prev = 32;
if (!_didIteratorError) {
_context4.next = 35;
break;
}
throw _iteratorError;
case 35:
return _context4.finish(32);
case 36:
return _context4.finish(29);
case 37:
ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 43;
break;
case 40:
_context4.prev = 40;
_context4.t1 = _context4['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t1.message);
case 43:
case 'end':
return _context4.stop();
}
}
}, _callee4, this, [[3, 10]]);
}, _callee4, this, [[3, 40], [12, 25, 29, 37], [30,, 32, 36]]);
}));
function get(_x4) {
function getMemberList(_x4) {
return _ref4.apply(this, arguments);
}
return getMemberList;
}()
/**
* 添加项目
* @interface /project/get
* @method GET
* @category project
* @foldnumber 10
* @param {Number} id 项目id不能为空
* @returns {Object}
* @example ./api/project/get.json
*/
}, {
key: 'get',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
params = ctx.request.query;
if (params.id) {
_context5.next = 3;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 3:
_context5.prev = 3;
_context5.next = 6;
return this.Model.get(params.id);
case 6:
result = _context5.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context5.next = 13;
break;
case 10:
_context5.prev = 10;
_context5.t0 = _context5['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
case 13:
case 'end':
return _context5.stop();
}
}
}, _callee5, this, [[3, 10]]);
}));
function get(_x5) {
return _ref5.apply(this, arguments);
}
return get;
}()
@ -450,28 +579,28 @@ var projectController = function (_baseController) {
}, {
key: 'list',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var group_id, pageNo, pageSize, result, resResult, i;
return _regenerator2.default.wrap(function _callee5$(_context5) {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
group_id = ctx.request.query.group_id, pageNo = ctx.request.query.pageNo || 1, pageSize = ctx.request.query.pageSize || 10;
if (group_id) {
_context5.next = 3;
_context6.next = 3;
break;
}
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空'));
case 3:
_context5.prev = 3;
_context5.next = 6;
_context6.prev = 3;
_context6.next = 6;
return this.Model.list(group_id);
case 6:
result = _context5.sent;
result = _context6.sent;
resResult = [];
i = (pageNo - 1) * pageSize;
@ -501,25 +630,25 @@ var projectController = function (_baseController) {
total: result.length,
list: resResult
});
_context6.next = 13;
_context6.next = 22;
break;
case 19:
_context6.prev = 10;
_context5.t0 = _context5['catch'](3);
_context6.prev = 19;
_context6.t0 = _context6['catch'](3);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 22:
case 'end':
return _context5.stop();
return _context6.stop();
}
}
}, _callee6, this, [[3, 10]]);
}, _callee6, this, [[3, 19]]);
}));
function list(_x5) {
return _ref5.apply(this, arguments);
function list(_x6) {
return _ref6.apply(this, arguments);
}
return list;
@ -539,78 +668,78 @@ var projectController = function (_baseController) {
}, {
key: 'del',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var id, interfaceInst, count, result;
return _regenerator2.default.wrap(function _callee6$(_context6) {
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:
_context6.prev = 0;
_context7.prev = 0;
id = ctx.request.body.id;
if (id) {
_context6.next = 4;
_context7.next = 4;
break;
}
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空'));
case 4:
interfaceInst = _yapi2.default.getInst(_interface2.default);
_context6.next = 7;
_context7.next = 7;
return interfaceInst.countByProjectId(id);
case 7:
count = _context6.sent;
count = _context7.sent;
if (!(count > 0)) {
_context6.next = 10;
_context7.next = 10;
break;
}
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '请先删除该项目下所有接口'));
case 10:
_context6.next = 12;
_context7.next = 12;
return this.jungeProjectAuth(id);
case 12:
_context6.t0 = _context6.sent;
_context7.t0 = _context7.sent;
if (!(_context6.t0 !== true)) {
_context6.next = 15;
if (!(_context7.t0 !== true)) {
_context7.next = 15;
break;
}
return _context6.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 15:
_context6.next = 17;
_context7.next = 17;
return this.Model.del(id);
case 17:
result = _context6.sent;
result = _context7.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context6.next = 24;
_context7.next = 24;
break;
case 21:
_context6.prev = 21;
_context6.t1 = _context6['catch'](0);
_context7.prev = 21;
_context7.t1 = _context7['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
case 24:
case 'end':
return _context6.stop();
return _context7.stop();
}
}
}, _callee6, this, [[0, 21]]);
}, _callee7, this, [[0, 21]]);
}));
function del(_x6) {
return _ref6.apply(this, arguments);
function del(_x7) {
return _ref7.apply(this, arguments);
}
return del;
@ -619,7 +748,7 @@ var projectController = function (_baseController) {
/**
* 编辑项目
* @interface /project/up
* @method GET
* @method POST
* @category project
* @foldnumber 10
* @param {Number} id 项目id不能为空
@ -637,65 +766,65 @@ var projectController = function (_baseController) {
}, {
key: 'up',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var id, params, checkRepeat, checkRepeatDomain, data, result;
return _regenerator2.default.wrap(function _callee7$(_context7) {
return _regenerator2.default.wrap(function _callee8$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:
_context7.prev = 0;
_context8.prev = 0;
id = ctx.request.body.id;
params = ctx.request.body;
_context7.next = 5;
_context8.next = 5;
return this.jungeMemberAuth(id, this.getUid());
case 5:
_context7.t0 = _context7.sent;
_context8.t0 = _context8.sent;
if (!(_context7.t0 !== true)) {
_context7.next = 8;
if (!(_context8.t0 !== true)) {
_context8.next = 8;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限'));
case 8:
if (!params.name) {
_context7.next = 14;
_context8.next = 14;
break;
}
_context7.next = 11;
_context8.next = 11;
return this.Model.checkNameRepeat(params.name);
case 11:
checkRepeat = _context7.sent;
checkRepeat = _context8.sent;
if (!(checkRepeat > 0)) {
_context7.next = 14;
_context8.next = 14;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名'));
case 14:
if (!(params.basepath && params.prd_host)) {
_context7.next = 20;
_context8.next = 20;
break;
}
_context7.next = 17;
_context8.next = 17;
return this.Model.checkDomainRepeat(params.prd_host, params.basepath);
case 17:
checkRepeatDomain = _context7.sent;
checkRepeatDomain = _context8.sent;
if (!(checkRepeatDomain > 0)) {
_context7.next = 20;
_context8.next = 20;
break;
}
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath'));
case 20:
data = {
@ -712,32 +841,32 @@ var projectController = function (_baseController) {
}
if (params.env) data.env = params.env;
_context7.next = 27;
_context8.next = 27;
return this.Model.up(id, data);
case 27:
result = _context7.sent;
result = _context8.sent;
ctx.body = _yapi2.default.commons.resReturn(result);
_context7.next = 34;
_context8.next = 34;
break;
case 31:
_context7.prev = 31;
_context7.t1 = _context7['catch'](0);
_context8.prev = 31;
_context8.t1 = _context8['catch'](0);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context7.t1.message);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message);
case 34:
case 'end':
return _context7.stop();
return _context8.stop();
}
}
}, _callee7, this, [[0, 31]]);
}, _callee8, this, [[0, 31]]);
}));
function up(_x7) {
return _ref7.apply(this, arguments);
function up(_x8) {
return _ref8.apply(this, arguments);
}
return up;
@ -757,40 +886,40 @@ var projectController = function (_baseController) {
}, {
key: 'search',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var q, projectList, groupList, projectRules, groupRules, queryList;
return _regenerator2.default.wrap(function _callee8$(_context8) {
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:
q = ctx.request.query.q;
if (q) {
_context8.next = 3;
_context9.next = 3;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'No keyword.'));
case 3:
if (_yapi2.default.commons.validateSearchKeyword(q)) {
_context8.next = 5;
_context9.next = 5;
break;
}
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(void 0, 400, 'Bad query.'));
case 5:
_context8.next = 7;
_context9.next = 7;
return this.Model.search(q);
case 7:
projectList = _context8.sent;
_context8.next = 10;
projectList = _context9.sent;
_context9.next = 10;
return this.groupModel.search(q);
case 10:
groupList = _context8.sent;
groupList = _context9.sent;
projectRules = ['_id', 'name', 'basepath', 'uid', 'env', 'members', { key: 'group_id', alias: 'groupId' }, { key: 'up_time', alias: 'upTime' }, { key: 'prd_host', alias: 'prdHost' }, { key: 'add_time', alias: 'addTime' }];
groupRules = ['_id', 'uid', { key: 'group_name', alias: 'groupName' }, { key: 'group_desc', alias: 'groupDesc' }, { key: 'add_time', alias: 'addTime' }, { key: 'up_time', alias: 'upTime' }];
@ -802,18 +931,18 @@ var projectController = function (_baseController) {
project: projectList,
group: groupList
};
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 200, 'ok'));
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(queryList, 200, 'ok'));
case 17:
case 'end':
return _context8.stop();
return _context9.stop();
}
}
}, _callee8, this);
}, _callee9, this);
}));
function search(_x8) {
return _ref8.apply(this, arguments);
function search(_x9) {
return _ref9.apply(this, arguments);
}
return search;