mock平台

user.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. const userModel = require('../models/user.js');
  2. const yapi = require('../yapi.js');
  3. const baseController = require('./base.js');
  4. const common = require('../utils/commons.js');
  5. const ldap = require('../utils/ldap.js');
  6. const interfaceModel = require('../models/interface.js');
  7. const groupModel = require('../models/group.js');
  8. const projectModel = require('../models/project.js');
  9. const avatarModel = require('../models/avatar.js');
  10. const jwt = require('jsonwebtoken');
  11. class userController extends baseController {
  12. constructor(ctx) {
  13. super(ctx);
  14. this.Model = yapi.getInst(userModel);
  15. }
  16. /**
  17. * 用户登录接口
  18. * @interface /user/login
  19. * @method POST
  20. * @category user
  21. * @foldnumber 10
  22. * @param {String} email email名称,不能为空
  23. * @param {String} password 密码,不能为空
  24. * @returns {Object}
  25. * @example ./api/user/login.json
  26. */
  27. async login(ctx) {
  28. //登录
  29. let userInst = yapi.getInst(userModel); //创建user实体
  30. let email = ctx.request.body.email;
  31. let password = ctx.request.body.password;
  32. if (!email) {
  33. return (ctx.body = yapi.commons.resReturn(null, 400, 'email不能为空'));
  34. }
  35. if (!password) {
  36. return (ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空'));
  37. }
  38. let result = await userInst.findByEmail(email);
  39. if (!result) {
  40. return (ctx.body = yapi.commons.resReturn(null, 404, '该用户不存在'));
  41. } else if (yapi.commons.generatePassword(password, result.passsalt) === result.password) {
  42. this.setLoginCookie(result._id, result.passsalt);
  43. return (ctx.body = yapi.commons.resReturn(
  44. {
  45. username: result.username,
  46. role: result.role,
  47. uid: result._id,
  48. email: result.email,
  49. add_time: result.add_time,
  50. up_time: result.up_time,
  51. type: 'site',
  52. study: result.study
  53. },
  54. 0,
  55. 'logout success...'
  56. ));
  57. } else {
  58. return (ctx.body = yapi.commons.resReturn(null, 405, '密码错误'));
  59. }
  60. }
  61. /**
  62. * 退出登录接口
  63. * @interface /user/logout
  64. * @method GET
  65. * @category user
  66. * @foldnumber 10
  67. * @returns {Object}
  68. * @example ./api/user/logout.json
  69. */
  70. async logout(ctx) {
  71. ctx.cookies.set('_yapi_token', null);
  72. ctx.cookies.set('_yapi_uid', null);
  73. ctx.body = yapi.commons.resReturn('ok');
  74. }
  75. /**
  76. * 更新
  77. * @interface /user/up_study
  78. * @method GET
  79. * @category user
  80. * @foldnumber 10
  81. * @returns {Object}
  82. * @example
  83. */
  84. async upStudy(ctx) {
  85. let userInst = yapi.getInst(userModel); //创建user实体
  86. let data = {
  87. up_time: yapi.commons.time(),
  88. study: true
  89. };
  90. try {
  91. let result = await userInst.update(this.getUid(), data);
  92. ctx.body = yapi.commons.resReturn(result);
  93. } catch (e) {
  94. ctx.body = yapi.commons.resReturn(null, 401, e.message);
  95. }
  96. }
  97. async loginByToken(ctx) {
  98. try {
  99. let ret = await yapi.emitHook('third_login', ctx);
  100. let login = await this.handleThirdLogin(ret.email, ret.username);
  101. if (login === true) {
  102. yapi.commons.log('login success');
  103. ctx.redirect('/group');
  104. }
  105. } catch (e) {
  106. yapi.commons.log(e.message, 'error');
  107. ctx.redirect('/');
  108. }
  109. }
  110. /**
  111. * ldap登录
  112. * @interface /user/login_by_ldap
  113. * @method
  114. * @category user
  115. * @foldnumber 10
  116. * @param {String} email email名称,不能为空
  117. * @param {String} password 密码,不能为空
  118. * @returns {Object}
  119. *
  120. */
  121. async getLdapAuth(ctx) {
  122. try {
  123. const { email, password } = ctx.request.body;
  124. // const username = email.split(/\@/g)[0];
  125. const { info: ldapInfo } = await ldap.ldapQuery(email, password);
  126. const emailPrefix = email.split(/\@/g)[0];
  127. const emailPostfix = yapi.WEBCONFIG.ldapLogin.emailPostfix;
  128. const emailParams =
  129. ldapInfo[yapi.WEBCONFIG.ldapLogin.emailKey || 'mail'] ||
  130. (emailPostfix ? emailPrefix + emailPostfix : email);
  131. const username = ldapInfo[yapi.WEBCONFIG.ldapLogin.usernameKey] || emailPrefix;
  132. let login = await this.handleThirdLogin(emailParams, username);
  133. if (login === true) {
  134. let userInst = yapi.getInst(userModel); //创建user实体
  135. let result = await userInst.findByEmail(emailParams);
  136. return (ctx.body = yapi.commons.resReturn(
  137. {
  138. username: result.username,
  139. role: result.role,
  140. uid: result._id,
  141. email: result.email,
  142. add_time: result.add_time,
  143. up_time: result.up_time,
  144. type: result.type || 'third',
  145. study: result.study
  146. },
  147. 0,
  148. 'logout success...'
  149. ));
  150. }
  151. } catch (e) {
  152. yapi.commons.log(e.message, 'error');
  153. return (ctx.body = yapi.commons.resReturn(null, 401, e.message));
  154. }
  155. }
  156. // 处理第三方登录
  157. async handleThirdLogin(email, username) {
  158. let user, data, passsalt;
  159. let userInst = yapi.getInst(userModel);
  160. try {
  161. user = await userInst.findByEmail(email);
  162. // 新建用户信息
  163. if (!user || !user._id) {
  164. passsalt = yapi.commons.randStr();
  165. data = {
  166. username: username,
  167. password: yapi.commons.generatePassword(passsalt, passsalt),
  168. email: email,
  169. passsalt: passsalt,
  170. role: 'member',
  171. add_time: yapi.commons.time(),
  172. up_time: yapi.commons.time(),
  173. type: 'third'
  174. };
  175. user = await userInst.save(data);
  176. await this.handlePrivateGroup(user._id, username, email);
  177. yapi.commons.sendMail({
  178. to: email,
  179. contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi平台,你的邮箱账号是:${email}</p>`
  180. });
  181. }
  182. this.setLoginCookie(user._id, user.passsalt);
  183. return true;
  184. } catch (e) {
  185. console.error('third_login:', e.message); // eslint-disable-line
  186. throw new Error(`third_login: ${e.message}`);
  187. }
  188. }
  189. /**
  190. * 修改用户密码
  191. * @interface /user/change_password
  192. * @method POST
  193. * @category user
  194. * @param {Number} uid 用户ID
  195. * @param {Number} [old_password] 旧密码, 非admin用户必须传
  196. * @param {Number} password 新密码
  197. * @return {Object}
  198. * @example ./api/user/change_password.json
  199. */
  200. async changePassword(ctx) {
  201. let params = ctx.request.body;
  202. let userInst = yapi.getInst(userModel);
  203. if (!params.uid) {
  204. return (ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'));
  205. }
  206. if (!params.password) {
  207. return (ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空'));
  208. }
  209. let user = await userInst.findById(params.uid);
  210. if (this.getRole() !== 'admin' && params.uid != this.getUid()) {
  211. return (ctx.body = yapi.commons.resReturn(null, 402, '没有权限'));
  212. }
  213. if (this.getRole() !== 'admin' || user.role === 'admin') {
  214. if (!params.old_password) {
  215. return (ctx.body = yapi.commons.resReturn(null, 400, '旧密码不能为空'));
  216. }
  217. if (yapi.commons.generatePassword(params.old_password, user.passsalt) !== user.password) {
  218. return (ctx.body = yapi.commons.resReturn(null, 402, '旧密码错误'));
  219. }
  220. }
  221. let passsalt = yapi.commons.randStr();
  222. let data = {
  223. up_time: yapi.commons.time(),
  224. password: yapi.commons.generatePassword(params.password, passsalt),
  225. passsalt: passsalt
  226. };
  227. try {
  228. let result = await userInst.update(params.uid, data);
  229. ctx.body = yapi.commons.resReturn(result);
  230. } catch (e) {
  231. ctx.body = yapi.commons.resReturn(null, 401, e.message);
  232. }
  233. }
  234. async handlePrivateGroup(uid) {
  235. var groupInst = yapi.getInst(groupModel);
  236. await groupInst.save({
  237. uid: uid,
  238. group_name: 'User-' + uid,
  239. add_time: yapi.commons.time(),
  240. up_time: yapi.commons.time(),
  241. type: 'private'
  242. });
  243. }
  244. setLoginCookie(uid, passsalt) {
  245. let token = jwt.sign({ uid: uid }, passsalt, { expiresIn: '7 days' });
  246. this.ctx.cookies.set('_yapi_token', token, {
  247. expires: yapi.commons.expireDate(7),
  248. httpOnly: true
  249. });
  250. this.ctx.cookies.set('_yapi_uid', uid, {
  251. expires: yapi.commons.expireDate(7),
  252. httpOnly: true
  253. });
  254. }
  255. /**
  256. * 用户注册接口
  257. * @interface /user/reg
  258. * @method POST
  259. * @category user
  260. * @foldnumber 10
  261. * @param {String} email email名称,不能为空
  262. * @param {String} password 密码,不能为空
  263. * @param {String} [username] 用户名
  264. * @returns {Object}
  265. * @example ./api/user/login.json
  266. */
  267. async reg(ctx) {
  268. //注册
  269. if (yapi.WEBCONFIG.closeRegister) {
  270. return (ctx.body = yapi.commons.resReturn(null, 400, '禁止注册,请联系管理员'));
  271. }
  272. let userInst = yapi.getInst(userModel);
  273. let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码
  274. params = yapi.commons.handleParams(params, {
  275. username: 'string',
  276. password: 'string',
  277. email: 'string'
  278. });
  279. if (!params.email) {
  280. return (ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空'));
  281. }
  282. if (!params.password) {
  283. return (ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空'));
  284. }
  285. let checkRepeat = await userInst.checkRepeat(params.email); //然后检查是否已经存在该用户
  286. if (checkRepeat > 0) {
  287. return (ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册'));
  288. }
  289. let passsalt = yapi.commons.randStr();
  290. let data = {
  291. username: params.username,
  292. password: yapi.commons.generatePassword(params.password, passsalt), //加密
  293. email: params.email,
  294. passsalt: passsalt,
  295. role: 'member',
  296. add_time: yapi.commons.time(),
  297. up_time: yapi.commons.time(),
  298. type: 'site'
  299. };
  300. if (!data.username) {
  301. data.username = data.email.substr(0, data.email.indexOf('@'));
  302. }
  303. try {
  304. let user = await userInst.save(data);
  305. this.setLoginCookie(user._id, user.passsalt);
  306. await this.handlePrivateGroup(user._id, user.username, user.email);
  307. ctx.body = yapi.commons.resReturn({
  308. uid: user._id,
  309. email: user.email,
  310. username: user.username,
  311. add_time: user.add_time,
  312. up_time: user.up_time,
  313. role: 'member',
  314. type: user.type,
  315. study: false
  316. });
  317. yapi.commons.sendMail({
  318. to: user.email,
  319. contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi可视化接口平台,您的账号 ${
  320. params.email
  321. } 已经注册成功</p>`
  322. });
  323. } catch (e) {
  324. ctx.body = yapi.commons.resReturn(null, 401, e.message);
  325. }
  326. }
  327. /**
  328. * 获取用户列表
  329. * @interface /user/list
  330. * @method GET
  331. * @category user
  332. * @foldnumber 10
  333. * @param {Number} [page] 分页页码
  334. * @param {Number} [limit] 分页大小,默认为10条
  335. * @returns {Object}
  336. * @example
  337. */
  338. async list(ctx) {
  339. let page = ctx.request.query.page || 1,
  340. limit = ctx.request.query.limit || 10;
  341. const userInst = yapi.getInst(userModel);
  342. try {
  343. let user = await userInst.listWithPaging(page, limit);
  344. let count = await userInst.listCount();
  345. return (ctx.body = yapi.commons.resReturn({
  346. count: count,
  347. total: Math.ceil(count / limit),
  348. list: user
  349. }));
  350. } catch (e) {
  351. return (ctx.body = yapi.commons.resReturn(null, 402, e.message));
  352. }
  353. }
  354. /**
  355. * 获取用户个人信息
  356. * @interface /user/find
  357. * @method GET
  358. * @param id 用户uid
  359. * @category user
  360. * @foldnumber 10
  361. * @returns {Object}
  362. * @example
  363. */
  364. async findById(ctx) {
  365. //根据id获取用户信息
  366. try {
  367. let userInst = yapi.getInst(userModel);
  368. let id = ctx.request.query.id;
  369. if (!id) {
  370. return (ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'));
  371. }
  372. let result = await userInst.findById(id);
  373. if (!result) {
  374. return (ctx.body = yapi.commons.resReturn(null, 402, '不存在的用户'));
  375. }
  376. return (ctx.body = yapi.commons.resReturn({
  377. uid: result._id,
  378. username: result.username,
  379. email: result.email,
  380. role: result.role,
  381. type: result.type,
  382. add_time: result.add_time,
  383. up_time: result.up_time
  384. }));
  385. } catch (e) {
  386. return (ctx.body = yapi.commons.resReturn(null, 402, e.message));
  387. }
  388. }
  389. /**
  390. * 删除用户,只有admin用户才有此权限
  391. * @interface /user/del
  392. * @method POST
  393. * @param id 用户uid
  394. * @category user
  395. * @foldnumber 10
  396. * @returns {Object}
  397. * @example
  398. */
  399. async del(ctx) {
  400. //根据id删除一个用户
  401. try {
  402. if (this.getRole() !== 'admin') {
  403. return (ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.'));
  404. }
  405. let userInst = yapi.getInst(userModel);
  406. let id = ctx.request.body.id;
  407. if (id == this.getUid()) {
  408. return (ctx.body = yapi.commons.resReturn(null, 403, '禁止删除管理员'));
  409. }
  410. if (!id) {
  411. return (ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'));
  412. }
  413. let result = await userInst.del(id);
  414. ctx.body = yapi.commons.resReturn(result);
  415. } catch (e) {
  416. ctx.body = yapi.commons.resReturn(null, 402, e.message);
  417. }
  418. }
  419. /**
  420. * 更新用户个人信息
  421. * @interface /user/update
  422. * @method POST
  423. * @param uid 用户uid
  424. * @param [role] 用户角色,只有管理员有权限修改
  425. * @param [username] String
  426. * @param [email] String
  427. * @category user
  428. * @foldnumber 10
  429. * @returns {Object}
  430. * @example
  431. */
  432. async update(ctx) {
  433. //更新用户信息
  434. try {
  435. let params = ctx.request.body;
  436. params = yapi.commons.handleParams(params, {
  437. username: 'string',
  438. email: 'string'
  439. });
  440. if (this.getRole() !== 'admin' && params.uid != this.getUid()) {
  441. return (ctx.body = yapi.commons.resReturn(null, 401, '没有权限'));
  442. }
  443. let userInst = yapi.getInst(userModel);
  444. let id = params.uid;
  445. if (!id) {
  446. return (ctx.body = yapi.commons.resReturn(null, 400, 'uid不能为空'));
  447. }
  448. let userData = await userInst.findById(id);
  449. if (!userData) {
  450. return (ctx.body = yapi.commons.resReturn(null, 400, 'uid不存在'));
  451. }
  452. let data = {
  453. up_time: yapi.commons.time()
  454. };
  455. params.username && (data.username = params.username);
  456. params.email && (data.email = params.email);
  457. if (data.email) {
  458. var checkRepeat = await userInst.checkRepeat(data.email); //然后检查是否已经存在该用户
  459. if (checkRepeat > 0) {
  460. return (ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册'));
  461. }
  462. }
  463. let member = {
  464. uid: id,
  465. username: data.username || userData.username,
  466. email: data.email || userData.email
  467. };
  468. let groupInst = yapi.getInst(groupModel);
  469. await groupInst.updateMember(member);
  470. let projectInst = yapi.getInst(projectModel);
  471. await projectInst.updateMember(member);
  472. let result = await userInst.update(id, data);
  473. ctx.body = yapi.commons.resReturn(result);
  474. } catch (e) {
  475. ctx.body = yapi.commons.resReturn(null, 402, e.message);
  476. }
  477. }
  478. /**
  479. * 上传用户头像
  480. * @interface /user/upload_avatar
  481. * @method POST
  482. * @param {*} basecode base64编码,通过h5 api传给后端
  483. * @category user
  484. * @returns {Object}
  485. * @example
  486. */
  487. async uploadAvatar(ctx) {
  488. try {
  489. let basecode = ctx.request.body.basecode;
  490. if (!basecode) {
  491. return (ctx.body = yapi.commons.resReturn(null, 400, 'basecode不能为空'));
  492. }
  493. let pngPrefix = 'data:image/png;base64,';
  494. let jpegPrefix = 'data:image/jpeg;base64,';
  495. let type;
  496. if (basecode.substr(0, pngPrefix.length) === pngPrefix) {
  497. basecode = basecode.substr(pngPrefix.length);
  498. type = 'image/png';
  499. } else if (basecode.substr(0, jpegPrefix.length) === jpegPrefix) {
  500. basecode = basecode.substr(jpegPrefix.length);
  501. type = 'image/jpeg';
  502. } else {
  503. return (ctx.body = yapi.commons.resReturn(null, 400, '仅支持jpeg和png格式的图片'));
  504. }
  505. let strLength = basecode.length;
  506. if (parseInt(strLength - (strLength / 8) * 2) > 200000) {
  507. return (ctx.body = yapi.commons.resReturn(null, 400, '图片大小不能超过200kb'));
  508. }
  509. let avatarInst = yapi.getInst(avatarModel);
  510. let result = await avatarInst.up(this.getUid(), basecode, type);
  511. ctx.body = yapi.commons.resReturn(result);
  512. } catch (e) {
  513. ctx.body = yapi.commons.resReturn(null, 401, e.message);
  514. }
  515. }
  516. /**
  517. * 根据用户uid头像
  518. * @interface /user/avatar
  519. * @method GET
  520. * @param {*} uid
  521. * @category user
  522. * @returns {Object}
  523. * @example
  524. */
  525. async avatar(ctx) {
  526. try {
  527. let uid = ctx.query.uid ? ctx.query.uid : this.getUid();
  528. let avatarInst = yapi.getInst(avatarModel);
  529. let data = await avatarInst.get(uid);
  530. let dataBuffer, type;
  531. if (!data || !data.basecode) {
  532. dataBuffer = yapi.fs.readFileSync(yapi.path.join(yapi.WEBROOT, 'static/image/avatar.png'));
  533. type = 'image/png';
  534. } else {
  535. type = data.type;
  536. dataBuffer = new Buffer(data.basecode, 'base64');
  537. }
  538. ctx.set('Content-type', type);
  539. ctx.body = dataBuffer;
  540. } catch (err) {
  541. ctx.body = 'error:' + err.message;
  542. }
  543. }
  544. /**
  545. * 模糊搜索用户名或者email
  546. * @interface /user/search
  547. * @method GET
  548. * @category user
  549. * @foldnumber 10
  550. * @param {String} q
  551. * @return {Object}
  552. * @example ./api/user/search.json
  553. */
  554. async search(ctx) {
  555. const { q } = ctx.request.query;
  556. if (!q) {
  557. return (ctx.body = yapi.commons.resReturn(void 0, 400, 'No keyword.'));
  558. }
  559. if (!yapi.commons.validateSearchKeyword(q)) {
  560. return (ctx.body = yapi.commons.resReturn(void 0, 400, 'Bad query.'));
  561. }
  562. let queryList = await this.Model.search(q);
  563. let rules = [
  564. {
  565. key: '_id',
  566. alias: 'uid'
  567. },
  568. 'username',
  569. 'email',
  570. 'role',
  571. {
  572. key: 'add_time',
  573. alias: 'addTime'
  574. },
  575. {
  576. key: 'up_time',
  577. alias: 'upTime'
  578. }
  579. ];
  580. let filteredRes = common.filterRes(queryList, rules);
  581. return (ctx.body = yapi.commons.resReturn(filteredRes, 0, 'ok'));
  582. }
  583. /**
  584. * 根据路由id初始化项目数据
  585. * @interface /user/project
  586. * @method GET
  587. * @category user
  588. * @foldnumber 10
  589. * @param {String} type 可选group|interface|project
  590. * @param {Number} id
  591. * @return {Object}
  592. * @example
  593. */
  594. async project(ctx) {
  595. let { id, type } = ctx.request.query;
  596. let result = {};
  597. try {
  598. if (type === 'interface') {
  599. let interfaceInst = yapi.getInst(interfaceModel);
  600. let interfaceData = await interfaceInst.get(id);
  601. result.interface = interfaceData;
  602. type = 'project';
  603. id = interfaceData.project_id;
  604. }
  605. if (type === 'project') {
  606. let projectInst = yapi.getInst(projectModel);
  607. let projectData = await projectInst.get(id);
  608. result.project = projectData.toObject();
  609. let ownerAuth = await this.checkAuth(id, 'project', 'danger'),
  610. devAuth;
  611. if (ownerAuth) {
  612. result.project.role = 'owner';
  613. } else {
  614. devAuth = await this.checkAuth(id, 'project', 'site');
  615. if (devAuth) {
  616. result.project.role = 'dev';
  617. } else {
  618. result.project.role = 'member';
  619. }
  620. }
  621. type = 'group';
  622. id = projectData.group_id;
  623. }
  624. if (type === 'group') {
  625. let groupInst = yapi.getInst(groupModel);
  626. let groupData = await groupInst.get(id);
  627. result.group = groupData.toObject();
  628. let ownerAuth = await this.checkAuth(id, 'group', 'danger'),
  629. devAuth;
  630. if (ownerAuth) {
  631. result.group.role = 'owner';
  632. } else {
  633. devAuth = await this.checkAuth(id, 'group', 'site');
  634. if (devAuth) {
  635. result.group.role = 'dev';
  636. } else {
  637. result.group.role = 'member';
  638. }
  639. }
  640. }
  641. return (ctx.body = yapi.commons.resReturn(result));
  642. } catch (e) {
  643. return (ctx.body = yapi.commons.resReturn(result, 422, e.message));
  644. }
  645. }
  646. }
  647. module.exports = userController;