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) diff --git a/app/generate.py b/app/generate.py new file mode 100644 index 0000000..ae4ef24 --- /dev/null +++ b/app/generate.py @@ -0,0 +1,48 @@ + +from random import randint +from PIL import Image, ImageDraw, ImageFont + + +def get_random_color(): + # 随机颜色RGB + return randint(120, 200), randint(120, 200), randint(120, 200) + + +def get_random_code(): + # 随机字符 + codes = [[chr(i) for i in range(48, 58)], [chr(i) for i in range(65, 91)], [chr(i) for i in range(97, 123)]] + codes = codes[randint(0, 2)] + return codes[randint(0, len(codes)-1)] + + +def generate_captcha(width=140, height=60, length=4): + # 生成验证码 + img = Image.new("RGB", (width, height), (250, 250, 250)) + draw = ImageDraw.Draw(img) + font = ImageFont.truetype("static/font/font.ttf", size=36) + # 验证码文本 + text = "" + for i in range(length): + c = get_random_code() + text += c + + rand_len = randint(-5, 5) + draw.text((width * 0.2 * (i+1) + rand_len, height * 0.2 + rand_len), c, font=font, fill=get_random_color()) + # 加入干扰线 + for i in range(3): + x1 = randint(0, width) + y1 = randint(0, height) + x2 = randint(0, width) + y2 = randint(0, height) + draw.line((x1, y1, x2, y2), fill=get_random_color()) + # 加入干扰点 + for i in range(16): + draw.point((randint(0, width), randint(0, height)), fill=get_random_color()) + # 保存图片 + img.save("static/captcha/" + text + ".jpg") + return text + ".jpg" + + +if __name__ == "__main__": + for i in range(1000): + generate_captcha() diff --git a/app/main.py b/app/main.py index 4e3f829..873950e 100644 --- a/app/main.py +++ b/app/main.py @@ -105,6 +105,17 @@ def mainpage(): yml=Yaml.yml, number_of_essays=number_of_essays) +@app.route('/index') +def index(): + return render_template("signup.html") + + +@app.route('/get_captcha', methods=['GET']) +def get_captcha(): + img_list = os.listdir("static/captcha") + img = img_list[random.randint(0, 1000)] + return os.path.join("static/captcha", img) + if __name__ == '__main__': ''' diff --git a/app/static/css/login_service.css b/app/static/css/login_service.css index 50277e6..65f5052 100644 --- a/app/static/css/login_service.css +++ b/app/static/css/login_service.css @@ -3,7 +3,7 @@ .container { background-color: #FFFFFF; width: 400px; - height: 500px; + height: 700px; margin: 7em auto; border-radius: 1.5em; box-shadow: 0px 11px 35px 2px rgba(0, 0, 0, 0.14); @@ -40,6 +40,27 @@ font-family: 'Ubuntu', sans-serif; } +/*增加1个类.image*/ +.image{ + width: 39%; + color: rgb(38, 50, 56); + font-weight: 700; + font-size: 14px; + letter-spacing: 1px; + background: rgba(136, 126, 126, 0.04); + padding: 10px 20px; + border: none; + border-radius: 20px; + outline: none; + box-sizing: border-box; + border: 2px solid rgba(124, 16, 97, 0.02); + margin-bottom: 50px; + margin-left: 46px; + text-align: center; + margin-bottom: 27px; + font-family: 'Ubuntu', sans-serif; +} + .btn { width: 50%; border: none; diff --git a/app/static/font/font.ttf b/app/static/font/font.ttf new file mode 100644 index 0000000..7394929 Binary files /dev/null and b/app/static/font/font.ttf differ diff --git a/app/templates/signup.html b/app/templates/signup.html index 9030d41..b1df1d4 100644 --- a/app/templates/signup.html +++ b/app/templates/signup.html @@ -6,7 +6,7 @@ You're logged in already! Logout. {% else %} - + + + +
{{ get_flashed_messages()[0] | safe }}
@@ -56,10 +87,17 @@ You're logged in already! Logout.