Prevent web crawlers

This commit is contained in:
Aaron Lee 2021-10-04 22:01:32 +08:00
parent 40b429fb7d
commit b1ead76963
4 changed files with 9 additions and 6 deletions

11
app.py
View file

@ -222,14 +222,15 @@ def forgotPassword():
@app.route('/resetPassword', methods=['GET', 'POST']) @app.route('/resetPassword', methods=['GET', 'POST'])
def resetPassword(): def resetPassword():
if request.args.get('oobCode') is None:
return abort(404)
if request.method == 'GET': if request.method == 'GET':
session['oobCode'] = request.args.get('oobCode') return render_template('verifiedChgPassword.html', oobCode=request.args.get('oobCode'))
return render_template('verifiedChgPassword.html')
else: else:
try: try:
if (verify_recaptcha("")): if (verify_recaptcha("")):
auth.verify_password_reset_code( auth.verify_password_reset_code(
session['oobCode'], request.form['password']) request.args.get('oobCode'), request.form['password'])
print("resetPassword success:", flush=True) print("resetPassword success:", flush=True)
session.clear() session.clear()
flash('重置密碼成功,請重新登入<br>Password reset success. Please login again.') flash('重置密碼成功,請重新登入<br>Password reset success. Please login again.')
@ -240,11 +241,11 @@ def resetPassword():
'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.') 'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.')
return redirect('/resetPassword') return redirect('/resetPassword')
except Exception as e: except Exception as e:
print("Error*resetPassword:", session['oobCode'], str(json.loads(e.args[1])[ print("Error*resetPassword:", request.args.get('oobCode'), str(json.loads(e.args[1])[
'error']['message']), flush=True) 'error']['message']), flush=True)
flash(str(json.loads(e.args[1])[ flash(str(json.loads(e.args[1])[
'error']['message'])) 'error']['message']))
return redirect('/resetPassword') return redirect('/resetPassword?mode=resetPassword&oobCode=' + request.args.get('oobCode'))
@ app.route('/logout', methods=['GET']) @ app.route('/logout', methods=['GET'])

View file

@ -4,6 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" />
<title>Attendance 點名系統 (β)</title> <title>Attendance 點名系統 (β)</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous"> integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

View file

@ -4,6 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex" />
<title>Attendance 點名系統 (β)</title> <title>Attendance 點名系統 (β)</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous"> integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

View file

@ -30,7 +30,7 @@
<div class="row"> <div class="row">
<div class="col"></div> <div class="col"></div>
<div class="col-md-5"> <div class="col-md-5">
<form action="/resetPassword" id="password_form" method="post"> <form action="/resetPassword?mode=resetPassword&oobCode={{oobCode}}" id="password_form" method="post">
<div class="form-group row" style="margin-bottom: 10px;"> <div class="form-group row" style="margin-bottom: 10px;">
<label for="password">New Password 新密碼:</label><br> <label for="password">New Password 新密碼:</label><br>
<div class="input-group mb-3 hasSmall"> <div class="input-group mb-3 hasSmall">