Exemplo n.º 1
0
def check_user():  #line:335
    O00O0OOOOOO000000 = {}  #line:336
    """
    以GET请求方式请求服务器(参数为user_id), 
    得到用户想要注册的用户名,
    检测用户名是否已经被注册.
    如果是返回元祖第一个值为零则表示系统是查询所账户不存在, 可以注册
    返回1表示账户存在, 返回2表示账户新注册成功注册(均同时返回新的账户user_id)
    flag = 1时表示查询账户是否存在, flag = 0时表示当前账户不存在并且希望注册新账户
    value -> 200 表示账户未被注册
          -> 201 账户已经被他人注册
          -> 202 账户注册成功
    """#line:347
    if request.method == "POST":  #line:348
        O0OOOOO0000OOOO00 = request.get_data()  #line:349
        try:  #line:351
            OO000OOO000O0OO00 = json.loads(O0OOOOO0000OOOO00)  #line:352
        except:  #line:353
            O00O0OOOOOO000000 = _OO000O00O000OOOO0(
                code=ReturnStatus.ERROR_PSOT_DATA,
                status="Failed",
                detail="POST not json_data!")  #line:354
            OO0OO0O0O0OO0OO0O = Response(
                json.dumps(O00O0OOOOOO000000),
                mimetype='application/json')  #line:355
            OO0OO0O0O0OO0OO0O.headers.add('Server', 'python flask')  #line:356
            return OO0OO0O0O0OO0OO0O  #line:357
        if re.findall(r"wechat", request.headers.get("User-Agent")):  #line:359
            try:  #line:360
                O0O0OOOOO00OOOOOO = OO000OOO000O0OO00["open_id"]  #line:361
                OOOOO0OO00OO00O00 = "Wechat_Mini_Program"  #line:362
            except:  #line:363
                O00O0OOOOOO000000 = _OO000O00O000OOOO0(
                    code=ReturnStatus.ERROR_PARAMS, status="Failed",
                    detail="")  #line:364
        else:  #line:366
            O0O0OOOOO00OOOOOO = OO000OOO000O0OO00["user_id"]  #line:367
            OOOOO0OO00OO00O00 = OO000OOO000O0OO00["passwd"]  #line:368
        try:  #line:369
            O0O0OOO0OO0O0OO0O = OO000OOO000O0OO00["flag"]  #line:370
        except:
            O0O0OOO0OO0O0OO0O = 1  #line:371
        if O0O0OOO0OO0O0OO0O:  #line:372
            OO0OOOO0OOO00OOOO = bcrypt_hash.Sign_In_Check(
                O0O0OOOOO00OOOOOO, OOOOO0OO00OO00O00)  #line:373
            if OO0OOOO0OOO00OOOO[
                    "code"] == ReturnStatus.USER_SUCCESS_SIGN_IN or OO0OOOO0OOO00OOOO[
                        "code"] == ReturnStatus.USER_WECHAT_SIGN:  #line:374
                pass  #line:376
    elif request.method == "GET":  #line:378
        pass  #line:379
    else:  #line:381
        O00O0OOOOOO000000 = _OO000O00O000OOOO0(
            code=ReturnStatus.DATABASE_OFF,
            status="Failed",
            detail="数据库繁忙或遇到技术障碍")  #line:382
        OO0OO0O0O0OO0OO0O = Response(json.dumps(O00O0OOOOOO000000),
                                     mimetype='application/json')  #line:383
        OO0OO0O0O0OO0OO0O.headers.add('Server', 'python flask')  #line:384
        return OO0OO0O0O0OO0OO0O  #line:385
Exemplo n.º 2
0
def login():
    """登录/注册函数
    
    用于用户登录/注册的api接口,
    用户登录是用户上传他的账户名,明文密码,若登录成功服务器返回cookies,账户名,状态码
    登录失败返回账户名,状态码,状态码可能标示该用户未注册,请求注册的信息,或者是密码错误的信息
    注册功能则是请求账户名,明文密码,flag参数为0
    Decorators:
        app.route
    """
    global re_dict

    data = request.get_data()
    try:
        dict_data = json.loads(data)
    except:
        re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PSOT_DATA,
                                     status="Failed",
                                     detail="ERROR_PSOT_DATA")

    if re.findall(r"wechat",
                  request.headers.get("User-Agent")):  # 如果判断用户请求是来自微信小程序
        try:
            user_id = dict_data["open_id"]
            passwd = "Wechat_Mini_Program"
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PARAMS,
                                         status="Failed",
                                         detail="ERROR_PARAMS")

    else:  # 请求来自非小程序端
        try:
            user_id = dict_data["user_id"]
            passwd = dict_data["passwd"]
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PARAMS,
                                         status="Failed",
                                         detail="ERROR_PARAMS")
    try:
        flag = dict_data["flag"]
    except:
        flag = 1  # 填写flag参数不为零或者不填写为登录的意思,而不是注册,注册请填写参数为0
    if flag:
        status = bcrypt_hash.Sign_In_Check(user_id, passwd)
        if status["code"] == ReturnStatus.USER_SUCCESS_SIGN_IN or status[
                "code"] == ReturnStatus.USER_WECHAT_SIGN:
            # 用户登录成功
            re_dict = copy.deepcopy(status)

        elif status["code"] == ReturnStatus.USER_FAILED_SIGN_IN:
            re_dict = copy.deepcopy(status)
        elif status["code"] == ReturnStatus.USER_NOT_SIGN_UP:
            re_dict = copy.deepcopy(status)

    response = Response(json.dumps(re_dict), mimetype='application/json')
    response.headers.add('Server', 'python flask')
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
    response.headers['Access-Control-Allow-Headers'] = 'x-requested-with'
    return response
Exemplo n.º 3
0
def check_user():
    re_dict = {}
    """
    以GET请求方式请求服务器(参数为user_id), 
    得到用户想要注册的用户名,
    检测用户名是否已经被注册.
    如果是返回元祖第一个值为零则表示系统是查询所账户不存在, 可以注册
    返回1表示账户存在, 返回2表示账户新注册成功注册(均同时返回新的账户user_id)
    flag = 1时表示查询账户是否存在, flag = 0时表示当前账户不存在并且希望注册新账户
    value -> 200 表示账户未被注册
          -> 201 账户已经被他人注册
          -> 202 账户注册成功
    """
    if request.method == "POST":
        data = request.get_data()  

        try:
            dict_data = json.loads(data)      
        except:
            re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PSOT_DATA, status="Failed", detail = "POST not json_data!")
            response = Response(json.dumps(re_dict), mimetype = 'application/json')    
            response.headers.add('Server','python flask')     
            response.headers['Access-Control-Allow-Origin'] = '*'
            response.headers['Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
            response.headers['Access-Control-Allow-Headers'] = 'x-requested-with'              
            return response

        if re.findall(r"wechat", request.headers.get("User-Agent")): # 如果判断用户请求是来自微信小程序
            try:
                user_id = dict_data["open_id"]
                passwd  = "Wechat_Mini_Program"
            except:
                re_dict = _Return_Error_Post(code=ReturnStatus.ERROR_PARAMS, status="Failed", detail="")

        else:
            user_id = dict_data["user_id"]
            passwd  = dict_data["passwd"]
        try:
            flag = dict_data["flag"]
        except:flag = 1 # 默认flag为登录的意思,而不是注册
        if flag:
            status = bcrypt_hash.Sign_In_Check(user_id, passwd)
            if status["code"] == ReturnStatus.USER_SUCCESS_SIGN_IN or status["code"] == ReturnStatus.USER_WECHAT_SIGN:
                # 如果用户登录成功则请求同步歌单
                pass
        
    elif request.method == "GET":
        pass
    
    else:
        re_dict = _Return_Error_Post(code=ReturnStatus.DATABASE_OFF, status="Failed", detail = "数据库繁忙或遇到技术障碍")
        response = Response(json.dumps(re_dict), mimetype = 'application/json')    
        response.headers.add('Server','python flask')     
        response.headers['Access-Control-Allow-Origin'] = '*'
        response.headers['Access-Control-Allow-Methods'] = 'OPTIONS,HEAD,GET,POST'
        response.headers['Access-Control-Allow-Headers'] = 'x-requested-with'          
        return response
Exemplo n.º 4
0
def login():  #line:183
    ""  #line:192
    global re_dict  #line:193
    OO0O0O0OO0O0000OO = request.get_data()  #line:195
    try:  #line:196
        OOOO0O0OO0O00OO0O = json.loads(OO0O0O0OO0O0000OO)  #line:197
    except:  #line:198
        re_dict = _OO000O00O000OOOO0(code=ReturnStatus.ERROR_PSOT_DATA,
                                     status="Failed",
                                     detail="post not json_data!")  #line:199
    if re.findall(r"wechat", request.headers.get("User-Agent")):  #line:201
        try:  #line:202
            O0O0000OO0O0O00OO = OOOO0O0OO0O00OO0O["open_id"]  #line:203
            O00O0O0000000O0O0 = "Wechat_Mini_Program"  #line:204
        except:  #line:205
            re_dict = _OO000O00O000OOOO0(code=ReturnStatus.ERROR_PARAMS,
                                         status="Failed",
                                         detail="")  #line:206
    else:  #line:208
        try:  #line:209
            O0O0000OO0O0O00OO = OOOO0O0OO0O00OO0O["user_id"]  #line:210
            O00O0O0000000O0O0 = OOOO0O0OO0O00OO0O["passwd"]  #line:211
        except:  #line:212
            re_dict = _OO000O00O000OOOO0(code=ReturnStatus.ERROR_PARAMS,
                                         status="Failed",
                                         detail="")  #line:213
    try:  #line:214
        OO00O0OOO00O00O0O = OOOO0O0OO0O00OO0O["flag"]  #line:215
    except:
        OO00O0OOO00O00O0O = 1  #line:216
    if OO00O0OOO00O00O0O:  #line:217
        OOO0O0O0OOOO00O00 = bcrypt_hash.Sign_In_Check(
            O0O0000OO0O0O00OO, O00O0O0000000O0O0)  #line:218
        if OOO0O0O0OOOO00O00[
                "code"] == ReturnStatus.USER_SUCCESS_SIGN_IN or OOO0O0O0OOOO00O00[
                    "code"] == ReturnStatus.USER_WECHAT_SIGN:  #line:219
            re_dict = copy.deepcopy(OOO0O0O0OOOO00O00)  #line:221
        elif OOO0O0O0OOOO00O00[
                "code"] == ReturnStatus.USER_FAILED_SIGN_IN:  #line:223
            re_dict = copy.deepcopy(OOO0O0O0OOOO00O00)  #line:224
        elif OOO0O0O0OOOO00O00[
                "code"] == ReturnStatus.USER_NOT_SIGN_UP:  #line:225
            re_dict = copy.deepcopy(OOO0O0O0OOOO00O00)  #line:226
    OO0O000O00000O0OO = Response(json.dumps(re_dict),
                                 mimetype='application/json')  #line:231
    OO0O000O00000O0OO.headers.add('Server', 'python flask')  #line:232
    return OO0O000O00000O0OO  #line:233