Exemplo n.º 1
0
async def search_users(request: Request) -> HTTPResponse:
    api_key, keywords = get_args(request, 'api_key', 'keywords')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    data = await request.app.moca_users.search_users(keywords)
    return json(data)
Exemplo n.º 2
0
async def get_user_phone_number(request: Request) -> HTTPResponse:
    api_key, userid_list = get_args(request, 'api_key', 'userid_list')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-SM-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    data = await request.app.moca_users.get_user_phone_number(userid_list)
    return json(data)
Exemplo n.º 3
0
async def send_sms_to_users(request: Request) -> HTTPResponse:
    api_key, userid_list, body = get_args(request, 'api_key', 'userid_list',
                                          'body')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-SM-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    data = await request.app.moca_users.send_sms_to_users(userid_list, body)
    return json(data)
Exemplo n.º 4
0
async def get_small_icon(request: Request) -> HTTPResponse:
    userid = get_args(request, 'userid')[0]
    status = await request.app.moca_users.get_small_icon(userid)
    return json({
        'status_code':
        status[0],
        'msg':
        status[1] if status[0] != 0 else 'data:image/jpeg;base64,' +
        b64encode(status[1]).decode('utf-8')
    })
Exemplo n.º 5
0
async def forgot_password(request: Request) -> HTTPResponse:
    api_key, userid = get_args(request, 'api_key', 'userid')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-SM-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.forgot_password(userid)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 6
0
async def search_users_by_name(request: Request) -> HTTPResponse:
    api_key, username = get_args(request, 'api_key', 'username')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.search_users_by_name(username)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 7
0
async def send_phone_login_code(request: Request) -> HTTPResponse:
    api_key, userid, phone = get_args(request, 'api_key', 'userid', 'phone')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.send_phone_login_code(userid, phone)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 8
0
async def verify_email(request: Request) -> HTTPResponse:
    api_key, userid, token = get_args(request, 'api_key', 'userid', 'token')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.verify_email(userid, token)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 9
0
async def lock_my_account(request: Request) -> HTTPResponse:
    api_key, userid, password = get_args(request, 'api_key', 'userid',
                                         'password')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.lock_my_account(userid, password)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 10
0
async def get_users_list(request: Request) -> HTTPResponse:
    api_key, userid, password, start, limit = get_args(request, 'api_key',
                                                       'userid', 'password',
                                                       ('start', int),
                                                       ('limit', int))
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-SM-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    data = await request.app.moca_users.get_users_list(userid, password, start,
                                                       limit)
    return json(data)
Exemplo n.º 11
0
async def change_password(request: Request) -> HTTPResponse:
    api_key, userid, old, new = get_args(request, 'api_key', 'userid', 'old',
                                         'new')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.change_password(userid, old, new)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 12
0
async def login_by_phone(request: Request) -> HTTPResponse:
    api_key, userid, token, phone = get_args(request, 'api_key', 'userid',
                                             'token', 'phone')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.login_by_phone(
        userid, token, phone, server.get_remote_address(request))
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 13
0
async def create_user(request: Request) -> HTTPResponse:
    api_key, username, password, userid, email = get_args(
        request, 'api_key', 'username', 'password', 'userid', 'email')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.create_user(username, password,
                                                      userid, email)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 14
0
async def delete_data_from_storage_by_key(request: Request) -> HTTPResponse:
    api_key, userid, access_token, key = get_args(request, 'api_key', 'userid',
                                                  'access_token', 'key')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.delete_data_from_storage_by_key(
        userid, access_token, key)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 15
0
async def save_my_user_data(request: Request) -> HTTPResponse:
    api_key, userid, access_token, storage, data = get_args(
        request, 'api_key', 'userid', 'access_token', ('storage', int), 'data')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.save_my_user_data(
        userid, access_token, storage, data)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 16
0
async def send_message(request: Request) -> HTTPResponse:
    api_key, from_, to_, access_token, message = get_args(
        request, 'api_key', 'from', 'to', 'access_token', 'message')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.send_message(from_, to_,
                                                       access_token, message)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 17
0
async def update_data_in_storage_by_id(request: Request) -> HTTPResponse:
    api_key, userid, access_token, content_id, data = get_args(
        request, 'api_key', 'userid', 'access_token', ('content_id', int),
        'data')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.update_data_in_storage_by_id(
        userid, access_token, content_id, data)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 18
0
async def add_phone_number(request: Request) -> HTTPResponse:
    api_key, userid, phone, access_token = get_args(request, 'api_key',
                                                    'userid', 'phone',
                                                    'access_token')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.add_phone_number(
        userid, phone, access_token)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 19
0
async def save_small_icon(request: Request) -> HTTPResponse:
    api_key, userid, access_token, icon = get_args(request, 'api_key',
                                                   'userid', 'access_token',
                                                   'icon')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.save_small_icon(
        userid, access_token, icon if isinstance(icon, str) else icon.body)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 20
0
async def save_user_file(request: Request) -> HTTPResponse:
    api_key, userid, access_token, key, data = get_args(
        request, 'api_key', 'userid', 'access_token', 'key', 'data')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.save_user_file(
        userid, access_token, key,
        data if isinstance(data, str) else data.body)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 21
0
async def get_shared_file(request: Request) -> HTTPResponse:
    api_key, key, protection = get_args(request, 'api_key', 'key',
                                        'protection')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.get_shared_file(key, protection)
    return json({
        'status_code':
        status[0],
        'msg':
        status[1] if status[0] != 0 else
        [b64encode(status[1][0]).decode('utf-8'), status[1][1], status[1][2]],
    })
Exemplo n.º 22
0
async def get_user_file(request: Request) -> HTTPResponse:
    api_key, userid, access_token, key = get_args(request, 'api_key', 'userid',
                                                  'access_token', 'key')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.get_user_file(
        userid, access_token, key)
    return json({
        'status_code':
        status[0],
        'msg':
        status[1] if status[0] != 0 else b64encode(status[1]).decode('utf-8'),
    })
Exemplo n.º 23
0
async def select_data_from_storage(request: Request) -> HTTPResponse:
    api_key, userid, access_token, key = get_args(request, 'api_key', 'userid',
                                                  'access_token', 'key')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.select_data_from_storage(
        userid, access_token, key)
    return json({
        'status_code':
        status[0],
        'msg':
        status[1] if status[0] != 0 else [(item[0], item[1], str(item[2]))
                                          for item in status[1]],
    })
Exemplo n.º 24
0
async def share_file(request: Request) -> HTTPResponse:
    api_key, userid, access_token, filename, data, protection, time_limit, info = get_args(
        request, 'api_key', 'userid', 'access_token', 'filename', 'data',
        'protection', ('time_limit', int), 'info')
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.share_file(
        userid, access_token, filename,
        data if isinstance(data, str) else data.body, protection, time_limit,
        info)
    return json({
        'status_code': status[0],
        'msg': status[1],
    })
Exemplo n.º 25
0
async def get_messages(request: Request) -> HTTPResponse:
    api_key, userid, access_token, start, limit = get_args(
        request, 'api_key', 'userid', 'access_token', ('start', int, 0),
        ('limit', int, 1024))
    api_key_status = await request.app.moca_access.check_api_key(
        api_key, '-NR-', request)
    if api_key_status[0] != 0:
        raise Forbidden(api_key_status[1])
    status = await request.app.moca_users.get_messages(userid, access_token,
                                                       start, limit)
    return json({
        'status_code':
        status[0],
        'msg':
        status[1] if status[0] != 0 else [(item[0], item[1], item[2],
                                           str(item[3])) for item in status[1]]
    })