diff --git a/app/account_service.py b/app/account_service.py index a7ed0c4..e4ff95b 100644 --- a/app/account_service.py +++ b/app/account_service.py @@ -23,11 +23,39 @@ def signup(): #! 添加如下代码为了过滤注册时的非法字符 warn = WarningMessage(username) if str(warn) != 'OK': - return jsonify({'status': '3', 'warn': str(warn)}) + return str(warn) + # return jsonify({'status': '3', 'warn': str(warn)}) available = check_username_availability(username) if not available: # 用户名不可用 - return jsonify({'status': '0'}) + flash('用户名 %s 已经被注册。' %(username)) + return render_template('signup.html') + elif len(password.strip()) < 8: # 密码过短 + return '密码少于8位。' + # return jsonify({'status': '0'}) + + has_specialchar = False + specialchar_list = ['+', '-', '*', '/', '_', '&', '%', ','] + for c in password.strip(): + if c in specialchar_list: + has_specialchar = True + break + if not has_specialchar: + return '密码必须包含特殊字符' + + has_upper_letter = False + has_lower_letter = False + for c in password.strip(): + if c.isupper(): + has_upper_letter = True + elif c.islower(): + has_lower_letter = True + has_both_letter = has_upper_letter and has_lower_letter + if has_both_letter: + break + if not has_both_letter: + return '密码必须同时包含大写字母和小写字母' + else: # 添加账户信息 add_user(username, password) verified = verify_user(username, password)