2017-07-05 17:47:51 +08:00
|
|
|
import yapi from '../yapi.js'
|
2017-07-10 11:56:53 +08:00
|
|
|
import projectModel from '../models/project.js'
|
2017-07-05 17:47:51 +08:00
|
|
|
class baseController{
|
|
|
|
constructor(ctx){
|
2017-07-10 11:11:35 +08:00
|
|
|
// console.log('baseControler init...')
|
|
|
|
// let router;
|
|
|
|
// if(router === 'user/reg' || 'router/login'){
|
|
|
|
|
|
|
|
// }else{
|
|
|
|
// var a = this.getLoginStatus()
|
|
|
|
// if(a === false){
|
|
|
|
// return ctx.body = {};
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// this.auth = false;
|
2017-07-05 17:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getUid(){
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
getLoginStatus(){
|
2017-07-07 12:04:14 +08:00
|
|
|
// let token = getCookie('_yapi_token');
|
|
|
|
// let uid = getCookie('_yapi_uid');
|
|
|
|
// let usermodel
|
2017-07-06 20:55:02 +08:00
|
|
|
|
2017-07-07 12:04:14 +08:00
|
|
|
// usermode.token === token
|
|
|
|
// return true
|
2017-07-05 17:47:51 +08:00
|
|
|
return true
|
|
|
|
}
|
2017-07-06 19:21:54 +08:00
|
|
|
|
|
|
|
getRole(){
|
|
|
|
return 'admin'
|
|
|
|
}
|
2017-07-10 11:56:53 +08:00
|
|
|
|
|
|
|
async jungeProjectAuth(id){
|
|
|
|
let model = yapi.getInst(projectModel);
|
|
|
|
if(this.getRole() === 'admin') return true;
|
|
|
|
if(!id) return false;
|
|
|
|
let result = await model.get(id);
|
|
|
|
if(result.uid === this.getUid()){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async jungeMemberAuth(id, member_uid){
|
|
|
|
let model = yapi.getInst(projectModel);
|
|
|
|
if(this.getRole() === 'admin') return true;
|
|
|
|
if(!id || !member_uid) return false;
|
|
|
|
let result = await model.checkMemberRepeat(id, member_uid);
|
|
|
|
if(result > 0){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-05 17:47:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = baseController
|