def account_email_get(email: str): isEmail = is_valid_email(email) if not isEmail: return response.bad_request('Email address is malformed') user = get_user_by_email(email) if user is None: return response.ok({'status': 'unregistered'}) else: return response.ok({'status': 'registered'})
def login_api(args, email: str) -> Response: username = 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') isCredentialValid = is_account_credential_valid(username, password) if not isCredentialValid: return response.forbidden( 'Email and password combination cannot be found') refreshed_user = login_account(username) res = response.ok({ 'id': refreshed_user.id, 'email': refreshed_user.username, 'login': refreshed_user.login_date, 'expiry': refreshed_user.login_expiry, }) res.set_cookie( key='identity_token', value=refreshed_user.token, expires=refreshed_user.login_expiry, ) return res
def blog_id_delete(id: int): try: blog_model = get_blog_by_id(id) except BlogNotFoundException: return response.not_found('Blog cannot be found') if g.user.id != blog_model.author_id: return response.unauthorized( 'Only the author can remove their article') delete_blog_by_model(blog_model) return response.ok()
def blog_id_patch(args, id: int): try: blog_model = get_blog_by_id(id) except BlogNotFoundException: return response.not_found('Blog cannot be found') if g.user.id != blog_model.author_id: return response.unauthorized( 'Only the author can remove their article') tags = args.get('tags', []) text = args.get('text', '') update_blog_by_model(blog_model, tags, text) return response.ok()
def tag_get(): tags = get_all_tags() return response.ok(serialise_tags(tags))
def blog_get(): blogs = get_all_blogs() return response.ok(serialise_blogs(blogs))
def github_webhook(): return response.ok()
def ping(): return response.ok('pong')