示例#1
0
def setLeader():

    resp = {"code": 200, "msg": ""}

    ip = request.remote_addr
    # resp['msg']=ip
    if ip not in app.config["ALLOWED_IP"]:
        resp['code'] = -1
        resp['msg'] = "无权限"
        return jsonify(resp)

    try:
        reqData = json.loads(request.get_data(as_text=True))

        if "token" not in reqData or reqData['token'] != app.config["TOKEN"]:
            resp['code'] = -1
            resp['msg'] = "无权限"
            return jsonify(resp)

        # 首先清空领导名单
        UserService.deleteLeader()
        # 再添加领导名单
        UserService.addLeader(reqData['data']['list'])

    except Exception as e:
        resp['code'] = -1
        resp['msg'] = "请求失败"
        print(e)

    return jsonify(resp)
示例#2
0
def reg():
    if request.method == 'GET':
        return ops_render('member/reg.html')

    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    login_pwd2 = req['login_pwd2'] if 'login_pwd2' in req else ''

    if not login_name or len(login_name) < 1:
        return ops_renderErrJSON(msg="Please input correct username!")

    if not login_pwd or len(login_pwd) < 6:
        return ops_renderErrJSON(
            msg="Please input correct password! At least 6 characters!")

    if login_pwd != login_pwd2:
        return ops_renderErrJSON(
            msg="Password not match!Please check and input again!")

    user_info = User.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrJSON(msg="Username already exist!")

    model_user = User()
    model_user.login_name = login_name
    model_user.nickname = login_name
    model_user.login_salt = UserService.genSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()
    return ops_renderJSON(msg="Register Success!")
示例#3
0
def reg():
    if request.method == "GET":
        return ops_render("member/reg.html")

    req = request.values
    nickname = req['nickname'] if "nickname" in req else ""
    login_name = req['login_name'] if "login_name" in req else ""
    login_pwd = req['login_pwd'] if "login_pwd" in req else ""
    login_pwd2 = req['login_pwd2'] if "login_pwd2" in req else ""

    if login_name is None or len(login_name) < 1:
        return ops_renderErrJSON(msg="请输入正确的登录用户名~~")

    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON(msg="请输入正确的登录密码,并且不能小于6个字符~~")

    if login_pwd != login_pwd2:
        return ops_renderErrJSON(msg="请输入正确的确认登录密码~~")

    user_info = User.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrJSON(msg="登录用户名已被注册,请换一个~~")

    model_user = User()
    model_user.login_name = login_name
    model_user.nickname = nickname if nickname is not None else login_name
    model_user.login_salt = UserService.geneSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()
    return ops_renderJSON(msg="注册成功~~")
示例#4
0
def login():
    if request.method == 'GET':
        return ops_render('member/login.html')

    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    if not login_name or len(login_name) < 1:
        return ops_renderErrJSON(msg="Please input correct username!")

    if not login_pwd or len(login_pwd) < 6:
        return ops_renderErrJSON(
            msg="Please input correct password! At least 6 characters!")

    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        return ops_renderErrJSON("Please input correct username and password!")

    if user_info.login_pwd != UserService.genePwd(login_pwd,
                                                  user_info.login_salt):
        return ops_renderErrJSON("Please input correct username and password!")

    if user_info.status != 1:
        return ops_renderErrJSON("Account has been forbidden!")

    #session['uid'] = user_info.id
    response = make_response(ops_renderJSON(msg="Success!"))
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        '{}#{}'.format(UserService.geneAuthCode(user_info),
                       user_info.id), 60 * 60 * 24 * 120)
    return response
示例#5
0
def login():
    if request.method == "GET":
        return ops_render("member/login.html")
    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ""
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ""

    if login_name is None or len(login_name) < 1:
        return ops_renderErrorJSON("请输入正确的管理员账户名!")

    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrorJSON("请输入正确的密码!")

    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        return ops_renderErrorJSON("请输入正确的管理员账户名和密码!")

    if user_info.login_pwd != UserService.genePwd(login_pwd,
                                                  user_info.login_salt):
        return ops_renderErrorJSON("请输入正确的管理员账户名或密码!")
    if user_info.status != 1:
        return ops_renderErrorJSON("账户被禁用,请联系技术管理员解决!")

    response = make_response(ops_renderJSON(msg="登录成功!"))
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        "%s#%s" % (UserService.geneAuthCode(user_info), user_info.id),
        60 * 60 * 24 * 120)
    return response
示例#6
0
def reg():
    if request.method == "GET":
        return render_template("member/reg.html")

    req = request.values
    login_name = req["login_name"] if "login_name" in req else ""
    login_pwd = req["login_pwd"] if "login_pwd" in req else ""
    login_pwd2 = req["login_pwd2"] if "login_pwd2" in req else ""

    if login_name is None or len(login_name) < 1:
        return ops_renderErrJSON(msg="请输入正确的登陆用户名~~")
    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON(msg="请你输入正确的登陆秘密,并且不能小于6个字符~~")
    if login_pwd != login_pwd2:
        return ops_renderErrJSON(msg="请确认你的登陆秘密是否一致~~")

    user_info = User1.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrJSON(msg="登陆用户名被注册,请换一个~~")

    model_user = User1()
    model_user.login_name = login_name
    model_user.nickname = login_name
    model_user.login_salt = UserService.geneSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd, model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()
    return ops_renderJSON(msg="注册成功~~")
示例#7
0
def reg():
    if request.method == "GET":
        return ops_render("member/reg.html")
    req = request.values  # 如果值在里面则取,不在则取空
    login_name = req['login_name'] if "login_name" in req else ""
    login_pwd = req['login_pwd'] if "login_pwd" in req else ""
    login_pwd2 = req['login_pwd2'] if "login_pwd2" in req else ""

    #后端输入验证
    if login_name is None or len(login_name) < 1:
        return ops_renderErrorJSON(msg="请输入正确的管理员账户名")
    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrorJSON(msg="请正确输入管理员账户密码,并且不能小于6个字符!")
    if login_pwd != login_pwd2:
        return ops_renderErrorJSON(msg="请确认管理员账户密码!")
    #后端数据库信息验证

    user_info = User.query.filter_by(login_name=login_name).first()
    if user_info:
        return ops_renderErrorJSON(msg="此管理员账户名已存在,请重新输入!")

    model_user = User()  #model实例化
    model_user.login_name = login_name
    model_user.login_salt = UserService.geneSalt(8)
    model_user.login_pwd = UserService.genePwd(login_pwd,
                                               model_user.login_salt)
    model_user.created_time = model_user.updated_time = getCurrentTime()
    db.session.add(model_user)
    db.session.commit()

    return ops_renderJSON(msg="注册提交成功,等待审核!")
示例#8
0
def login():
    if request.method == "GET":
        return ops_render("member/login.html")

    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    if login_name is None or len(login_name) < 1:
        return ops_renderErrJSON("请输入正确的登录用户名~~")

    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON("请输入正确的登录密码~~")
    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -1~~")

    if user_info.login_pwd != UserService.genePwd(login_pwd,
                                                  user_info.login_salt):
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -2 ~~")

    if user_info.status != 1:
        return ops_renderErrJSON("账号被禁用,请联系管理员处理~~")

    #session['uid'] = user_info.id
    response = make_response(ops_renderJSON(msg="登录成功~~"))
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        "%s#%s" % (UserService.geneAuthCode(user_info), user_info.id),
        60 * 60 * 24 * 120)
    return response
示例#9
0
def setPersonState():

    resp = {"code": 200, "msg": ""}

    ip = request.remote_addr
    # resp['msg']=ip
    if ip not in app.config["ALLOWED_IP"]:
        resp['code'] = -1
        resp['msg'] = "无权限"
        return jsonify(resp)

    try:
        reqData = json.loads(request.get_data(as_text=True))

        if "token" not in reqData or reqData['token'] != app.config["TOKEN"]:
            resp['code'] = -1
            resp['msg'] = "无权限"
            return jsonify(resp)

        now = datetime.datetime.now()
        str_now = getFormatDate(date=now)

        for item in reqData['data']:
            UserService.updateState(item['state'], item['list'], str_now)

    except Exception as e:
        resp['code'] = -1
        resp['msg'] = "请求失败"
        print(e)

    return jsonify(resp)
示例#10
0
def cancel():
    resp = {"code": 200, "msg": "success", "data": {}}
    req = request.values

    ids = req["ids"] if "ids" in req else None
    if not ids:
        resp["code"] = -1
        resp["msg"] = "请选择审批单"
        return jsonify(resp)

    member_info = g.member_info

    for id in ids.split(","):
        UserService.cancel(member_info.no, id)
    return jsonify(resp)
示例#11
0
def getUserList(usertype):
    resp_data = {"code": 200, "msg": "操作成功", "data": {}}

    # 权限判断
    if g.current_user.super!=1:#超级管理员权限
        resp_data["code"] = -1
        resp_data["msg"] = "无权限"
        return jsonify(resp_data)

    req = request.values
    page = int(req["p"]) if ("p" in req and req["p"]) else 1
    dept = req["dept"] if 'dept' in req else ''
    no = req["no"] if 'no' in req else ''
    name = req["name"] if 'name' in req else ''

    totalCount,userList = UserService.search(usertype,dept,no,name,page,app.config["PAGE_SIZE"])

    page_params = {
        "total": totalCount,
        "page_size": app.config["PAGE_SIZE"],
        "page_num": page,
        "display": app.config["PAGE_DISPLAY"],
    }

    pages = iPagination(page_params)
    
    resp_data["list"] = userList
    resp_data["pages"] = pages
    return jsonify(resp_data)
示例#12
0
def check_login():
    cookies = request.cookies
    auth_cookie = cookies[app.config['AUTH_COOKIE_NAME']] if app.config[
        'AUTH_COOKIE_NAME'] in cookies else None

    if '/api' in request.path:
        app.logger.info(request.path)
        auth_cookie = request.headers.get("Authorization")
        app.logger.info(request.headers.get("Authorization"))

    if auth_cookie is None:
        return False

    auth_info = auth_cookie.split("#")
    if len(auth_info) != 2:
        return False

    try:
        user_info = S_User_Info.query.filter_by(Id=auth_info[1]).first()
    except Exception:
        return False

    if user_info is None:
        return False

    if auth_info[0] != UserService.geneAuthCode(user_info):
        return False

    return user_info
示例#13
0
def update():
    resp_data = {}
    if request.method == 'GET':
        req = request.args
        id = req.get('id')
        info = S_User_Info.query.filter_by(Id=id).first()
        resp_data['info'] = info
        return ops_render('admin/update.html', resp_data)

    req = request.values
    userPwd = req['userPwd'] if 'userPwd' in req else ''

    if userPwd == '':
        resp_data['msg'] = '密码不能为空'
        resp_data['code'] = -1
    info = S_User_Info.query.filter_by(Id=g.current_user.Id).first()
    info.UserPwd = userPwd
    db.session.add(info)
    db.session.commit()

    resp_data['msg'] = '修改成功'
    resp_data['code'] = 200

    response = make_response(json.dumps(resp_data))
    response.set_cookie(app.config['AUTH_COOKIE_NAME'],
                        "%s#%s" % (UserService.geneAuthCode(info), info.Id))
    return response
示例#14
0
def userRegister():
    resp =  {"code": 200, "msg": "注册操作成功", "tel": ""}
    req = request.values
    name = req["name"] if "name" in req else None
    tel = req["tel"] if "tel" in req else None
    adminPhoneList = ["13906040102"]  #凡是管理员的tel都放在这里面
    if not name:
        resp["code"] = -1
        resp["msg"] = "请给出昵称"
        return jsonify(resp)
    if not tel:
        resp["code"] = -1
        resp["msg"] = "请给出电话"
        return jsonify(resp)
    timestamp = int(round(time.time()))
    userid = str(timestamp)
    if str(tel) in adminPhoneList:
        labels = "admin"
    else:
        labels = "user"

    status = UserService.create_user_node(name,userid,tel,labels)
    if status == 1:
        resp["msg"] = "用户注册成功!"
        return jsonify(resp)
    else :
        resp["msg"] = "注册失败,请检查提交的信息"
        return jsonify(resp)
示例#15
0
def addApply():
    resp = {"code": 200, "msg": "success", "data": {}}
    req = request.values

    venueid = req["venueid"] if "venueid" in req else None
    if not venueid:
        resp["code"] = -1
        resp["msg"] = "请选择场所"
        return jsonify(resp)

    reviewer = req["reviewer"] if "reviewer" in req else None
    if not reviewer:
        resp["code"] = -1
        resp["msg"] = "请选择审核人"
        return jsonify(resp)

    starttime = req["starttime"] if "starttime" in req else None
    if not starttime:
        resp["code"] = -1
        resp["msg"] = "请选择开始时间"
        return jsonify(resp)

    endtime = req["endtime"] if "endtime" in req else None
    if not endtime:
        resp["code"] = -1
        resp["msg"] = "请选择结束时间"
        return jsonify(resp)

    reason = req["reason"] if "reason" in req else None
    if not reason:
        resp["code"] = -1
        resp["msg"] = "请填写申请原因"
        return jsonify(resp)

    id = VenueService.geneVenueID()  #生成审批id
    applytime = getFormatDate(date=datetime.datetime.now())

    member_info = g.member_info
    UserService.addApply(member_info.no, venueid, reviewer, id, applytime,
                         starttime, endtime, reason)

    return jsonify(resp)
示例#16
0
def check_user_login():
    userid = request.headers.get("userid")

    # userid="###003###"
    # userid="###003admin###"

    if userid is None:
        return None

    #通过token获取User
    member_info = UserService.getByUserid(userid)
    return member_info
示例#17
0
def approve():
    resp = {"code": 200, "msg": "success", "data": {}}
    req = request.values

    id = req["id"] if "id" in req else None
    if not id:
        resp["code"] = -1
        resp["msg"] = "请选择审批单"
        return jsonify(resp)

    state = int(req["state"]) if ("state" in req and req["state"]) else None
    if not state:
        resp["code"] = -1
        resp["msg"] = "请选择意见"
        return jsonify(resp)

    approvetime = getFormatDate(date=datetime.datetime.now())
    member_info = g.member_info

    UserService.approve(member_info.no, id, state, approvetime)
    return jsonify(resp)
示例#18
0
def login():

    resp = {"code": 200, "msg": "", "data": {}}

    req = request.values
    userno = req["userno"] if "userno" in req else None
    if not userno:
        resp["code"] = -1
        resp["msg"] = "请输入完整信息"
        return jsonify(resp)

    username = req["username"] if "username" in req else None
    if not username:
        resp["code"] = -1
        resp["msg"] = "请输入完整信息"
        return jsonify(resp)

    # 连接数据库匹配count(),等于1则存在账号,登录成功。否则失败
    # if userno!='186123456' or username!='张三':
    exist, userorg = checkExist(userno, username)

    if exist == False:
        resp["code"] = -1
        resp["msg"] = "账号不存在"
        return jsonify(resp)

    usertype = 3
    userid = UserService.geneUserid(userno, app.config["SALT"])

    data = {
        'userno': userno,
        'userorg': userorg,
        'username': username,
        'usertype': usertype,
        'userid': userid
    }
    UserService.updateUser(data)

    resp["data"] = data
    return jsonify(resp)
示例#19
0
def getVenueAndReviewer():
    resp_data = {
        "code": 200,
        "msg": "success",
        "venueList": {},
        "reviewerList": {}
    }

    venueList = VenueService.getVenueIdAndName()
    reviewerList = UserService.getReviewerNoAndName()

    resp_data['venueList'] = venueList
    resp_data['reviewerList'] = reviewerList
    return jsonify(resp_data)
示例#20
0
def getMyApply():
    req = request.values
    pageNum = int(req["pageNum"]) if ("pageNum" in req
                                      and req["pageNum"]) else 1
    pageSize = int(req["pageSize"]) if (
        "pageSize" in req and req["pageSize"]) else app.config["PAGE_SIZE"]
    type = int(req["type"]) if ("type" in req
                                and req["type"]) else 1  #1全部 2未审 3已审

    member_info = g.member_info
    resp_data = {"code": 200, "msg": "success", "data": {}}
    applyList = UserService.getMyApply(member_info.no, type, pageNum, pageSize)

    resp_data['data'] = applyList
    return jsonify(resp_data)
示例#21
0
def getLeader():

    resp = {"code": 200, "msg": ""}

    ip = request.remote_addr
    # resp['msg']=ip
    if ip not in app.config["ALLOWED_IP"]:
        resp['code'] = -1
        resp['msg'] = "无权限"
        return jsonify(resp)

    try:
        reqData = json.loads(request.get_data(as_text=True))
        if "token" not in reqData or reqData['token'] != app.config["TOKEN"]:
            resp['code'] = -1
            resp['msg'] = "无权限"
            return jsonify(resp)

        page_num = reqData['data']['page_num']
        page_size = reqData['data']['page_size']

        totalCount, userList = UserService.getLeader(page_num, page_size)

        page_params = {
            "total": totalCount,
            "page_size": page_size,
            "page_num": page_num,
            "display": app.config["PAGE_DISPLAY"],
        }

        pages = iPaginationForAPI(page_params)
        resp["pages"] = pages
        resp['data'] = userList

    except Exception as e:
        resp['code'] = -1
        resp['msg'] = "请求失败"
        print(e)

    return jsonify(resp)
示例#22
0
def check_login():
    cookies = request.cookies
    cookie_name = app.config['AUTH_COOKIE_NAME']
    auth_cookie = cookies[cookie_name] if cookie_name in cookies else None
    if auth_cookie is None:
        return False
    auth_info = auth_cookie.split("#")
    if len(auth_info) != 2:
        return False

    try:
        user_info = User.query.filter_by(id=auth_info[1]).first()
    except Exception:
        return False

    if user_info is None:
        return False

    if auth_info[0] != UserService.geneAuthCode(user_info):
        return False

    return user_info
示例#23
0
def login():
    if request.method == "GET":
        if g.current_user:
            return redirect(UrlManager.buildUrl("/index"))
        return ops_render('login.html')

    result = {'code': 200, 'msg': '登录成功'}
    value = request.values
    login_name = value['login_name'] if 'login_name' in value else ''
    login_pwd = value['login_pwd'] if 'login_pwd' in value else ''

    if login_name is None or len(login_name) < 1:
        result['code'] = -1
        result['msg'] = 'error'
        return jsonify(result)

    if login_pwd is None or len(login_pwd) < 1:
        result['code'] = -1
        result['msg'] = 'error'
        return jsonify(result)

    user_info = S_User_Info.query.filter_by(UserName=login_name).first()
    if not user_info:
        result['code'] = -1
        result['msg'] = '账号错误'
        return jsonify(result)

    if user_info.UserPwd != login_pwd:
        result['code'] = -1
        result['msg'] = '密码错误'
        return jsonify(result)

    response = make_response(json.dumps(result))
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        "%s#%s" % (UserService.geneAuthCode(user_info), user_info.Id))

    return response
示例#24
0
def userLogin():
    resp = {"code": 200, "msg": "操作成功", "userid": ""}
    req = request.values
    name = req["name"] if "name" in req else None
    tel = req["tel"] if "tel" in req else None
    if not name:
        resp["code"] = -1
        resp["msg"] = "请给出昵称"
        return jsonify(resp)
    if not tel:
        resp["code"] = -1
        resp["msg"] = "请给出电话"
        return jsonify(resp)
    result = UserService.search_user_node(del_uesr_tel)
    if result:
        labels1 = result.labels
        if(labels1=='admin'):
        resp["msg"] = "管理员登录成功"
        else:
        resp["msg"] = "用户登录成功"


    else:
      resp["msg"] = "请去注册"
示例#25
0
def addTrackByAdmin():
    resp = {"code": 1000, "msg": "venue_name", "data": {}}
    req = request.values
    venueid = req["venueid"] if "venueid" in req else None
    if not venueid:
        resp["code"] = -1
        resp["msg"] = "需要场所id"
        return jsonify(resp)

    userid = req["userid"] if "userid" in req else None
    if not userid:
        resp["code"] = -1
        resp["msg"] = "需要用户id"
        return jsonify(resp)

    venue_info = VenueService.getByID(venueid)

    if not venue_info:
        resp["code"] = -1
        resp["msg"] = "场所不存在"
        return jsonify(resp)

    if venue_info.status == -1:
        resp["code"] = -1
        resp["msg"] = "场所已删除"
        return jsonify(resp)

    #通过userid获取User
    member_info = UserService.getByUserid(userid)
    if not member_info:
        resp["code"] = -1
        resp["msg"] = "用户不存在"
        return jsonify(resp)

    if member_info.leader == None:  #不是领导
        resp['data'] = {
            "userdept": member_info.dept,
            "username": member_info.name,
        }
    else:  #是领导
        resp['data'] = {
            "userdept": "",
            "username": "******",
        }

    now = datetime.datetime.now()
    str_now = getFormatDate(date=now)
    # now = datetime.datetime.now()
    # expiretime = now + datetime.timedelta(days=+10)
    # str_now = getFormatDate(date=expiretime)

    currentUser = g.member_info

    # -1直接红码
    if member_info.state == -1:
        # print("红码")
        resp["code"] = 2000
        resp["msg"] = venue_info.name  #获取场所名称返回 放在msg里
        return jsonify(resp)

    # 1直接绿码
    if member_info.state == 1:
        # print("超级用户绿码")
        # 添加轨迹
        TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                   str_now, 1)  #type=1 绿码 2黄码

        resp["code"] = 1001  #1001绿码 1002黄码 #2000红码
        resp["msg"] = venue_info.name  #绿码
        return jsonify(resp)

    # 判断是否有提交过审批 需要审批通过且时间合法
    result2 = UserService.hasLegalApply(member_info.no, venueid, str_now)
    if result2 == True:
        TrackService.create(member_info.no, venueid, str_now, 1)  #绿码
        resp["code"] = 1001  #1001绿码 1002黄码 #2000红码
        resp["msg"] = venue_info.name
        return jsonify(resp)

    permissionType = venue_info.permissionType
    if permissionType == 2:  #对全体教职工开放
        if "TEACHER" in member_info.labels:  #教职工
            # print("绿码")
            TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                       str_now, 1)  #type=1 绿码 2黄码
            resp["code"] = 1001  #1001绿码 1002黄码 #2000红码
            resp["msg"] = venue_info.name  #绿码
            return jsonify(resp)
        else:
            # print("黄码")
            TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                       str_now, 2)  #type=1 绿码 2黄码
            resp["code"] = 1002  #1001绿码 1002黄码 #2000红码
            resp["msg"] = venue_info.name  #绿码
            return jsonify(resp)
    elif permissionType == 3:  #对全体学生开放
        if "STUDENT" in member_info.labels:  #学生
            # print("绿码")
            TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                       str_now, 1)  #type=1 绿码 2黄码
            resp["code"] = 1001  #1001绿码 1002黄码 #2000红码
            resp["msg"] = venue_info.name  #绿码
            return jsonify(resp)
        else:
            # print("黄码")
            TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                       str_now, 2)  #type=1 绿码 2黄码
            resp["code"] = 1002  #1001绿码 1002黄码 #2000红码
            resp["msg"] = venue_info.name  #绿码
            return jsonify(resp)
    elif permissionType == 4:  #对所有人开放
        # print("绿码")
        TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                   str_now, 1)  #type=1 绿码 2黄码
        resp["code"] = 1001  #1001绿码 1002黄码 #2000红码
        resp["msg"] = venue_info.name  #绿码
        return jsonify(resp)
    else:  #permissionType==1 #根据白名单授权

        if member_info.state == None:  #没有赋值过state状态,暂且当做黄码处理
            # 添加轨迹
            TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                       str_now, 2)  #type=1 绿码 2黄码
            resp["code"] = 1002  #1001绿码 1002黄码 #2000红码
            resp["msg"] = venue_info.name  #绿码
            return jsonify(resp)

        if member_info.state == 0:
            # print("需要进一步判断")

            result = TrackService.hasPermission(member_info.no, venueid)
            if result == True:
                # print("有权限")
                type = 1
                resp["code"] = 1001  #1001绿码 1002黄码 #2000红码
            else:
                type = 2
                resp["code"] = 1002  #1001绿码 1002黄码 #2000红码

            # 添加轨迹
            TrackService.createByAdmin(currentUser.no, member_info.no, venueid,
                                       str_now, type)  #绿码
            resp["msg"] = venue_info.name
            return jsonify(resp)
示例#26
0
def getPersonState():

    resp = {"code": 200, "msg": ""}

    ip = request.remote_addr
    # resp['msg']=ip
    if ip not in app.config["ALLOWED_IP"]:
        resp['code'] = -1
        resp['msg'] = "无权限"
        return jsonify(resp)

    try:
        reqData = json.loads(request.get_data(as_text=True))
        if "token" not in reqData or reqData['token'] != app.config["TOKEN"]:
            resp['code'] = -1
            resp['msg'] = "无权限"
            return jsonify(resp)

        page_num = reqData['data']['page_num']
        page_size = reqData['data']['page_size']
        state = reqData['data']['state']
        noList = reqData['data']['XGH']

        if state == "":
            if noList == []:  # print("noList是空")
                totalCount, stateList = UserService.getStateAll(
                    page_num, page_size)
            else:  # print("noList不空")
                totalCount, stateList = UserService.getStateWithNoList(
                    noList, page_num, page_size)

        elif state == "null":  # 查找状态为null的信息
            if noList == []:  # print("noList是空")
                totalCount, stateList = UserService.getStateNull(
                    page_num, page_size)
            else:  # print("noList不空")
                totalCount, stateList = UserService.getStateNullWithNoList(
                    noList, page_num, page_size)

        else:  # print("state不空="+state)
            state = int(state)
            if noList == []:  # print("noList是空")
                totalCount, stateList = UserService.getStateWithState(
                    state, page_num, page_size)
            else:  # print("noList不空")
                totalCount, stateList = UserService.getStateWithNoListAndState(
                    state, noList, page_num, page_size)

        page_params = {
            "total": totalCount,
            "page_size": page_size,
            "page_num": page_num,
            "display": app.config["PAGE_DISPLAY"],
        }

        pages = iPaginationForAPI(page_params)
        resp["pages"] = pages
        resp['data'] = stateList

    except Exception as e:
        resp['code'] = -1
        resp['msg'] = "请求失败"
        print(e)

    return jsonify(resp)