示例#1
0
async def email(request):
    receiver = {}

    receiver['email'] = request.json['email']
    receiver['nickname'] = request.json['nickname']
    ret = mail(receiver)

    return json_success(ret)
示例#2
0
async def update(request, tid):
    """
    更新字段
    :param request:
    :param uid;
    :return:
    """
    filter = request.json
    res = db.task.update({"_id": tid}, {"$set": filter})
    return json_success(res)
示例#3
0
async def find(request):
    filter, project, sort, skip, limit = parse_find_from_request(request)
    res = db.task.find(
        filter=filter,
        projection=project,
        sort=sort,
        skip=skip,
        limit=limit,
    )
    return json_success(list(res))
示例#4
0
async def update(request, nid):
    """
    更新字段
    :param request:
    :param nid;
    :return:
    """
    filter = request.json
    res = db.notification.update({"_id": nid}, {"$set": filter})
    return json_success(res)
示例#5
0
async def show(request):
    # query, project, sort = parse_find_from_request(request)
    # return Demo(mydb).find(
    #     query=query,
    #     project=project,
    #     sort=sort,
    #     prune=True
    # )
    p = db.info.find_one()
    print(p)
    return json_success(p)
示例#6
0
async def auth(request):
    """
    :param request:
    :return:
    """
    access_token = request.json['access_token']
    QQ_APP_ID = '101834891'
    userId = request.json['userId']
    url = "https://graph.qq.com/user/get_user_info?access_token=" + access_token + "&oauth_consumer_key=" + QQ_APP_ID + "&openid=" + userId;
    p = requests.get(url)

    return json_success(p.json())
示例#7
0
async def add_friend(request):
    uid = request.json['uid']
    session = request['session']
    _id = session['_auth']['uid']
    user = db.user.find_one({"_id": _id})
    friend = user.get('friend', [])
    if uid not in friend:
        friend.append(uid)
    else :
        raise MUTIPLE_FRIEND(reason="请勿重复添加!")
    user['friend'] = friend
    res = db.user.update({"_id": _id}, user)
    return json_success(res)
示例#8
0
async def register(request):
    """
    提交参数应为:{name: xxx, sex:xxx, desc:xxxx}
    :param reqeust:
    :param qq号
    :return:
    """

    query = {"email": request.json['email']}
    user = db.user.find_one(filter=query)
    if user is not None:
        raise ALLREADY_REGISTER_USER(reason="该邮箱已被注册!")
    insert_data = request.json
    insert_data['_id'] = request.json['email']
    res = db.user.insert(insert_data)
    return json_success(res)
示例#9
0
async def create(request):
    session = request['session']
    uid_1 = session['_auth']['uid']
    pid = request.json['pid']
    plan = db.plan.find_one({"_id": pid})
    task = db.task.find({"pid": pid, "$or": [{'uid1': uid_1}, {'uid2': uid_1}]})

    if task != None:
        raise TASK_ALREADY_USE(reason="宁已经有此任务!")
    plan['pid'] = pid
    plan['start'] = request.json['start']
    plan['uid1'] = uid_1
    plan['uid2'] = request.json['uid']
    plan['score'] ={'uid1': 0, 'uid2': 0}
    plan["_id"] = str(random.randint(100000000, 10000000000))
    plan['state'] = 'todo'
    plan['finish'] = {'uid1': [0]*int(plan['days']), 'uid2':[0]*int(plan['days'])}
    db.task.insert(plan)
    return json_success(plan)
示例#10
0
async def find(request):

    p = list(db.info.find())

    return json_success(p)
示例#11
0
async def info(request):
    session = request['session']

    _id = session['_auth']['uid']
    user = db.user.find_one({"_id": _id})
    return json_success(user)
示例#12
0
async def show(request, uid):
    res = db.user.find_one({"_id": uid})
    if res is None:
        raise UNBOUND_USER
    return json_success(res)
示例#13
0
async def create(request):
    # request.json have sender, receiver, message, is_read, time
    notification = request.json
    notification['_id'] = str(random.randint(100000000, 10000000000))
    db.notification.insert(notification)
    return json_success(None)