Esempio n. 1
0
def account_post(args):
    username = args.get('email', '').lower()
    password = args.get('password', '')
    if not username or not password:
        return response.bad_request(
            'Either email or password field is empty'
        )

    isEmail = is_valid_email(username)
    if not isEmail:
        return response.bad_request(
            'Email address is malformed'
        )

    user = get_user_by_email(username)
    if user is not None:
        return response.unprocessable_entity(
            'Email address has already been registered'
        )

    new_user = register_account(username, password)
    res = response.created()
    res.set_cookie(
        key='identity_token',
        value=new_user.token,
        expires=new_user.login_expiry,
    )
    return res
Esempio n. 2
0
def blog_post(args):
    title = args.get('title')
    tags = args.get('tags', [])
    text = args.get('text', '')
    if not title:
        return response.unprocessable_entity('Blog title cannot be empty')

    new_blog = add_blog(g.user.id, title, tags, text)
    return response.created({
        'id': new_blog.id,
        'title': new_blog.title,
        'update': new_blog.last_update,
    })
Esempio n. 3
0
def account_email_patch(args, email: str):
    action = args.get('action')
    if action is None:
        return response.unprocessable_entity('Action is required')

    if action == 'logout':
        logout_user(g.user.id)
        g.user = None
        res = response.accepted()
        res.set_cookie(key='identity_token', value='', expires=0)
        return res

    return response.bad_request('Action cannot be handled properly')