Change error message representation

This commit is contained in:
Aaron Lee 2021-10-03 14:03:54 +08:00
parent 88c5e7e90e
commit 16124f7617
3 changed files with 25 additions and 17 deletions

38
app.py
View file

@ -91,7 +91,7 @@ def index():
'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.') 'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.')
return redirect('/') return redirect('/')
except Exception as e: except Exception as e:
print("Error:", email, str(e), flush=True) print("Error*Login:", email, str(e), flush=True)
flash( flash(
'帳號或密碼錯誤,請重新輸入<br>Incorrect username or password') '帳號或密碼錯誤,請重新輸入<br>Incorrect username or password')
return redirect('/') return redirect('/')
@ -131,8 +131,10 @@ def selSubUser():
'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.') 'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.')
return redirect('/select') return redirect('/select')
except Exception as e: except Exception as e:
print("Error:", data, str(e), flush=True) print("Error*select:", session['email'], str(json.loads(e.args[1])[
flash(str(e)) 'error']['message']), flush=True)
flash(str(json.loads(e.args[1])[
'error']['message']))
return redirect('/select') return redirect('/select')
@ -185,21 +187,23 @@ def chgPassword():
data, usr['idToken']) data, usr['idToken'])
except: except:
pass pass
print("Error:", oldEmail, str(e), flush=True) print("Error*chgPassword:", oldEmail, str(json.loads(e.args[1])[
flash(str(e)) 'error']['message']), flush=True)
flash(str(json.loads(e.args[1])[
'error']['message']))
return redirect('/chgPassword') return redirect('/chgPassword')
@app.route('/iforgot', methods=['GET', 'POST']) @app.route('/forgotPassword', methods=['GET', 'POST'])
def iforgot(): def forgotPassword():
if request.method == 'GET': if request.method == 'GET':
return render_template('iforgot.html') return render_template('forgotPassword.html')
elif request.method == 'POST': elif request.method == 'POST':
email = request.form['username'] email = request.form['username']
try: try:
if (verify_recaptcha("")): if (verify_recaptcha("")):
auth.send_password_reset_email(email) auth.send_password_reset_email(email)
print("iforgot email sent:", email, flush=True) print("forgotPassword email sent:", email, flush=True)
flash( flash(
'重置密碼信件已寄出,請至信箱收取<br>Password reset email has been sent to your email. Please check your email.') '重置密碼信件已寄出,請至信箱收取<br>Password reset email has been sent to your email. Please check your email.')
return redirect('/') return redirect('/')
@ -207,11 +211,13 @@ def iforgot():
print("ReC Error:", email, flush=True) print("ReC Error:", email, flush=True)
flash( flash(
'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.') 'reCAPTCHA 錯誤,請稍後再試一次<br>reCAPTCHA Failed. Please try again later.')
return redirect('/iforgot') return redirect('/forgotPassword')
except Exception as e: except Exception as e:
print("Error:", email, str(e), flush=True) print("Error*forgotPassword:", email, str(json.loads(e.args[1])[
flash(str(e)) 'error']['message']), flush=True)
return redirect('/iforgot') flash(str(json.loads(e.args[1])[
'error']['message']))
return redirect('/forgotPassword')
@app.route('/resetPassword', methods=['GET', 'POST']) @app.route('/resetPassword', methods=['GET', 'POST'])
@ -234,8 +240,10 @@ 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:", str(e), flush=True) print("Error*resetPassword:", session['oobCode'], str(json.loads(e.args[1])[
flash(str(e)) 'error']['message']), flush=True)
flash(str(json.loads(e.args[1])[
'error']['message']))
return redirect('/resetPassword') return redirect('/resetPassword')

View file

@ -29,7 +29,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="/iforgot" id="forgotPassword_sel" method="post"> <form action="/forgotPassword" id="forgotPassword_sel" method="post">
<div class="form-group row" style="margin-bottom: 10px;"> <div class="form-group row" style="margin-bottom: 10px;">
<div class="col-3 center"><label for="username" style="font-size: 19px">Username 帳號: </label> <div class="col-3 center"><label for="username" style="font-size: 19px">Username 帳號: </label>
</div> </div>

View file

@ -45,7 +45,7 @@
<button class="btn btn-primary btn-block g-recaptcha" onclick="loadingAnimation()">Login <button class="btn btn-primary btn-block g-recaptcha" onclick="loadingAnimation()">Login
登入</button> 登入</button>
</form> </form>
<a href="/iforgot">Forgot Password 忘記密碼</a> <a href="/forgotPassword">Forgot Password 忘記密碼</a>
<div class="disclaimer" hidden="hidden"> <div class="disclaimer" hidden="hidden">
This site is protected by reCAPTCHA and the Google This site is protected by reCAPTCHA and the Google
<a target="_blank" href="https://policies.google.com/privacy">Privacy Policy</a> and <a target="_blank" href="https://policies.google.com/privacy">Privacy Policy</a> and