Beispiel #1
0
def admin_remove_comment(group_id, comment_id):
    Struct.ObjectId(group_id, 'group_id')
    Struct.ObjectId(comment_id, 'comment_id')

    comment = _admin_get_comment(comment_id, group_id)
    comment.delete()

    return output_comment(comment)
Beispiel #2
0
def visit_remove_comment(group_key, comment_id):
    Struct.ObjectId(comment_id, 'comment_id')

    author_id = get_args('author_id')
    author_token = get_args('author_token')

    if not author_id:
        author_id = _get_default_author_id()

    comment = _visit_get_comment(comment_id, group_key)

    if not comment['anonymous']:
        pass
        # todo
        # verify member
    elif author_id != comment['author_id']:
        raise CommentNotAuthor

    comment.delete()

    return {
        "id": comment_id,
        "updated": now(),
        "deleted": 1,
    }
Beispiel #3
0
def visit_get_comment(group_key, comment_id):
    Struct.ObjectId(comment_id, 'comment_id')

    author_id = get_args('author_id')
    comment = _visit_get_comment(comment_id, group_key)

    return output_comment(comment, author_id)
Beispiel #4
0
def get_post(post_id):
    Struct.ObjectId(post_id)
    post = current_app.mongodb_conn.Post.\
        find_one_by_id_and_open_id(post_id, g.curr_user["open_id"])
    if not post:
        raise PostNotFound

    return output_post(post)
Beispiel #5
0
def get_oauth_access_token(open_id):
    Struct.Id(open_id)

    state = get_param('state', Struct.Sid, True)
    code = get_param('code', Struct.Sid, True)

    if not current_app.sup_oauth.match_random_string(state, open_id):
        raise UserStateInvalid

    ExtUser = current_app.mongodb_conn.ExtUser

    user = ExtUser.find_one_by_open_id(open_id)

    if not user:
        user = ExtUser()
        user['open_id'] = open_id

    try:
        resp = current_app.sup_oauth.get_access_token(code)
        print resp
        assert 'access_token' in resp
    except Exception as e:
        raise RequestAccessTokenFailed('access')

    try:
        profile = current_app.sup_oauth.get_profile(resp['access_token'])
    except current_app.sup_oauth.OAuthInvalidAccessToken as e:
        raise RequestAccessTokenFailed('profile')
    except Exception as e:
        raise UserProfileFailed(str(e))

    try:
        ext_token = current_app.sup_oauth.generate_ext_token(open_id)
    except Exception as e:
        raise UserTokenFailed(str(e))

    user['access_token'] = resp['access_token']
    user['refresh_token'] = resp['refresh_token']
    user['expires_at'] = resp['expires_in'] + now()
    user['token_type'] = resp['token_type']
    user['status'] = ExtUser.STATUS_ACTIVATED

    user['display_name'] = profile['display_name']
    user['title'] = profile['title']
    user['locale'] = profile['locale']
    user['description'] = profile['description']
    user['type'] = profile['type']
    user['snapshot'] = profile['snapshot']
    user['scope'] = pre_process_scope(profile['owner_alias'],
                                      profile['app_alias'])
    user.save()

    logged_user = output_user(user)
    logged_user['token'] = ext_token

    return logged_user
Beispiel #6
0
def admin_remove_group(group_id):
    Struct.ObjectId(group_id, 'group_id')

    comment_group = _admin_get_comment_group(group_id)
    comments = _admin_get_comments(group_id)
    for comment in comments:
        comment.delete()
    comment_group.delete()

    return output_group(comment_group)
Beispiel #7
0
def check_user(open_id):
    Struct.Id(open_id)

    user = g.curr_user

    result = True

    if not user \
            or user['open_id'] != open_id \
            or not user["refresh_token"] \
            or not user["scope"]:
        result = False

    return {'result': result}
Beispiel #8
0
def get_oauth_access_code(open_id):
    Struct.Id(open_id)

    state = current_app.sup_oauth.make_random_string(open_id)

    ext_key = current_app.config.get('EXT_KEY')
    redirect_uri = current_app.config.get('OAUTH_REDIRECT_URI')

    return {
        'state': state,
        'ext_key': ext_key,
        'response_type': 'code',
        'redirect_uri': redirect_uri
    }
Beispiel #9
0
def admin_remove_comments(group_id):
    Struct.ObjectId(group_id, 'group_id')

    def deal_comments(comment_id, group_id):
        Struct.ObjectId(comment_id, 'comment_id')
        comment = _admin_get_comment(comment_id, group_id)
        comment.delete()
        return output_comment(comment)

    comment_ids = get_param('comment_ids', Struct.List)

    return {
        "deleted":
        [deal_comments(comment_id, group_id) for comment_id in comment_ids],
    }
Beispiel #10
0
def update_post(post_id):
    Struct.ObjectId(post_id)
    title = get_param('title', Struct.Attr, required=True)
    content = get_param('content', Struct.Text, required=True)

    post = current_app.mongodb_conn.Post.\
        find_one_by_id_and_open_id(post_id, g.curr_user["open_id"])
    if not post:
        raise PostNotFound

    post["title"] = title
    post["content"] = content
    post["update_time"] = now()
    post.save()

    return output_post(post)
Beispiel #11
0
def logout_user(open_id):
    Struct.Id(open_id)

    user = g.curr_user

    if user:
        try:
            current_app.sup_oauth.logout(user['access_token'])
        except Exception:
            raise LogoutAccessTokenFailed

        user['access_token'] = None
        user['refresh_token'] = None
        user.save()

    return output_user(user)
Beispiel #12
0
def send_test_post(post_id):
    Struct.ObjectId(post_id)
    test_email = get_param('test_mail', Struct.Email, required=True)
    password = get_param('password', Struct.Pwd, required=True)

    profile = current_app.mongodb_conn.Profile.\
        find_one_by_open_id(g.curr_user["open_id"])
    if not profile:
        raise ProfileNotFound

    post = current_app.mongodb_conn.Post.\
        find_one_by_id_and_open_id(post_id, g.curr_user["open_id"])
    if not post:
        raise PostNotFound

    _send_mail(post, profile, password, test_email)

    return output_post(post)
Beispiel #13
0
def send_post(post_id):
    Struct.ObjectId(post_id)
    roles = get_param('selected_roles', Struct.List, required=True)
    password = get_param('password', Struct.Pwd, required=True)

    profile = current_app.mongodb_conn.Profile.\
        find_one_by_open_id(g.curr_user["open_id"])
    if not profile:
        raise ProfileNotFound

    post = current_app.mongodb_conn.Post.\
        find_one_by_id_and_open_id(post_id, g.curr_user["open_id"])
    if not post:
        raise PostNotFound

    to = []
    for role in roles:
        to.extend(_get_member_email_by_role(role))

    if to:
        _send_mail(post, profile, password, to)

    return output_post(post)
Beispiel #14
0
 def deal_comments(comment_id, group_id):
     Struct.ObjectId(comment_id, 'comment_id')
     comment = _admin_get_comment(comment_id, group_id)
     comment.delete()
     return output_comment(comment)
Beispiel #15
0
def admin_get_group_comments(group_id):
    Struct.ObjectId(group_id, 'group_id')

    comments = _admin_get_comments(group_id)

    return [output_comment(comment) for comment in comments]