Exemplo n.º 1
0
def Login():
    '''
    3种情况会调用这个接口,第一种是用户第一次登陆,第二种是取消绑定后账号密码被清空,第三种是账号密码验证被却确定是无效
    :return:
    '''
    try:
        code = request.form['code']
        account = request.form['account']
        password = request.form['password']
    except LoginError as e:
        return jsonify(e.send_msg_back())
    except Exception:
        return jsonify(Fail_msg().res_json_back())
    else:
        result_dict = get_openid_dict_by_code(code)
        if check_result_dict_validate(result_dict):
            # code有效
            if check_user_exist(result_dict['openid'])[0]:
                user_item = User.query.filter_by(openid=result_dict['openid']).first()
                # 用户存在
                token = CDUTToken(account, password).fetch_token(is_fresh=True)
                check_result = Token.check_account(token)
                if check_result:
                    # user_item = User.query.filter_by(open_id=result_dict['openid']).first()
                    user_item.stu_id = account
                    user_item.password = password
                    db.session.commit()
                    return jsonify(token_back(user_item.token).res_json_back())
                else:
                    # 教务处验证不正确
                    return jsonify(success_msg(code=440, res_msg='validate_fail').res_json_back())
            else:
                token = Token(account, password)
                token_string = token.fetch_token()
                check_result = Token.check_account(token_string)
                if check_result:
                    print('不存在逻辑')
                    # 用户不存在
                    new_instance = User(result_dict['openid'], result_dict['session_key'], stu_id=account,
                                        password=password)
                    db.session.add(new_instance)
                    db.session.commit()

                    return jsonify({'token': new_instance.token})
                    db.session.close()
                else:
                    # 教务处验证不正确
                    return jsonify(success_msg(code=440, res_msg='validate_fail').res_json_back())
        else:
            # code无效
            return jsonify(Fail_msg(res_msg='no openId').res_json_back())
Exemplo n.º 2
0
def quit():
    if request.form.get('token'):
        token = request.form.get('token')
        user_item = User.query.filter_by(token=token).first()
        db.session.delete(user_item)
        db.session.commit()
        db.session.close()
        return jsonify(success_msg().res_json_back())
    else:
        return jsonify(Fail_msg(code=440, res_msg='token fail').res_json_back())
Exemplo n.º 3
0
def UserCheckRavel():
    '''
    1.直接登陆是没有传输值进入的,判断此openid数据库里面是否有账号密码,且账号密码可用(通过教务处去拿token),如果没有就放回新用户必须绑定。
    :return:
    '''
    try:
        code = request.form['code']
    except LoginError as e:
        return jsonify(e.send_msg_back())
    except Exception:
        return jsonify(Fail_msg().res_json_back())
    else:
        result_dict = get_openid_dict_by_code(code)
        if check_result_dict_validate(result_dict):
            # code有效
            if check_user_exist(result_dict['openid'])[0]:
                # 用户存在
                User_item = User.query.filter_by(open_id=result_dict['openid']).first()
                is_account_exist = check_account_password_exist(User_item)
                if is_account_exist:
                    # 该账号账号密码存在,验证这个教务处账号是否可用
                    password_show = User_item.decrypt('This is a key123', 'This is an IV456')
                    print(password_show)
                    token = CDUTToken(User_item.stu_id, password_show).fetch_token(is_fresh=True)

                    check_result = Token.check_account(token)
                    if check_result:
                        # 验证成功
                        return jsonify(token_back(User_item.token).res_json_back())
                    else:
                        # 验证失败
                        return jsonify(success_msg(code=406, res_msg='绑定的账号密码存在').res_json_back())
                else:
                    # 该账号账号密码不存在,需要重新绑定,可能是取消绑定,用户在,但是账号密码清空就不会在。
                    return jsonify(success_msg(code=406, res_msg='绑定的账号密码不存在').res_json_back())
            else:
                # 微信用户没有在表内,返回状态值,要用户绑定教务处
                return jsonify(completeInfo().res_json_back())
        else:
            # code无效
            return jsonify(Fail_msg(res_msg='no openId').res_json_back())
Exemplo n.º 4
0
def save_avatar_name():
    if request.form.get('token') and request.form.get('avatar_url') and request.form.get('name'):
        token = request.form.get('token')
        avatar_url = request.form.get('avatar_url')
        name = request.form.get('name')
        user_item = User.query.filter_by(token=token).first()
        if user_item:
            user_item.avatar_url = avatar_url
            user_item.nick_name = name
            db.session.commit()
            db.session.close()
            return jsonify(success_msg().res_json_back())
        else:
            return jsonify(Fail_msg(code=440, res_msg='token fail').res_json_back())
    else:
        return jsonify(Fail_msg(code=440, res_msg='数据表单信息不完整').res_json_back())
Exemplo n.º 5
0
def addMapInfo():
    '''
    id = Column(Integer, primary_key=True)
    marker_latitude = Column(Float)
    marker_longitude = Column(Float)
    submit_user = Column(String(255))
    description = Column(Text)
    validate_time = Column(DateTime)
    :return:
    '''
    if request.form.get('marker_latitude') and request.form.get(
            'marker_longitude') and request.form.get(
                'submit_user') and request.form.get('description'):
        marker_latitude = request.form.get('marker_latitude')
        marker_longitude = request.form.get('marker_longitude')
        submit_user = request.form.get('submit_user')
        description = request.form.get('description')
        if MapInfo.query.filter_by(submit_user=submit_user).first():
            '''
            如果找到用户,更新
            '''
            map_info = MapInfo.query.filter_by(submit_user=submit_user).first()
            map_info.marker_latitude = marker_latitude
            map_info.marker_longitude = marker_longitude
            db.session.commit()
            db.session.close()
        else:
            '''
            如果找不到用户,就添加
            '''
            new_mapInfo = MapInfo(marker_latitude, marker_longitude,
                                  submit_user, description)
            db.session.add(new_mapInfo)
            db.session.commit()
            db.session.close()
        return jsonify(success_msg().res_json_back())
    else:
        return jsonify(Fail_msg(code=440, res_msg='数据表单信息不完整').res_json_back())