Пример #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)
Пример #2
0
def wxlogin(userid, password, openid=None):
    udata = UTBL.user_by_userid(userid)
    if openid and udata['openid'] != openid:
        return False
    if udata['password'] == password:
        return True
    else:
        return False
Пример #3
0
def RESOURCE(target=""):
	# 在智慧校园系统中 session丢失
	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')
	print(session)
	userid = userid or 'anonymouse'
	if not objid:
		rtdata['msg'] = 'no objectid'
		rtdata['success'] = 'no'
		return json.dumps(rtdata, cls=DateEncoder)
	action = request.args.get('action')
	if target == 'meeting':
		if action == 'list':
			page = int(request.args.get('page'))
			size = int(request.args.get('page_limit', 20))
			overtime = request.args.get('overtime') == 'yes'
			summary = request.args.get('summary') == 'yes'
			lastid = int(request.args.get('last_id', 0))
			if summary:
				count, datas = MEETING.list_by_objid(objid, lastmid=lastid, page=0, pagesize=size, simple=True, summary=True)
				rtdata['dlen'] = count
				rtdata['data'] = datas
			else:
				datas = MEETING.list_by_objid(objid, lastmid=0, page=lastid, pagesize=0, simple=True)
				rtdata['data'] = datas
		elif action == 'mlist':
			# list for manager
			page = int(request.args.get('page'))
			size = int(request.args.get('page_limit', 20))
			overtime = request.args.get('overtime') == 'yes'
			rpmode = int(request.args.get('rpmode', -1))
			p_start = request.args.get('p_start')
			p_end= request.args.get('p_end')
			holder = userid if request.args.get('holder') == 'yes' else None
			summary = request.args.get('summary') == 'yes' or page == 1
			lastid = int(request.args.get('last_id', 0))
			handler = mgr_actions(objid)
			rtdata['data'] = handler.list_meetings2(rpmode=rpmode, p_start=p_start, p_end=p_end, holder=holder, page=1, size=size, summary=summary, overtime=overtime)
			if summary:
				rtdata['dlen'] = handler.extdata
		elif action == 'mylist':
			userid = request.args['userid']
			ondate = request.args.get('ondate') #could be None
			user_hanlder = user_actions(objid)
			meetings = user_hanlder.user_meetings(userid, ondate)
			if meetings:
				rtdata['data'] = meetings
		elif action == 'full_detail':
			# full detail get by manager
			mid = int(request.args.get('mid', 0))
			if mid > 0:
				handler = mgr_actions(objid)
				rtdata['data'] = handler.fullmeeting(mid)
		else:
			rtdata['success'] = 'no'
	elif target == 'mroom':
		if action == 'list':
			page = int(request.args.get('page'))
			size = int(request.args.get('page_limit', 20))
			summary = request.args.get('summary') == 'yes'
			lastid = int(request.args.get('last_id', 0))
			if summary:
				count, datas = MROOM.list(objid, page, size, lastid=lastid, summary=True)
				rtdata['dlen'] = count
				rtdata['data'] = datas
			else:
				datas = MROOM.list(objid, page, size, lastid=lastid)
				rtdata['data'] = datas
		elif action == 'schedule':
			roomid = int(request.args.get('roomid'))
			handler = mgr_actions(objid)
			period_from = request.args.get("period_from")
			period_end = request.args.get('period_end') #None
			#rtdata['data'] = handler.room_schedule(roomid, ondate, ontime)
			rtdata['data'] = handler.room_schedule2(roomid, period_from=period_from, period_end=period_end)
		elif action == 'available':
			# room available for special request
			ondate = request.args.get('ondate')
			ontime = request.args.get('ontime')
			mtime = int(request.args.get('mtime', 120))
			sign_mode = int(request.args.get('sign_mode'))
			handler = mgr_actions(objid)
			rtdata['data'] = handler.available_rooms(ondate=ondate, ontime=ontime, mtime=mtime, by_sign_mode=sign_mode)
		elif action == 'info':
			roomid = request.args.get["roomid"]
			rtdata['data'] = MROOM.detail(roomid)
		else:
			rtdata['success'] = 'no'
	elif target == 'users':
		if action == 'list':
			page = int(request.args.get('page'))
			size = int(request.args.get('page_limit', 20))
			summary = request.args.get('summary') == 'yes' or page == 1
			lastid = int(request.args.get('last_id', 0))
			onlyreged = request.args.get("onlyreged") == 'yes'
			dpid = request.args.get("departid") # 'dpid1,dpid2,...'
			user_list = USER.list_users(objid, page=page, size=size, only_reged=onlyreged, by_dpid=dpid)
			if not user_list:
				rtdata['success'] = 'no'
			elif summary:
				count = USER.count_users(objid)
				rtdata['dlen'] = count
			rtdata['data'] = user_list
		elif action == 'userinfo':
			uinfo = USER.user_by_userid(userid)
			print(uinfo)
			if uinfo:
				rtdata['data'] = uinfo
			else:
				rtdata['success'] = 'no'
	elif target == 'attenders':
		if action == 'list':
			page = 1
			size = 100
			mid = int(request.args.get('mid', 0))
			mcount = int(request.args.get('mcount', -1))
			# mtimes === mcount; 0 is the first, -1 as not set
			handler = mgr_actions(objid)
			attdrs = handler.list_attenders(mid, mcount)
			#attdrs = ATTENDERS.get_attenders(mid, mtimes=mcount)
			if attdrs:
				rtdata['data'] = attdrs
			else:
				rtdata['data'] = None
				rtdata['success'] = 'no'
	elif target == 'school':
		userid = request.args.get("userid")
		user_hanlder = user_actions(objid)
	return json.dumps(rtdata, cls=DateEncoder)