From e502c1eb5d50812d70a62842206a64b974dc7e45 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 11 Dec 2022 13:14:22 -0800 Subject: [PATCH] add downloading challenge link --- nerochan/routes/auth.py | 14 ++++++++++++-- nerochan/templates/auth/challenge.html | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/nerochan/routes/auth.py b/nerochan/routes/auth.py index 1ca448e..5623573 100644 --- a/nerochan/routes/auth.py +++ b/nerochan/routes/auth.py @@ -1,5 +1,7 @@ -from flask import Blueprint, render_template -from flask import flash, redirect, url_for +from datetime import datetime + +from flask import Blueprint, render_template, request +from flask import flash, redirect, url_for, Response from flask_login import logout_user, current_user from nerochan.forms import UserForm, UserRegistration, UserChallenge @@ -67,6 +69,14 @@ def challenge(handle): flash('Already logged in.') return redirect(url_for('main.index')) + if request.args.get('download'): + fn = int(datetime.utcnow().timestamp()) + return Response( + user.challenge, + mimetype='text/plain', + headers={'Content-Disposition': f'attachment;filename=challenge_{fn}.txt'} + ) + if form.validate_on_submit(): data = { 'data': user.challenge, diff --git a/nerochan/templates/auth/challenge.html b/nerochan/templates/auth/challenge.html index 0fd85b7..1055eb3 100644 --- a/nerochan/templates/auth/challenge.html +++ b/nerochan/templates/auth/challenge.html @@ -6,7 +6,7 @@

challenge

Handle: {{ user.handle }}

-

Challenge: {{ user.challenge }}

+

Challenge: {{ user.challenge }} (download)

Wallet Address: {{ user.wallet_address }}

{% include 'includes/form.html' %}