mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-09 05:00:30 +08:00
add: 修改密码功能和获取项目成员列表功能
This commit is contained in:
parent
2877abb825
commit
0126784857
@ -3,7 +3,7 @@
|
||||
"webhost": "127.0.0.1",
|
||||
"adminAccount": "admin@admin.com",
|
||||
"db": {
|
||||
"servername": "192.168.237.71",
|
||||
"servername": "127.0.0.1",
|
||||
"DATABASE": "yapi",
|
||||
"port": 27017
|
||||
},
|
||||
|
@ -2,6 +2,7 @@ import projectModel from '../models/project.js'
|
||||
import yapi from '../yapi.js'
|
||||
import baseController from './base.js'
|
||||
import interfaceModel from '../models/interface.js'
|
||||
import userModel from '../models/user.js'
|
||||
|
||||
class projectController extends baseController {
|
||||
|
||||
@ -136,6 +137,41 @@ class projectController extends baseController {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目成员列表
|
||||
* @interface /project/get_member_list
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @return {Object}
|
||||
* @example ./api/project/get_member_list.json
|
||||
*/
|
||||
|
||||
async getMemberList(ctx) {
|
||||
let params = ctx.request.query;
|
||||
if(!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
let project = await this.Model.get(params.id);
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let result = [];
|
||||
|
||||
for(let i of project.members) {
|
||||
let user = await userInst.findById(i);
|
||||
result.push(user);
|
||||
}
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch(e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/get
|
||||
|
@ -149,22 +149,41 @@ class userController extends baseController{
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
* @param {*} ctx
|
||||
* @interface /user/change_password
|
||||
* @method POST
|
||||
* @category user
|
||||
* @param {Number} uid 用户ID
|
||||
* @param {Number} [old_password] 旧密码, 非admin用户必须传
|
||||
* @param {Number} password 新密码
|
||||
* @return {Object}
|
||||
* @example ./api/user/change_password
|
||||
*/
|
||||
async changePassword(ctx){
|
||||
let params = ctx.request.body;
|
||||
var userInst = yapi.getInst(userModel);
|
||||
let userInst = yapi.getInst(userModel);
|
||||
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) {
|
||||
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) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, '旧密码错误');
|
||||
}
|
||||
}
|
||||
|
||||
let passsalt = yapi.commons.randStr();
|
||||
let data = {
|
||||
up_time: yapi.commons.time(),
|
||||
password: yapi.commons.generatePassword(passsalt, passsalt),
|
||||
password: yapi.commons.generatePassword(params.password, passsalt),
|
||||
passsalt: passsalt
|
||||
}
|
||||
};
|
||||
try{
|
||||
let result = await userInst.update(id, data);
|
||||
let result = await userInst.update(params.uid, data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 401, e.message);
|
||||
|
@ -52,12 +52,7 @@ class userModel extends baseModel{
|
||||
update(id,data){
|
||||
return this.model.update({
|
||||
_id: id
|
||||
},{
|
||||
username: data.username,
|
||||
email: data.email,
|
||||
role: data.role,
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
}, data)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ createAction('user', 'del', 'post', 'del')
|
||||
createAction('user', 'status', 'get', 'getLoginStatus')
|
||||
createAction('user', 'logout', 'get', 'logout')
|
||||
createAction('user', 'login_by_token', 'post', 'loginByToken')
|
||||
createAction('user', 'change_password', 'post', 'changePassword');
|
||||
|
||||
|
||||
//project
|
||||
@ -54,6 +55,8 @@ createAction('project', 'up', 'post', 'up')
|
||||
createAction('project', 'del', 'post', 'del')
|
||||
createAction('project', 'add_member', 'post', 'addMember')
|
||||
createAction('project', 'del_member', 'post', 'delMember')
|
||||
createAction('project', 'get_member_list', 'get', 'getMemberList')
|
||||
|
||||
|
||||
//interface
|
||||
createAction('interface', 'add', 'post', 'add')
|
||||
|
@ -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);
|
||||
@ -44,6 +48,10 @@ var _interface = require('../models/interface.js');
|
||||
|
||||
var _interface2 = _interopRequireDefault(_interface);
|
||||
|
||||
var _user = require('../models/user.js');
|
||||
|
||||
var _user2 = _interopRequireDefault(_user);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var projectController = function (_baseController) {
|
||||
@ -355,22 +363,24 @@ var projectController = function (_baseController) {
|
||||
|
||||
return delMember;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 添加项目
|
||||
* @interface /project/get
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @returns {Object}
|
||||
* @example ./api/project/get.json
|
||||
*/
|
||||
* 获取项目成员列表
|
||||
* @interface /project/get_member_list
|
||||
* @method GET
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id 项目id,不能为空
|
||||
* @return {Object}
|
||||
* @example ./api/project/get_member_list.json
|
||||
*/
|
||||
|
||||
}, {
|
||||
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) {
|
||||
@ -390,30 +400,155 @@ var projectController = function (_baseController) {
|
||||
return this.Model.get(params.id);
|
||||
|
||||
case 6:
|
||||
result = _context4.sent;
|
||||
project = _context4.sent;
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
result = [];
|
||||
_iteratorNormalCompletion = true;
|
||||
_didIteratorError = false;
|
||||
_iteratorError = undefined;
|
||||
_context4.prev = 12;
|
||||
_iterator = (0, _getIterator3.default)(project.members);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 13;
|
||||
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(user);
|
||||
|
||||
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;
|
||||
}()
|
||||
|
||||
@ -431,49 +566,49 @@ 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, result;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context5.next = 13;
|
||||
_context6.next = 13;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
_context5.prev = 10;
|
||||
_context5.t0 = _context5['catch'](3);
|
||||
_context6.prev = 10;
|
||||
_context6.t0 = _context6['catch'](3);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 13:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
return _context6.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[3, 10]]);
|
||||
}, _callee6, this, [[3, 10]]);
|
||||
}));
|
||||
|
||||
function list(_x5) {
|
||||
return _ref5.apply(this, arguments);
|
||||
function list(_x6) {
|
||||
return _ref6.apply(this, arguments);
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -493,78 +628,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;
|
||||
@ -591,65 +726,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 = {
|
||||
@ -666,32 +801,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;
|
||||
|
@ -342,14 +342,21 @@ var userController = function (_baseController) {
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
* @param {*} ctx
|
||||
* @interface /user/change_password
|
||||
* @method POST
|
||||
* @category user
|
||||
* @param {Number} uid 用户ID
|
||||
* @param {Number} [old_password] 旧密码, 非admin用户必须传
|
||||
* @param {Number} password 新密码
|
||||
* @return {Object}
|
||||
* @example ./api/user/change_password
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'changePassword',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var params, userInst, passsalt, data, result;
|
||||
var params, userInst, user, passsalt, data, result;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
@ -358,42 +365,70 @@ var userController = function (_baseController) {
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
|
||||
if (!(this.getRole() !== 'admin' && params.uid != this.getUid())) {
|
||||
_context5.next = 4;
|
||||
_context5.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
console.log(this.getRole(), this.getUid());
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, '没有权限'));
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context5.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
if (params.old_password) {
|
||||
_context5.next = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '旧密码不能为空'));
|
||||
|
||||
case 8:
|
||||
_context5.next = 10;
|
||||
return userInst.findById(params.uid);
|
||||
|
||||
case 10:
|
||||
user = _context5.sent;
|
||||
|
||||
if (!(_yapi2.default.commons.generatePassword(params.old_password, user.passsalt) !== user.password)) {
|
||||
_context5.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, '旧密码错误'));
|
||||
|
||||
case 13:
|
||||
passsalt = _yapi2.default.commons.randStr();
|
||||
data = {
|
||||
up_time: _yapi2.default.commons.time(),
|
||||
password: _yapi2.default.commons.generatePassword(passsalt, passsalt),
|
||||
password: _yapi2.default.commons.generatePassword(params.password, passsalt),
|
||||
passsalt: passsalt
|
||||
};
|
||||
_context5.prev = 6;
|
||||
_context5.next = 9;
|
||||
return userInst.update(id, data);
|
||||
_context5.prev = 15;
|
||||
_context5.next = 18;
|
||||
return userInst.update(params.uid, data);
|
||||
|
||||
case 9:
|
||||
case 18:
|
||||
result = _context5.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context5.next = 16;
|
||||
_context5.next = 25;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_context5.prev = 13;
|
||||
_context5.t0 = _context5['catch'](6);
|
||||
case 22:
|
||||
_context5.prev = 22;
|
||||
_context5.t0 = _context5['catch'](15);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 401, _context5.t0.message);
|
||||
|
||||
case 16:
|
||||
case 25:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[6, 13]]);
|
||||
}, _callee5, this, [[15, 22]]);
|
||||
}));
|
||||
|
||||
function changePassword(_x6) {
|
||||
@ -644,17 +679,16 @@ var userController = function (_baseController) {
|
||||
key: 'findById',
|
||||
value: function () {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var userInst, _id, result;
|
||||
|
||||
var userInst, id, result;
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
while (1) {
|
||||
switch (_context10.prev = _context10.next) {
|
||||
case 0:
|
||||
_context10.prev = 0;
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_id = ctx.request.body.id;
|
||||
id = ctx.request.body.id;
|
||||
_context10.next = 5;
|
||||
return userInst.findById(_id);
|
||||
return userInst.findById(id);
|
||||
|
||||
case 5:
|
||||
result = _context10.sent;
|
||||
@ -695,8 +729,7 @@ var userController = function (_baseController) {
|
||||
key: 'del',
|
||||
value: function () {
|
||||
var _ref11 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee11(ctx) {
|
||||
var userInst, _id2, result;
|
||||
|
||||
var userInst, id, result;
|
||||
return _regenerator2.default.wrap(function _callee11$(_context11) {
|
||||
while (1) {
|
||||
switch (_context11.prev = _context11.next) {
|
||||
@ -712,9 +745,9 @@ var userController = function (_baseController) {
|
||||
|
||||
case 3:
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_id2 = ctx.request.body.id;
|
||||
id = ctx.request.body.id;
|
||||
_context11.next = 7;
|
||||
return userInst.del(_id2);
|
||||
return userInst.del(id);
|
||||
|
||||
case 7:
|
||||
result = _context11.sent;
|
||||
@ -760,15 +793,14 @@ var userController = function (_baseController) {
|
||||
key: 'update',
|
||||
value: function () {
|
||||
var _ref12 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee12(ctx) {
|
||||
var userInst, _id3, data, checkRepeat, result;
|
||||
|
||||
var userInst, id, data, checkRepeat, result;
|
||||
return _regenerator2.default.wrap(function _callee12$(_context12) {
|
||||
while (1) {
|
||||
switch (_context12.prev = _context12.next) {
|
||||
case 0:
|
||||
_context12.prev = 0;
|
||||
userInst = _yapi2.default.getInst(_user2.default);
|
||||
_id3 = this.getUid();
|
||||
id = this.getUid();
|
||||
data = {
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
@ -796,7 +828,7 @@ var userController = function (_baseController) {
|
||||
|
||||
case 12:
|
||||
_context12.next = 14;
|
||||
return userInst.update(_id3, data);
|
||||
return userInst.update(id, data);
|
||||
|
||||
case 14:
|
||||
result = _context12.sent;
|
||||
|
@ -108,12 +108,7 @@ var userModel = function (_baseModel) {
|
||||
value: function update(id, data) {
|
||||
return this.model.update({
|
||||
_id: id
|
||||
}, {
|
||||
username: data.username,
|
||||
email: data.email,
|
||||
role: data.role,
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
}, data);
|
||||
}
|
||||
}]);
|
||||
return userModel;
|
||||
|
@ -71,6 +71,7 @@ createAction('user', 'del', 'post', 'del');
|
||||
createAction('user', 'status', 'get', 'getLoginStatus');
|
||||
createAction('user', 'logout', 'get', 'logout');
|
||||
createAction('user', 'login_by_token', 'post', 'loginByToken');
|
||||
createAction('user', 'change_password', 'post', 'changePassword');
|
||||
|
||||
//project
|
||||
createAction('project', 'add', 'post', 'add');
|
||||
@ -80,6 +81,7 @@ createAction('project', 'up', 'post', 'up');
|
||||
createAction('project', 'del', 'post', 'del');
|
||||
createAction('project', 'add_member', 'post', 'addMember');
|
||||
createAction('project', 'del_member', 'post', 'delMember');
|
||||
createAction('project', 'get_member_list', 'get', 'getMemberList');
|
||||
|
||||
//interface
|
||||
createAction('interface', 'add', 'post', 'add');
|
||||
|
Loading…
Reference in New Issue
Block a user