Beispiel #1
0
def get_info():
    if request.method == 'GET':
        requestdict = request.args.to_dict()
        print(requestdict)
        print(type(requestdict))
        # 从登录表找到user,然后读用户表信息
        if not requestdict["token"]:
            return json.dumps({"code": 50000, "message": "没有读到token"})
        else:
            my_token_user_dict = mysqlutil.get_logineduser(
                requestdict["token"])
            print(type(my_token_user_dict))
            print(my_token_user_dict)
            my_user = my_token_user_dict["username"]
            my_userinfo = mysqlutil.get_userinfo(my_user)

            return json.dumps({
                "code": 20000,
                "data": {
                    "name": my_user,
                    "roles": my_userinfo["roles"],
                    "avatar": my_userinfo["avatar"],
                    "introduction": my_userinfo["introduction"]
                }
            })
Beispiel #2
0
def login():
    if request.method == 'POST':
        requestdict = get_post_data()
        # print(requestdict)
        if not requestdict['username'] or not requestdict['password'] or len(str(requestdict['username'])) == 0 or len(
                str(requestdict['password'])) == 0:
            return json.dumps({"code": 50000, "message": "用户名或密码为空"})
        else:
            myusername = requestdict['username']
            mypassword = requestdict['password']

            mypasssaltroledict = mysqlutil.get_userinfo(myusername)
            print(mypasssaltroledict)
            if not mypasssaltroledict:
                return json.dumps({"code": 50043, "message": "账号密码不正确"})
            else:
                resultpass = myencryutils.passwordenc(mypassword, mypasssaltroledict["salt"])
                # print(resultpass)
                if resultpass == mypasssaltroledict["password"]:
                    # print("登录成功")
                    # print(type(requestdict))
                    tokendata = myencryutils.newtoken(myusername, str(mypasssaltroledict["salt"])[-6:])
                    mysqlutil.add_logineduser(tokendata, myusername)
                    # print(tokendata)
                    return json.dumps({"code": 20000, "data": {"token": tokendata}})
                else:
                    return json.dumps({"code": 50043, "message": "账号密码不正确"})
    elif request.method == 'GET':
        return json.dumps({"code": 200, "message": "GET"})
Beispiel #3
0
def make_capture_token():
    myapi = mydbconfig.getmyapi() + "/api/deal_capture_token" + "|"
    # myapi = "http://172.31.61.132:5000/api/deal_capture_token" + "|"
    if request.method == 'POST':
        requestdict = get_post_data()
        print(requestdict)
        if not requestdict['name'] or not requestdict['token'] or len(str(requestdict['name'])) == 0 or len(
                str(requestdict['token'])) == 0:
            return json.dumps({"code": 50000, "data": "参数异常"})
        else:
            myname = requestdict['name']
            mytoken = requestdict['token']

            myusername = get_username_by_request(request)
            if myname != myusername:
                myname = myusername

            if requestdict['createflag'] == '0':
                # 查询token显示
                print("查询")
                tempresult = mysqlutil.get_userinfo(myname)
                return json.dumps(
                    {"code": 20000, "data": "success",
                     "capture_token": myapi + tempresult["capture_token"]})
            else:
                if requestdict['date']:
                    mydate = requestdict['date']
                else:
                    return json.dumps({"code": 50000, "data": "failed", "message": "日期为空"})
                try:
                    mytokens = request.headers.get('X-Token')
                    if not mytokens:
                        return json.dumps({"code": 50000, "data": "failed"})
                    else:
                        print("生成token")
                        my_capture_token = myencryutils.new_capture_token(myname, mytoken)
                        tempdict = {}
                        tempdict['capture_token'] = my_capture_token
                        tempdict['username'] = myname
                        tempdict['validtime'] = mydate
                        # 写入
                        mysqlutil.user_edit(tempdict)
                        # return json.dumps({"code": 20000, "data": "success", "capture_token": my_capture_token})
                except Exception as e:
                    print(e)
                    return json.dumps({"code": 50000, "data": "failed"})
                return json.dumps(
                    {"code": 20000, "data": "success",
                     "capture_token": myapi + my_capture_token})