Skip to content

Commit

Permalink
个人信息界面修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Cl0udG0d committed May 27, 2020
1 parent e26ffc1 commit e9c0c4b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 15 deletions.
Binary file modified __pycache__/models.cpython-37.pyc
Binary file not shown.
50 changes: 44 additions & 6 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask import render_template, request, redirect, url_for, session, flash
import uuid
from models import User, Log, BaseInfo, InvitationCode,BugList,POC,IPInfo,DomainInfo
from models import User, Log, BaseInfo, InvitationCode,BugList,POC,IPInfo,DomainInfo,Profile
from exts import db
from init import app,redispool
# from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -75,11 +75,45 @@ def setting():
return render_template('setting.html')


@app.route('/editinfo')
@app.route('/editinfo',methods=['GET','POST'])
# @login_required
def editinfo():
return render_template('user-infor.html')

user_id = session.get('user_id')
nowuser = User.query.filter(User.id == user_id).first()
username = nowuser.username
if request.method == 'GET':
profile=Profile.query.filter(Profile.userid == user_id).first()
if not profile:
signature=""
blog=""
else:
signature=profile.signature
blog = profile.blog
return render_template('user-infor.html',username=username,blog=blog,signature=signature)
else:
blog=request.form.get('blog')
signature=request.form.get('signature')
oldpassword=request.form.get('oldpassword')
password1=request.form.get('password1')
password2=request.form.get('password2')
if nowuser.check_password(oldpassword):
if password1!=password2:
flash("两次密码输入不一致 :D")
return render_template('user-infor.html')
else:
profile = Profile.query.filter(Profile.userid == user_id).first()
if not profile:
temp=Profile(userid=user_id,blog=blog,signature=signature)
db.session.add(temp)
else:
profile.blog=blog
profile.signature=signature
nowuser.set_password(password1)
db.session.commit()
return redirect(url_for('user'))
else:
flash("旧密码输入错误 :(")
return render_template('user-infor.html',username=username,blog=blog,signature=signature)


@app.route('/domaindetail/<int:id>',methods=['GET'])
Expand Down Expand Up @@ -126,10 +160,14 @@ def bugdetail(id=None):
# @login_required
def user():
allcode=InvitationCode.query.order_by(InvitationCode.id.desc()).limit(10).all()
user_id = session.get('user_id')
nowuser = User.query.filter(User.id == user_id).first()
username = nowuser.username
profile = Profile.query.filter(Profile.userid == user_id).first()
if request.method == 'GET':
return render_template('user-center.html',allcode=allcode)
return render_template('user-center.html',allcode=allcode,username=username,profile=profile)
else:
return render_template('user-center.html',allcode=allcode)
return render_template('user-center.html',allcode=allcode,username=username,profile=profile)


@app.route('/test_console', methods=['GET', 'POST'])
Expand Down
34 changes: 34 additions & 0 deletions migrations/versions/8542881e833a_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""empty message
Revision ID: 8542881e833a
Revises:
Create Date: 2020-05-27 17:03:22.827796
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8542881e833a'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('profile',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('userid', sa.Integer(), nullable=False),
sa.Column('blog', sa.String(length=100), nullable=True),
sa.Column('signature', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('profile')
# ### end Alembic commands ###
Binary file not shown.
7 changes: 7 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def set_password(self, password):
def check_password(self, password):
return check_password_hash(self.pw_hash, password)

class Profile(db.Model):
__tablename__ = 'profile'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
userid=db.Column(db.Integer, nullable=False)
blog=db.Column(db.String(100), nullable=True)
signature=db.Column(db.Text, nullable=True)


# boolcheck ->true 即 ip ->false 即 domain
class BaseInfo(db.Model):
Expand Down
6 changes: 3 additions & 3 deletions templates/user-center.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<div class="left-context">
<div class="user-self">
<img src="../static/images/dn.jpg">
<p class="name">水兵月</p>
<p>个人博客:xxxxxxxx</p>
<p>简介:快睡觉快睡觉快睡觉快睡觉</p>
<p class="name">{{username}}</p>
<p>个人博客:{{profile.blog}}</p>
<p>简介:{{profile.signature}}</p>
<button onclick="window.location.href='{{ url_for('editinfo') }}'">修改信息</button>
</div>
</div>
Expand Down
45 changes: 39 additions & 6 deletions templates/user-infor.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,60 @@
<div class="tab-content">
<div class="tabPane active" id="tab_1" onmouseover="showAlter('alter')" onmouseout="hideAlter('alter')"
style="display:block;">
<form class="myDate">
<form class="myDate" method="POST">
<ol>
<li>
<label>用户名</label>
<input type="text" name="username" placeholder="xxx" id="username">
<p>{{username}}</p>
</li>
<li>
<label>密 码</label>
<input type="text" name="username" placeholder="******" id="username">
<label>个人博客</label>
<input type="text" name="blog" placeholder="{{blog}}" id="blog">
</li>
<li>
<label>个人签名</label>
<input type="text" name="signature" placeholder="{{signature}}" id="signature">
</li>
<li>
<label>旧密码</label>
<input type="password" name="oldpassword" placeholder="******" id="oldpassword">
</li>
<li>
<label>新密码</label>
<input type="text" name="username" placeholder="*******" id="username">
<input type="password" name="password1" placeholder="*******" id="password1">
</li>
<li>
<label>确认密码</label>
<input type="text" name="username" placeholder="********" id="username">
<input type="password" name="password2" placeholder="********" id="password2">
</li>
</ol>
<button>Submit</button>
</form>
<div class="error" style="
position: relative;
top: 70px;
left: -50px;
width: 400px;
height: 40px;
text-align: center;
line-height: 40px;
overflow: hidden;
color: #b22222;
/* background-color: #ffe4e1;
list-style-type: none;
list-style-type: none;
border: 1px #f08080 solid;
border-radius: 8px;
*/
">
{% with messages = get_flashed_messages() %} {% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %} {% endwith %}
</div>
</div>
</div>
{% endblock %}

0 comments on commit e9c0c4b

Please sign in to comment.