Skip to content

Instantly share code, notes, and snippets.

@GoldsteinE
Created February 25, 2020 20:01
Show Gist options
  • Save GoldsteinE/2edfe1e04c5c7c4f11a192620bc70afa to your computer and use it in GitHub Desktop.
Save GoldsteinE/2edfe1e04c5c7c4f11a192620bc70afa to your computer and use it in GitHub Desktop.
admin_route = pipe()
@admin_route
def extract_data(request: HttpRequest) -> Ns:
return Ns(
user=request.cookies.get('user'),
authcookie=request.cookies.get('auth'),
)
@admin_route
def get_user_from_db(state: Ns) -> Union[Ns, Err]:
sql_result = run_sql(
'SELECT full_name, is_admin FROM User WHERE login = ? AND cookie = ?',
state.user,
state.authcookie,
)
if sql_result is None:
return Err('user not found')
return Ns(
full_name=sql_result[0],
is_admin=sql_result[1],
)
@admin_route
def form_response(state: Ns) -> Union[Response, Err]:
if not state.is_admin:
Err('access denied')
return format_template('template.html', full_name=state.full_name)
app.route(
'/admin',
admin_route
)
# neomake: skip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment