Compare commits
No commits in common. "391e859d309d185f62b06234b6e240861a273a0e" and "329732038f2d583765e6809eff7701fb9cc68eba" have entirely different histories.
391e859d30
...
329732038f
|
@ -2,6 +2,7 @@ from flask import *
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
|
from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
|
||||||
|
|
||||||
|
|
||||||
# 初始化蓝图
|
# 初始化蓝图
|
||||||
accountService = Blueprint("accountService", __name__)
|
accountService = Blueprint("accountService", __name__)
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ def signup():
|
||||||
return jsonify({'status': '1'})
|
return jsonify({'status': '1'})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@accountService.route("/login", methods=['GET', 'POST'])
|
@accountService.route("/login", methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
'''
|
'''
|
||||||
|
@ -58,20 +60,7 @@ def login():
|
||||||
username = escape(request.form['username'])
|
username = escape(request.form['username'])
|
||||||
password = escape(request.form['password'])
|
password = escape(request.form['password'])
|
||||||
verified = verify_user(username, password)
|
verified = verify_user(username, password)
|
||||||
#读black.txt文件判断用户是否在黑名单中
|
if verified:
|
||||||
with open('black.txt') as f:
|
|
||||||
for line in f:
|
|
||||||
line = line.strip()
|
|
||||||
if username == line:
|
|
||||||
return jsonify({'status': '5'})
|
|
||||||
with open('black.txt', 'a+') as f:
|
|
||||||
f.seek(0)
|
|
||||||
lines = f.readlines()
|
|
||||||
line=[]
|
|
||||||
for i in lines:
|
|
||||||
line.append(i.strip('\n'))
|
|
||||||
#读black.txt文件判断用户是否在黑名单中
|
|
||||||
if verified and username not in line: #TODO: 一个用户名是另外一个用户名的子串怎么办?
|
|
||||||
# 登录成功,写入session
|
# 登录成功,写入session
|
||||||
session['logged_in'] = True
|
session['logged_in'] = True
|
||||||
session[username] = username
|
session[username] = username
|
||||||
|
@ -79,27 +68,9 @@ def login():
|
||||||
user_expiry_date = get_expiry_date(username)
|
user_expiry_date = get_expiry_date(username)
|
||||||
session['expiry_date'] = user_expiry_date
|
session['expiry_date'] = user_expiry_date
|
||||||
session['visited_articles'] = None
|
session['visited_articles'] = None
|
||||||
f.close()
|
|
||||||
return jsonify({'status': '1'})
|
return jsonify({'status': '1'})
|
||||||
elif verified==0 and password!='黑名单':
|
else:
|
||||||
#输入错误密码次数小于5次
|
|
||||||
return jsonify({'status': '0'})
|
return jsonify({'status': '0'})
|
||||||
else:
|
|
||||||
#输入错误密码次数达到5次
|
|
||||||
with open('black.txt', 'a+') as f:
|
|
||||||
f.seek(0)
|
|
||||||
lines = f.readlines()
|
|
||||||
line = []
|
|
||||||
for i in lines:
|
|
||||||
line.append(i.strip('\n'))
|
|
||||||
if username in line:
|
|
||||||
return jsonify({'status': '5'})
|
|
||||||
else:
|
|
||||||
f.write(username)
|
|
||||||
f.write('\n')
|
|
||||||
return jsonify({'status': '5'})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@accountService.route("/logout", methods=['GET', 'POST'])
|
@accountService.route("/logout", methods=['GET', 'POST'])
|
||||||
|
@ -113,7 +84,6 @@ def logout():
|
||||||
return redirect(url_for('mainpage'))
|
return redirect(url_for('mainpage'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@accountService.route("/reset", methods=['GET', 'POST'])
|
@accountService.route("/reset", methods=['GET', 'POST'])
|
||||||
def reset():
|
def reset():
|
||||||
'''
|
'''
|
||||||
|
@ -139,4 +109,3 @@ def reset():
|
||||||
return jsonify({'status':'1'}) # 修改成功
|
return jsonify({'status':'1'}) # 修改成功
|
||||||
else:
|
else:
|
||||||
return jsonify({'status':'2'}) # 修改失败
|
return jsonify({'status':'2'}) # 修改失败
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
hsy
|
|
|
@ -8,27 +8,7 @@
|
||||||
<link rel="stylesheet" href="static/css/login_service.css">
|
<link rel="stylesheet" href="static/css/login_service.css">
|
||||||
<script src="static/js/jquery.js"></script>
|
<script src="static/js/jquery.js"></script>
|
||||||
<script>
|
<script>
|
||||||
let blackList = [];
|
function login(){
|
||||||
|
|
||||||
<!--function getBlack() {-->
|
|
||||||
<!-- const fs = require('fs');-->
|
|
||||||
<!-- global.blackFile = fs.readFileSync('black', 'utf8');-->
|
|
||||||
<!-- const blackListTemp = blackFile.split('\n');-->
|
|
||||||
<!-- global.blackList = blackListTemp.map(line => line.trim()).filter(line => line !== '');-->
|
|
||||||
<!--}-->
|
|
||||||
|
|
||||||
function putUserIntoBlack(usernameTemp) {
|
|
||||||
|
|
||||||
blackList.push(usernameTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ifUsernameInBlack(usernameTemp) {
|
|
||||||
return blackList.includes(usernameTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
count=0
|
|
||||||
function login()
|
|
||||||
{
|
|
||||||
let username = $("#username").val();
|
let username = $("#username").val();
|
||||||
let password = $("#password").val();
|
let password = $("#password").val();
|
||||||
if (username === "" || password === ""){
|
if (username === "" || password === ""){
|
||||||
|
@ -39,56 +19,17 @@ function ifUsernameInBlack(usernameTemp) {
|
||||||
alert('输入不能包含空格!');
|
alert('输入不能包含空格!');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$.post(
|
||||||
|
|
||||||
$.post
|
|
||||||
(
|
|
||||||
"/login", {'username': username, 'password': password},
|
"/login", {'username': username, 'password': password},
|
||||||
|
function (response) {
|
||||||
function (response)
|
if (response.status === '0') {
|
||||||
{
|
|
||||||
|
|
||||||
if(response.status === '5')
|
|
||||||
{
|
|
||||||
alert('已被加入黑名单,请联系管理员!');
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(!ifUsernameInBlack(username))
|
|
||||||
{
|
|
||||||
if (response.status === '0')
|
|
||||||
{
|
|
||||||
if(count<5)
|
|
||||||
{
|
|
||||||
alert('无法通过验证。');
|
alert('无法通过验证。');
|
||||||
<!--window.location.href = "/login";-->
|
window.location.href = "/login";
|
||||||
count++;
|
} else if (response.status === '1') {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
<!--输入错误密码次数超过5次-->
|
|
||||||
alert('密码输入错误超过五次,已被加入黑名单!');
|
|
||||||
putUserIntoBlack(username);
|
|
||||||
console.log(ifUsernameInBlack(username));
|
|
||||||
response.status=5;
|
|
||||||
$("#password").val('黑名单');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (response.status === '1')
|
|
||||||
{
|
|
||||||
window.location.href = "/"+username+"/userpage";
|
window.location.href = "/"+username+"/userpage";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(ifUsernameInBlack(username))
|
|
||||||
{
|
|
||||||
alert('已被加入黑名单!');
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue