yapi/server_dist/controllers/base.js

169 lines
5.5 KiB
JavaScript
Raw Normal View History

2017-07-05 17:47:51 +08:00
'use strict';
2017-07-10 11:56:53 +08:00
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
2017-07-05 17:47:51 +08:00
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _yapi = require('../yapi.js');
var _yapi2 = _interopRequireDefault(_yapi);
2017-07-10 11:56:53 +08:00
var _project = require('../models/project.js');
var _project2 = _interopRequireDefault(_project);
2017-07-05 17:47:51 +08:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var baseController = function () {
function baseController(ctx) {
(0, _classCallCheck3.default)(this, baseController);
console.log('baseControler init...');
}
(0, _createClass3.default)(baseController, [{
key: 'getUid',
value: function getUid() {
return 0;
}
}, {
key: 'getLoginStatus',
value: function getLoginStatus() {
return true;
}
2017-07-06 19:21:54 +08:00
}, {
key: 'getRole',
value: function getRole() {
return 'admin';
}
2017-07-10 11:56:53 +08:00
}, {
key: 'jungeProjectAuth',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(id) {
var model, result;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
model = _yapi2.default.getInst(_project2.default);
if (!(this.getRole() === 'admin')) {
_context.next = 3;
break;
}
return _context.abrupt('return', true);
case 3:
if (id) {
_context.next = 5;
break;
}
return _context.abrupt('return', false);
case 5:
_context.next = 7;
return model.get(id);
case 7:
result = _context.sent;
if (!(result.uid === this.getUid())) {
_context.next = 10;
break;
}
return _context.abrupt('return', true);
case 10:
return _context.abrupt('return', false);
case 11:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function jungeProjectAuth(_x) {
return _ref.apply(this, arguments);
}
return jungeProjectAuth;
}()
}, {
key: 'jungeMemberAuth',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(id, member_uid) {
var model, result;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
model = _yapi2.default.getInst(_project2.default);
if (!(this.getRole() === 'admin')) {
_context2.next = 3;
break;
}
return _context2.abrupt('return', true);
case 3:
if (!(!id || !member_uid)) {
_context2.next = 5;
break;
}
return _context2.abrupt('return', false);
case 5:
_context2.next = 7;
return model.checkMemberRepeat(id, member_uid);
case 7:
result = _context2.sent;
if (!(result > 0)) {
_context2.next = 10;
break;
}
return _context2.abrupt('return', true);
case 10:
return _context2.abrupt('return', false);
case 11:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
function jungeMemberAuth(_x2, _x3) {
return _ref2.apply(this, arguments);
}
return jungeMemberAuth;
}()
2017-07-05 17:47:51 +08:00
}]);
return baseController;
}();
module.exports = baseController;