project_manager_check.js 1019 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. /**
  3. * 检验是否为项目管理员中间件
  4. *
  5. * @author CaiAoLin
  6. * @date 2018/1/23
  7. * @version
  8. */
  9. module.exports = app => {
  10. return function* projectManagerCheck(next) {
  11. const sessionProject = this.session.sessionProject;
  12. const sessionUser = this.session.sessionUser;
  13. try {
  14. if (sessionProject.userAccount === undefined) {
  15. throw '不存在对应项目数据';
  16. }
  17. // 判断当前用户是否为管理员
  18. if (sessionUser.account !== sessionProject.userAccount) {
  19. throw '当前用户没有权限';
  20. }
  21. } catch (error) {
  22. this.log(error);
  23. if (this.helper.isAjax(this.request)) {
  24. this.ajaxErrorBody(error, '管理员权限异常');
  25. } else {
  26. this.postError(error, '管理员权限异常');
  27. return this.redirect(this.request.headers.referer);
  28. }
  29. }
  30. yield next;
  31. };
  32. };