update-redis

merge-requests/6/head
王宇洋 3 years ago
commit ff28d96ec8

@ -35,17 +35,17 @@ def login():
user = User.query.filter_by(student_id=student_id).first()
if user is None:
flash("Your StudentID/OrganizationID has not been registered")
return render_template('auth/login.html')
return redirect(url_for('auth.login'))
elif user.verify_password(password) is False:
flash("StudentID/OrganizationID or password error")
return render_template('auth/login.html')
return redirect(url_for('auth.login'))
if user is not None and user.verify_password(password):
login_user(user, True)
next = request.args.get('next')
if next is None or not next.startswith('/'):
next = url_for('main.index')
return redirect(next)
return render_template('auth/login.html')
return redirect(url_for('auth.login'))
# # 登录
@ -112,23 +112,23 @@ def register():
is_student = Students.query.filter_by(student_id=request.form["BJUT_id"]).first() # 学号
if is_student is None:
flash("Sorry, you are not a BJUT student and cannot sign up for this account.")
return render_template('auth/register.html')
return redirect(url_for('auth.login'))
if is_student.id_number != request.form["id_num"]:
flash("Your student ID does not match your ID number, you cannot register for this account.")
return render_template('auth/register.html')
return redirect(url_for('auth.login'))
if is_student is not None and is_student.id_number == request.form["id_num"]:
if is_student.confirmed:
flash("Your student number has been registered, you cannot register for a second SOFB account")
return render_template('auth/register.html')
return redirect(url_for('auth.login'))
else:
email_find = User.query.filter_by(email=request.form["email"]).first()
if email_find is not None:
flash("Your email has been registered, please change your email")
return render_template('auth/register.html')
return redirect(url_for('auth.login'))
username_find = User.query.filter_by(username=request.form["user_name"]).first()
if username_find is not None:
flash("Your username has been registered, please change your username")
return render_template('auth/register.html')
return redirect(url_for('auth.login'))
student = Students.query.filter_by(student_id=request.form["BJUT_id"]).first()
user = User(email=request.form["email"],
ID_number=request.form["id_num"],

@ -684,6 +684,23 @@ def follow(username):
flash('You are now following %s.' % username)
return redirect(url_for('.user', username=username))
@main.route('/AJAXfollow/<username>', methods=['POST'], strict_slashes=False)
@csrf.exempt
@permission_required(Permission.FOLLOW)
def AJAXfollow(username):
if current_user is None:
return redirect(url_for("/"))
user = User.query.filter_by(username=username).first()
if user is not None:
if current_user.is_following(user):
current_user.unfollow(user)
db.session.commit()
return jsonify({'code': 200, 'like': False})
else:
current_user.follow(user)
db.session.commit()
return jsonify({'code': 200, 'like': True})
@main.route('/unfollow/<username>')
@login_required

@ -25,9 +25,20 @@
{% block body %}
<div id="onepagebg" class="onepage-bg" style="width: 100%;height: 100%;text-align: center">
{% with messages =get_flashed_messages() %}
{% if messages %}
<ul style="background-color: red;color: white;padding: 4px">
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% else %}
<br>
{% endif %}
{% endwith %}
<div class="mainbox" id="mainbox">
<div class="form-container sign-up-container" style="overflow:scroll">
<form class="form-signin" method="post" style="margin: 75px auto 0 auto;">
<form class="form-signin" action="{{ url_for("auth.register") }}" method="post" style="margin: 75px auto 0 auto;">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<h1 class="form-signin-heading">Register</h1>
@ -121,12 +132,13 @@
<script src={{ url_for('static',filename='js/login-and-register.js') }}></script>
<script>
var stuID = document.getElementById('inputName');
var stuID1 = document.getElementById('inputName');
var info = document.getElementById('p1');
var pwd = document.getElementById('inputPassword');
var captcha;
//学号
stuID.onblur = function () {
var stuid = this.value;
a= function () {
var stuid = stuID1.value;
var reg = /[0-9]{1,4}/;
{#var reg = /^\d{18}$/;#}
// 不符合规则的话
@ -138,11 +150,15 @@
info.innerHTML = '';
info.className = 'text-success';
}
if (info.className == 'text-success') {
if (info.className === 'text-success' && captcha.getValidate() !==undefined) {
document.getElementById("submit0").disabled = false;
}
}
stuID1.onblur=a
window.onmousemove=a
var handler = function (captchaObj) {
captcha=captchaObj
$("#submit").click(function (e) {
var result = captchaObj.getValidate();
if (!result) {
@ -179,6 +195,160 @@
}
});
</script>
<script>
// 学号
var stuID = document.getElementById('BJUT_id');
var info = document.getElementById('stuid');
//身份证号
var ID = document.getElementById('id_num');
var IDinfo = document.getElementById('id');
//用户名
var user = document.getElementById('user_name');
var userinfo = document.getElementById('user');
//邮箱
var email = document.getElementById('email');
var ep = document.getElementById('emailp');
//密码
var pw1 = document.getElementById('password');
var pw2 = document.getElementById('confirm_pwd');
var pwdp = document.getElementById('pwd');
//学号
stuID.onblur = function () {
var stuid = this.value;
var reg = /^\d{8}$/;
// 不符合规则的话
if(!reg.test(stuid)){
info.innerHTML = 'Please enter the 8-digit StudentID';
info.className = 'text-danger';
document.getElementById("submit1").disabled=true;
}
else{
info.innerHTML = '';
info.className = 'text-success';
}
{#当所有都满足条件#}
if(pwdp.className === 'text-success'){
if(ep.className === 'text-success'){
if(IDinfo.className === 'text-success'){
if(info.className === 'text-success') {
if(userinfo.className === 'text-success'){
document.getElementById("submit1").disabled = false;
}
}
}
}
}
}
// 身份证号
ID.onblur = function () {
var id = this.value;
var reg = /^[1-9]([0-9]{16}|[0-9]{13})[xX0-9]$/;
// 不符合规则的话
if(!reg.test(id)){
IDinfo.innerHTML = 'Please enter your ID number';
IDinfo.className = 'text-danger';
document.getElementById("submit1").disabled=true;
}
else{
IDinfo.innerHTML = '';
IDinfo.className = 'text-success';
}
{#当所有都满足条件#}
if(pwdp.className === 'text-success'){
if(ep.className === 'text-success'){
if(IDinfo.className === 'text-success'){
if(info.className === 'text-success') {
if(userinfo.className === 'text-success'){
document.getElementById("submit1").disabled = false;
}
}
}
}
}
}
//用户名
user.onblur = function () {
var e = this.value;
if(e == ''){
userinfo.innerHTML = 'The username cannot be empty';
userinfo.className = 'text-danger';
document.getElementById("submit1").disabled=true;
}
else{
userinfo.innerHTML = '';
userinfo.className = 'text-success';
}
{#当所有都满足条件#}
if(pwdp.className == 'text-success'){
if(ep.className == 'text-success'){
if(IDinfo.className == 'text-success'){
if(info.className == 'text-success') {
if(userinfo.className == 'text-success'){
document.getElementById("submit1").disabled = false;
}
}
}
}
}
}
//邮箱
email.onblur = function () {
var e = this.value;
var reg = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
// 不符合规则的话
if(!reg.test(e)){
ep.innerHTML = 'Please enter the correct format of the email';
ep.className = 'text-danger';
document.getElementById("submit1").disabled=true;
}
else{
ep.innerHTML = '';
ep.className = 'text-success';
}
{#当所有都满足条件#}
if(pwdp.className == 'text-success'){
if(ep.className == 'text-success'){
if(IDinfo.className == 'text-success'){
if(info.className == 'text-success') {
if(userinfo.className == 'text-success'){
document.getElementById("submit1").disabled = false;
}
}
}
}
}
}
// 确认密码相同
pw2.onblur = function () {
var pwd1 = pw1.value;
var pwd2 = this.value;
// 不符合规则的话
if( pwd1 != pwd2 ){
pwdp.innerHTML = 'Please enter the same password';
pwdp.className = 'text-danger';
document.getElementById("submit1").disabled=true;
}
else{
pwdp.innerHTML = '';
pwdp.className = 'text-success';
}
{#当所有都满足条件#}
if(pwdp.className == 'text-success'){
if(ep.className == 'text-success'){
if(IDinfo.className == 'text-success'){
if(info.className == 'text-success') {
if(userinfo.className == 'text-success'){
document.getElementById("submit1").disabled = false;
}
}
}
}
}
}
</script>
</div>

@ -202,15 +202,52 @@
&nbsp{{ post.author.college }}</h6>
</div>
{% if current_user.can(Permission.FOLLOW) and post.author != current_user %}
{% if not current_user.is_following(post.author) %}
<a align="center"
href="{{ url_for('.follow', username=post.author.username) }}"
class="btn btn-primary" style="margin-top: 12px">Follow</a>
{% else %}
<a align="center"
href="{{ url_for('.unfollow', username=post.author.username) }}"
class="btn btn-default" style="margin-top: 12px">Unfollow</a>
{% endif %}
{# {% if not current_user.is_following(post.author) %}#}
{# <a align="center"#}
{# href="{{ url_for('.follow', username=post.author.username) }}"#}
{# class="btn btn-primary" style="margin-top: 12px">Follow</a>#}
{# {% else %}#}
{# <a align="center"#}
{# href="{{ url_for('.unfollow', username=post.author.username) }}"#}
{# class="btn btn-default" style="margin-top: 12px">Unfollow</a>#}
{# {% endif %}#}
<a align="center"
href="javascript:void (0);"
class="{% if not current_user.is_following(post.author) %}btn btn-primary{% else %}btn btn-default{% endif %}" style="margin-top: 12px" onclick="{
var csrftoken = $('meta[name=csrf-token]').attr('content');
var _this=this;
var span1=this.childNodes[1];
{#console.log(this.childNodes[3]);#}
{#console.log(this.childElementCount);#}
var sendData={
'csrf_token':csrftoken
};
$.ajax({
url: '{{ url_for('.AJAXfollow', username=post.author.username) }}',
type: 'POST',
{#dataType: 'json',#}
{#contentType: 'application/json',#}
{#data: JSON.stringify(sendData),#}
success: function(result) {
console.log('success\n'+result);
if(result.like){
_this.innerText='Unfollow'
_this.setAttribute('class','btn btn-default')
}else{
_this.innerText='Follow'
_this.setAttribute('class','btn btn-primary')
}
},
error:function(msg){
console.log(msg);
if(msg.status===403){
window.location.href='{{ url_for('auth.login') }}'
}
}
})
}">{% if not current_user.is_following(post.author) %}Follow{% else %}Unfollow{% endif %}</a>
{% endif %}
</div>
{% endif %}
@ -265,25 +302,67 @@
<!-- 点赞与查看点赞的人 -->
<div class="like-btn">
<!-- 点赞-->
{% if not current_user.is_liking(post) %}
<a class="unlike" href="{{ url_for('.like_inpost', post_id=post.id) }}">
<svg viewBox="0 0 1024 1024" width="25" height="25">
<path d="M889.6 396.8 608 396.8C633.6 262.4 684.8 96 576 44.8 460.8-6.4 454.4 64 441.6 179.2c-12.8 121.6-192 249.6-192 249.6l0 563.2 608 0c83.2-38.4 134.4-377.6 160-499.2C1043.2 371.2 889.6 396.8 889.6 396.8z"
fill="#868686"></path>
<path d="M0 428.8l179.2 0 0 569.6-179.2 0 0-569.6Z" fill="#868686"></path>
</svg>
<div>{{ post.liker.count() }} likes</div>
</a>
{% else %}
<a class="liked" href="{{ url_for('.dislike_inpost', post_id=post.id) }}">
{# {% if not current_user.is_liking(post) %}#}
{# <a class="unlike" href="{{ url_for('.like_inpost', post_id=post.id) }}">#}
{# <svg viewBox="0 0 1024 1024" width="25" height="25">#}
{# <path d="M889.6 396.8 608 396.8C633.6 262.4 684.8 96 576 44.8 460.8-6.4 454.4 64 441.6 179.2c-12.8 121.6-192 249.6-192 249.6l0 563.2 608 0c83.2-38.4 134.4-377.6 160-499.2C1043.2 371.2 889.6 396.8 889.6 396.8z"#}
{# fill="#868686"></path>#}
{# <path d="M0 428.8l179.2 0 0 569.6-179.2 0 0-569.6Z" fill="#868686"></path>#}
{# </svg>#}
{# <div>{{ post.liker.count() }} likes</div>#}
{# </a>#}
{# {% else %}#}
{# <a class="liked" href="{{ url_for('.dislike_inpost', post_id=post.id) }}">#}
{# <svg viewBox="0 0 1024 1024" width="25" height="25">#}
{# <path d="M889.6 396.8 608 396.8C633.6 262.4 684.8 96 576 44.8 460.8-6.4 454.4 64 441.6 179.2c-12.8 121.6-192 249.6-192 249.6l0 563.2 608 0c83.2-38.4 134.4-377.6 160-499.2C1043.2 371.2 889.6 396.8 889.6 396.8z"#}
{# fill="#3688FF"></path>#}
{# <path d="M0 428.8l179.2 0 0 569.6-179.2 0 0-569.6Z" fill="#3688FF"></path>#}
{# </svg>#}
{# <div>{{ post.liker.count() }} likes</div>#}
{# </a>#}
{# {% endif %}#}
<a class="{% if not current_user.is_liking(post) %}unlike{% else %}liked{% endif %}" href="javascript:void (0);" onclick="{
var csrftoken = $('meta[name=csrf-token]').attr('content');
var _this=this;
var fill1=document.getElementById('fill1')
var fill2=document.getElementById('fill2')
var span2=document.getElementById('likes_count')
var sendData={
'csrf_token':csrftoken
};
$.ajax({
url: '{{ url_for('.AJAXlike', post_id=post.id) }}',
type: 'POST',
success: function(result) {
console.log('success\n'+result);
if(result.like){
{#span1.setAttribute('class', 'glyphicon glyphicon-heart');#}
fill1.setAttribute('fill', '#3688FF')
fill2.setAttribute('fill', '#3688FF')
}else{
{#span1.setAttribute('class', 'glyphicon glyphicon-heart-empty');#}
fill1.setAttribute('fill', '#868686')
fill2.setAttribute('fill', '#868686')
}
span2.innerText=result.num+' likes';
},
error:function(msg){
console.log(msg);
if(msg.status===403){
window.location.href='{{ url_for('auth.login') }}'
}
}
})
}">
<svg viewBox="0 0 1024 1024" width="25" height="25">
<path d="M889.6 396.8 608 396.8C633.6 262.4 684.8 96 576 44.8 460.8-6.4 454.4 64 441.6 179.2c-12.8 121.6-192 249.6-192 249.6l0 563.2 608 0c83.2-38.4 134.4-377.6 160-499.2C1043.2 371.2 889.6 396.8 889.6 396.8z"
fill="#3688FF"></path>
<path d="M0 428.8l179.2 0 0 569.6-179.2 0 0-569.6Z" fill="#3688FF"></path>
<path id="fill1" d="M889.6 396.8 608 396.8C633.6 262.4 684.8 96 576 44.8 460.8-6.4 454.4 64 441.6 179.2c-12.8 121.6-192 249.6-192 249.6l0 563.2 608 0c83.2-38.4 134.4-377.6 160-499.2C1043.2 371.2 889.6 396.8 889.6 396.8z"
fill="{% if not current_user.is_liking(post) %}#868686{% else %}#3688FF{% endif %}"></path>
<path id="fill2" d="M0 428.8l179.2 0 0 569.6-179.2 0 0-569.6Z" fill="{% if not current_user.is_liking(post) %}#868686{% else %}#3688FF{% endif %}"></path>
</svg>
<div>{{ post.liker.count() }} likes</div>
</a>
{% endif %}
<div id="likes_count">{{ post.liker.count() }} likes</div>
</a>
<a class="unlike" href="javascript:void (0);" onclick="{
var csrftoken = $('meta[name=csrf-token]').attr('content');
var _this=document.getElementById('follow_answer');

@ -58,13 +58,50 @@
{% endif %}
</h3>
{% if current_user.can(Permission.FOLLOW) and user != current_user %}
{% if not current_user.is_following(user) %}
<a href="{{ url_for('.follow', username=user.username) }}"
class="btn btn-follow">Follow</a>
{% else %}
<a href="{{ url_for('.unfollow', username=user.username) }}" class="btn btn-unfollow"
id="unfollow">Followed</a>
{% endif %}
{# {% if not current_user.is_following(user) %}#}
{# <a href="{{ url_for('.follow', username=user.username) }}"#}
{# class="btn btn-follow">Follow</a>#}
{# {% else %}#}
{# <a href="{{ url_for('.unfollow', username=user.username) }}" class="btn btn-unfollow"#}
{# id="unfollow">Followed</a>#}
{# {% endif %}#}
<a
href="javascript:void (0);"
class="{% if not current_user.is_following(user) %}btn btn-follow{% else %}btn btn-unfollow{% endif %}" onclick="{
var csrftoken = $('meta[name=csrf-token]').attr('content');
var _this=this;
var span1=this.childNodes[1];
{#console.log(this.childNodes[3]);#}
{#console.log(this.childElementCount);#}
var sendData={
'csrf_token':csrftoken
};
$.ajax({
url: '{{ url_for('.AJAXfollow', username=user.username) }}',
type: 'POST',
{#dataType: 'json',#}
{#contentType: 'application/json',#}
{#data: JSON.stringify(sendData),#}
success: function(result) {
console.log('success\n'+result);
if(result.like){
_this.innerText='Unfollow'
_this.setAttribute('class','btn btn-unfollow')
}else{
_this.innerText='Follow'
_this.setAttribute('class','btn btn-follow')
}
},
error:function(msg){
console.log(msg);
if(msg.status===403){
window.location.href='{{ url_for('auth.login') }}'
}
}
})
}">{% if not current_user.is_following(user) %}Follow{% else %}Unfollow{% endif %}</a>
{% endif %}
</li>
<li class="list-group-item info-box" style="color: #727070;">

@ -22,11 +22,13 @@ class Config:
FLASKY_FOLLOWERS_PER_PAGE = 50
FLASKY_COMMENTS_PER_PAGE = 30
FLASKY_LIKER_PER_PAGE = 50
CACHE_TYPE = "simple"
ADMIN_EMAIL=['1148636961@qq.com','me@echo.cool','2721712688@qq.com','1635743062@qq.com']
CACHE_TYPE = os.environ.get('CACHE_TYPE') or "simple"
REDIS_URL = os.environ.get('REDIS_URL') or ""
REDIS_USERNAME = os.environ.get('REDIS_USERNAME') or ""
REDIS_PASSWORD = os.environ.get('REDIS_PASSWORD') or ""
ADMIN_EMAIL = ['1148636961@qq.com', 'me@echo.cool', '2721712688@qq.com', '1635743062@qq.com']
@staticmethod
def init_app(app):

Loading…
Cancel
Save