From e42309184df19c7d219b53ac78741c4716a6d2a4 Mon Sep 17 00:00:00 2001 From: bargin <912465467@qq.com> Date: Sun, 23 Apr 2023 19:57:18 +0800 Subject: [PATCH] Optimized HTML tags --- app/account_service.py | 63 +++++++---------------- app/templates/login_success.html | 10 ++++ app/templates/password_change_status.html | 15 ++++++ app/templates/signup_success.html | 11 ++++ 4 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 app/templates/login_success.html create mode 100644 app/templates/password_change_status.html create mode 100644 app/templates/signup_success.html diff --git a/app/account_service.py b/app/account_service.py index 9b1c46b..635f527 100644 --- a/app/account_service.py +++ b/app/account_service.py @@ -1,7 +1,6 @@ from flask import * from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage - # 初始化蓝图 accountService = Blueprint("accountService", __name__) @@ -19,22 +18,15 @@ def signup(): # POST方法需判断是否注册成功,再根据结果返回不同的内容 username = escape(request.form['username']) password = escape(request.form['password']) - password2 = escape(request.form['password2']) - - #! 添加如下代码为了过滤注册时的非法字符 + # ! 添加如下代码为了过滤注册时的非法字符 warn = WarningMessage(username) if str(warn) != 'OK': - return str(warn) - + return jsonify({'status': '3', 'warn': str(warn)}) + available = check_username_availability(username) - if not available: # 用户名不可用 - flash('用户名 %s 已经被注册。' % (username)) - return render_template('signup.html') - elif len(password.strip()) < 4: # 密码过短 - return '密码过于简单。' - elif password != password2: - return '确认密码与输入密码不一致!' - else: # 添加账户信息 + if not available: # 用户名不可用 + return jsonify({'status': '0'}) + else: # 添加账户信息 add_user(username, password) verified = verify_user(username, password) if verified: @@ -44,11 +36,11 @@ def signup(): session['username'] = username session['expiry_date'] = get_expiry_date(username) session['articleID'] = None - return '

恭喜,你已成功注册, 你的用户名是 %s

\ -

开始使用 返回首页

' % (username, username, username) + return render_template('signup_success.html', username=username) + # session['existing_articles'] = None + # return jsonify({'status': '2'}) else: - return '用户名密码验证失败。' - + return jsonify({'status': '1'}) @accountService.route("/login", methods=['GET', 'POST']) @@ -64,8 +56,7 @@ def login(): return render_template('login.html') else: # 已登录,提示信息并显示登出按钮 - return '你已登录 %s。 登出点击这里。' % ( - session['username'], session['username']) + return render_template('login_success.html', username=session['username']) elif request.method == 'POST': # POST方法用于判断登录是否成功 # check database and verify user @@ -79,10 +70,10 @@ def login(): session['username'] = username user_expiry_date = get_expiry_date(username) session['expiry_date'] = user_expiry_date - session['articleID'] = None - return redirect(url_for('user_bp.userpage', username=username)) + session['existing_articles'] = None + return jsonify({'status': '1'}) else: - return '无法通过验证。' + return jsonify({'status': '0'}) @accountService.route("/logout", methods=['GET', 'POST']) @@ -115,31 +106,15 @@ def reset(): # POST请求用于提交修改后信息 old_password = escape(request.form['old-password']) new_password = escape(request.form['new-password']) - re_new_password = escape(request.form['re-new-password']) # 确认新密码 - if re_new_password != new_password: #验证新密码两次输入是否相同 + if re_new_password != new_password: # 验证新密码两次输入是否相同 return '新密码不匹配,请重新输入' - if len(new_password) < 4: #验证新密码长度,原则参照注册模块 + if len(new_password) < 4: # 验证新密码长度,g原则参照注册模块 return '密码过于简单。(密码长度至少4位)' - flag = change_password(username, old_password, new_password) # flag表示是否修改成功 + flag = change_password(username, old_password, new_password) # flag表示是否修改成功 if flag: session['logged_in'] = False - return \ -''' - - -''' - + return render_template('password_change_status.html', message="密码修改成功,请重新登录。", path="/login") else: - return \ -''' - - -''' + return render_template('password_change_status.html', message="密码修改失败", path="/reset") diff --git a/app/templates/login_success.html b/app/templates/login_success.html new file mode 100644 index 0000000..eca571f --- /dev/null +++ b/app/templates/login_success.html @@ -0,0 +1,10 @@ + + + + + 已成功登录 + + + 你已登录 {{ username}}。 登出点击这里。 + + \ No newline at end of file diff --git a/app/templates/password_change_status.html b/app/templates/password_change_status.html new file mode 100644 index 0000000..a2e426f --- /dev/null +++ b/app/templates/password_change_status.html @@ -0,0 +1,15 @@ + + + + + 密码修改提示 + + + + + + + \ No newline at end of file diff --git a/app/templates/signup_success.html b/app/templates/signup_success.html new file mode 100644 index 0000000..75d46f8 --- /dev/null +++ b/app/templates/signup_success.html @@ -0,0 +1,11 @@ + + + + + 注册成功 + + +

恭喜,你已成功注册, 你的用户名是 {{ username }}

+

开始使用 返回首页

+ +