Beispiel #1
0
def index():
    # 用户态登录
    # /?objectid=2XaxJgvRj6Udone&objType=2&userid=2y7M3LPNb4odone&timestamp=1586688086&sign=BAC3CB4662B8F8F96794E92780D9E14E
    rtdata = {
        'success': 'yes',
        'msg': 'done',
        'code': 0,
        'data': None,
        'dlen': 0
    }
    objid = request.args.get("objectid", "2XaxJgvRj6Udone")
    userid = request.args.get("userid") or session.get("userid")
    if not userid:
        print("un user---for test set to...")
        userid = 'ytVAOSEv75cdone'
        #userid = '2y7M3LPNb4odone'
    if request.method == 'GET':
        if not userid:
            return abort(404)
        session['userid'] = userid
        if 'action' not in request.args:
            # go for page html
            # check client
            ua = request.headers.get('User-Agent')
            if not objid:
                if cur_config.conf_server('mode') != 'development':
                    loger.error("not development mode and no objectid!")
                    return abort(404)
                print("no objid found. with dev mode: set to 'no_obj_id'")
                session['objectid'] = 'no_obj_id'
            else:
                session['objectid'] = objid
            #print(ua)
            client = check_client(ua)
            uinfo = USER.user_by_userid(userid)
            if uinfo:
                print(f"user in: {uinfo}")
                cookies = {'userid': userid, 'username': uinfo['username']}
            else:
                print("empty userin...")
                cookies = {'userid': userid}
            if client == 'mobile':
                return ASST.cookie_file_respon('statics/htmls/mgm_mobile.html',
                                               cookies)
                #return send_file('statics/htmls/mgm_mobile.html', mimetype='text/html')
            elif client == 'wx':
                return 'wx index page'
            else:
                return send_file('statics/htmls/admin_index.html',
                                 mimetype='text/html')
        openid = session.get("openid")
        if openid:
            user = muser.get(openid)
            rtdata['msg'] = 'logoned-index'
            rtdata['data'] = user.loadtime
        else:
            rtdata['success'] = 'no'
        return json.dumps(rtdata)
    print(request.form)
    return json.dumps(rtdata)
Beispiel #2
0
 def via_cache(cls, cpath, force=False):
     # check for switch cache
     dt = time.time() - cls.last_time
     if dt > cls.switch_time:
         loger.info("time to switch cacher")
         cls.cacheA_Mark = not cls.cacheA_Mark
         cls.cache = cls.cacherA if cls.cacheA_Mark else cls.cacherB
         cls.cache_array = []
         cls.last_time = time.time()
         cls.stimer = Timer(cls.clear_time, cls.cclear)
         cls.stimer.start()
     # real job
     cpath = cls._xpath(cpath)
     if cpath in cls.cache:
         loger.info("%s in cache!" % cpath)
         if cls.C_LOCK is True:
             loger.debug("CHECK: wait for C_LOCK!")
             t = cls.lock_wcount
             while t > 0:
                 time.sleep(cls.lock_wait)
                 if cls.C_LOCK is False:
                     break
                 t -= 1
             loger.error("CHECK: wait for C_CLOCK over time!")
             return None
         cls.cache_array.remove(cpath)
         cls.cache_array.insert(0, cpath)
         return cls.cache[cpath]
     else:
         return None
Beispiel #3
0
def API(target):
    rtdata = {
        'success': 'yes',
        'msg': 'done',
        'code': 0,
        'data': None,
        'dlen': 0
    }
    objid = request.args.get('objectid', "2XaxJgvRj6Udone")
    userid = request.args.get('userid') or session.get('userid')
    #userid = session.get('userid')
    if not userid:
        loger.error("no userid from session!")
        rtdata['success'] = 'no'
        rtdata['msg'] = "未登录"
        return json.dumps(rtdata)
    action = request.args.get('action')
    if request.method == 'GET':
        if target == 'meeting':
            if action == 'mylist':
                userid = request.args['userid']
                ondate = request.args.get('ondate')  #could be None
                user_hanlder = user_actions(objid)
                rt = user_hanlder.user_meetings(userid, ondate)
            elif action == 'sign_status':
                mid = int(request.args.get('mid'))
                mcount = int(request.args.get('mcount', 0))
                rt = ATTENDERS.sign_status(mid, userid, mcount)
            else:
                rt = None
        if rt:
            rtdata['data'] = rt
        else:
            rtdata['success'] = 'no'
        return json.dumps(rtdata)
    # ON POST
    params = request.form.to_dict()
    print(params)
    #action = params.pop('action')
    if not objid:
        rtdata['msg'] = 'no objid!'
        rtdata['success'] = 'no'
        return json.dumps(rtdata, cls=DateEncoder)
    rt = None
    handler = None
    if target == 'meeting':
        if action == 'new':
            roomid = int(params.get("mroom", 0))
            params['holder'] = userid
            handler = mgr_actions(objid)
            mid = handler.newmeeting_safe2(params, getndtime=True)
            if mid is False:
                rt = False
            else:
                rt = {'mid': mid, 'nextdtime': handler.extdata}
        elif action == 'modify':
            # 是否已经结束,是否已经超时
            pass
        elif action == 'sign':
            # 签到
            mid = int(params['mid'])
            userid = params['userid']
            mtimes = int(params.get('mtimes', 0))
            mcount = int(params.get('mcount') or -1)
            roomid = int(params.get("roomid", 0))
            identify_key = params['room_identifier']
            user_hanlder = user_actions(objid)
            rt = user_hanlder.meeting_signin(userid,
                                             mid,
                                             identify_key,
                                             roomid=roomid,
                                             mcount=mcount)
            rtdata['msg'] = user_hanlder.extdata
        elif action == 'ask_off':
            mcount = int(params.get('mcount') or -1)
            remark = params.get("remark")
            userid = params['userid']
            mid = int(params['mid'])
            user_hanlder = user_actions(objid)
            rt = user_hanlder.meeting_off(userid,
                                          mid,
                                          mcount=mcount,
                                          remark=remark)
        elif action == 'delete':
            mid = int(params['mid'])
            mcount = int(params.get('mcount') or 0)
            handler = mgr_actions(objid)
            rt = handler.drop_meeting(mid, mcount)
        elif action == 'mod_rparg':
            # only same rpmode could action
            pass
    elif target == 'mroom':
        if action == 'new':
            roomid = MROOM.new(objid, params)
            if roomid and roomid > 0:
                rt = roomid
            else:
                rt = False
        elif action == 'modify':
            roomid = int(params.pop("roomid"))
            rt = MROOM.update(roomid, **params)
    elif target == 'users':
        if action == 'import':
            users = json_flat_2_list(request.form)['users']
            print(users)
            if len(users) == 1:
                rt = USER.import_user(objid, users[0])
            else:
                # may conflict
                rt = USER.import_multi(users, objid)
            if not rt:
                rtdata['msg'] = "有已经导入的教师"
        elif action == 'importall':
            handler = mgr_actions(objid)
            rt = handler.import_all()
    elif target == 'attenders':
        mid = int(params.pop('mid'))
        # mcount: ""
        mcount = int(params.get('mcount') or -1)
        print(mcount)
        if not mgr_actions.action_ontime(objid, mid, mcount=mcount):
            rtdata['success'] = 'no'
            rtdata['msg'] = '当前会议相关配置不可操作(请确认您操作是否过时会议)'
            return json.dumps(rtdata)
        # 注意区分: 对于重复模式会议,只能修改未开始会议的参会者,当前会议是已完成则不能修改:只有idle状态(before announce)才能修改
        if action == 'add':
            attdrs = json_flat_2_list(params)['attenders']
            print(attdrs)
            rt = ATTENDERS.set_attenders(mid, attdrs, mtimes=mcount)
        elif action == 'delete':
            aid = int(request.form['aid'])
            rt = ATTENDERS.kick(aid)
        elif action == 'role':
            aid = int(request.form['aid'])
            roleid = int(request.form['roleid'])
            if roleid == 0:
                rt = ATTENDERS.set_assistor(aid, unset=True)
            elif roleid == 1:
                rt = ATTENDERS.set_assistor(aid)
        elif action == 'clear':
            mid = int(request.args['mid'])
            rt = ATTENDERS.drop_bymeeting(mid, mtimes=mcount)
        elif action == 'unset_status':
            # 重置状态 == 0
            aid = int(request.form['aid'])
            handler = mgr_actions(objid)
            rt = handler.reset_status(aid)
    elif target == 'message':
        if action == 'send_user':
            wxuserid = request.form['wxuserid']
            content = request.form['content']
            msgtype = request.form.get("msgtype", 'text')
            #ischool = myschool.myschool(objid)
            ischool = app_school(objid)
            msger = pmsgr(ischool, msgtype, content)
            msger.send2user(wxuserid)
    else:
        loger.error("unknown comd!")
        rt = False
    # rt: return value, most of times is return from execute_db, which will return False if not success!
    if not rt:
        rtdata['success'] = 'no'
        if handler:
            rtdata['msg'] = handler.emsg
    elif not rtdata['data']:
        rtdata['data'] = rt
    return json.dumps(rtdata, cls=DateEncoder)