Изменение профиля: изменение почты, фотографии. Исправлены ошибки в отображении постов
This commit is contained in:
parent
28acfed856
commit
86c1fa11d4
BIN
db/moona_data.db
BIN
db/moona_data.db
Binary file not shown.
123
main.py
123
main.py
@ -27,6 +27,7 @@ app.config['SECRET_KEY'] = 'moona_secret_key'
|
|||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
login_manager.init_app(app)
|
login_manager.init_app(app)
|
||||||
help_arg = False
|
help_arg = False
|
||||||
|
help_arg_2 = False
|
||||||
send_msg = False
|
send_msg = False
|
||||||
secret_code = None
|
secret_code = None
|
||||||
photo = None
|
photo = None
|
||||||
@ -51,7 +52,7 @@ def save_photo(photo, login, post=False, id_post=None):
|
|||||||
with open(f'static/app_image/users_photo/{login}_logo.png', 'wb') as f:
|
with open(f'static/app_image/users_photo/{login}_logo.png', 'wb') as f:
|
||||||
photo.save(f)
|
photo.save(f)
|
||||||
return f'static/app_image/users_photo/{login}_logo.png'
|
return f'static/app_image/users_photo/{login}_logo.png'
|
||||||
elif post and id_post != None:
|
elif post and id_post is not None:
|
||||||
with open(f'static/app_image/post_photo/{login}_post_{id_post}.png', 'wb') as f:
|
with open(f'static/app_image/post_photo/{login}_post_{id_post}.png', 'wb') as f:
|
||||||
photo.save(f)
|
photo.save(f)
|
||||||
return f'../static/app_image/post_photo/{login}_post_{id_post}.png'
|
return f'../static/app_image/post_photo/{login}_post_{id_post}.png'
|
||||||
@ -76,14 +77,25 @@ def main_page():
|
|||||||
def edit_profile(logins):
|
def edit_profile(logins):
|
||||||
global photo
|
global photo
|
||||||
global help_arg
|
global help_arg
|
||||||
|
global help_arg_2
|
||||||
form = RegisterForm()
|
form = RegisterForm()
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
ph_f = False
|
ph_f = False
|
||||||
|
if current_user.photo != '../static/img/None_logo.png':
|
||||||
|
photo = current_user.photo
|
||||||
|
ph_f = True
|
||||||
|
else:
|
||||||
|
photo = None
|
||||||
if form.del_photo.data:
|
if form.del_photo.data:
|
||||||
help_arg = photo
|
help_arg = photo
|
||||||
photo = '../static/img/None_logo.png'
|
photo = '../static/img/None_logo.png'
|
||||||
if form.submit2.data:
|
if form.submit2.data:
|
||||||
user = session.query(User).filter(User.login == logins).first()
|
user = session.query(User).filter(User.login == logins).first()
|
||||||
|
if user.email != form.email.data:
|
||||||
|
if session.query(User).filter(User.email == form.email.data).first():
|
||||||
|
return render_template('edit_profile.html', title='Редактирование профиля', form=form,
|
||||||
|
ph_f=ph_f,
|
||||||
|
message="Такая почта уже есть")
|
||||||
user.name = form.name.data
|
user.name = form.name.data
|
||||||
user.surname = form.surname.data
|
user.surname = form.surname.data
|
||||||
user.age = form.age.data
|
user.age = form.age.data
|
||||||
@ -95,7 +107,11 @@ def edit_profile(logins):
|
|||||||
help_arg = False
|
help_arg = False
|
||||||
user.photo = photo
|
user.photo = photo
|
||||||
session.commit()
|
session.commit()
|
||||||
return redirect('/profile')
|
if user.email == form.email.data:
|
||||||
|
return redirect('/profile')
|
||||||
|
else:
|
||||||
|
help_arg_2 = form.email.data
|
||||||
|
return redirect('/confirmation')
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
if current_user.login == logins:
|
if current_user.login == logins:
|
||||||
form.email.data = current_user.email
|
form.email.data = current_user.email
|
||||||
@ -106,16 +122,12 @@ def edit_profile(logins):
|
|||||||
form.about.data = current_user.about
|
form.about.data = current_user.about
|
||||||
form.password.data = None
|
form.password.data = None
|
||||||
form.password2.data = None
|
form.password2.data = None
|
||||||
if current_user.photo != '../static/img/None_logo.png':
|
|
||||||
photo = current_user.photo
|
|
||||||
ph_f = True
|
|
||||||
else:
|
|
||||||
photo = None
|
|
||||||
return render_template('edit_profile.html', title='Редактирование профиля', form=form, message='', ph_f=ph_f)
|
return render_template('edit_profile.html', title='Редактирование профиля', form=form, message='', ph_f=ph_f)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/profile')
|
@app.route('/profile')
|
||||||
def profile():
|
def profile():
|
||||||
|
global help_arg_2
|
||||||
db_sess = db_session.create_session()
|
db_sess = db_session.create_session()
|
||||||
pub_post = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id, DiaryPost.public == 1).all()
|
pub_post = db_sess.query(DiaryPost).filter(DiaryPost.author == current_user.id, DiaryPost.public == 1).all()
|
||||||
pub_post = pub_post[::-1]
|
pub_post = pub_post[::-1]
|
||||||
@ -141,7 +153,8 @@ def profile():
|
|||||||
if db_sess.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first():
|
if db_sess.query(Like).filter(Like.post == i.id, Like.user == current_user.id).first():
|
||||||
emotion['is_like'] = 1
|
emotion['is_like'] = 1
|
||||||
emotion_pub.append(emotion)
|
emotion_pub.append(emotion)
|
||||||
return render_template('profile.html', title='Профиль', pub_post=pub_post, emotion_pub=emotion_pub)
|
message = 'Ваша почта успешно изменена!' if help_arg_2 == 'EditEmail' else ''
|
||||||
|
return render_template('profile.html', title='Профиль', pub_post=pub_post, emotion_pub=emotion_pub, message=message)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/new_like/<int:user_id>/<int:post_id>/<string:ret_href>')
|
@app.route('/new_like/<int:user_id>/<int:post_id>/<string:ret_href>')
|
||||||
@ -559,46 +572,64 @@ def confirmation():
|
|||||||
global send_msg
|
global send_msg
|
||||||
global secret_code
|
global secret_code
|
||||||
global photo
|
global photo
|
||||||
form = help_arg
|
global help_arg_2
|
||||||
session = db_session.create_session()
|
session = db_session.create_session()
|
||||||
conf = Confirmation()
|
if not help_arg_2:
|
||||||
if not send_msg:
|
form = help_arg
|
||||||
secret_code = secret_key()
|
if not send_msg:
|
||||||
mail(f'Ваш секретный код: {secret_code}', form.email.data, 'Moona Код')
|
secret_code = secret_key()
|
||||||
send_msg = True
|
mail(f'Ваш секретный код: {secret_code}', form.email.data, 'Moona Код')
|
||||||
if conf.validate_on_submit():
|
send_msg = True
|
||||||
if str(conf.code_key.data).strip() == str(secret_code).strip():
|
conf = Confirmation()
|
||||||
if form.photo.data:
|
if conf.validate_on_submit():
|
||||||
user = User(
|
if str(conf.code_key.data).strip() == str(secret_code).strip():
|
||||||
name=form.name.data,
|
if form.photo.data:
|
||||||
surname=form.surname.data,
|
user = User(
|
||||||
login=form.login.data,
|
name=form.name.data,
|
||||||
age=form.age.data,
|
surname=form.surname.data,
|
||||||
about=form.about.data,
|
login=form.login.data,
|
||||||
email=form.email.data,
|
age=form.age.data,
|
||||||
photo=photo,
|
about=form.about.data,
|
||||||
role='user'
|
email=form.email.data,
|
||||||
)
|
photo=photo,
|
||||||
|
role='user'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
user = User(
|
||||||
|
name=form.name.data,
|
||||||
|
surname=form.surname.data,
|
||||||
|
login=form.login.data,
|
||||||
|
age=form.age.data,
|
||||||
|
about=form.about.data,
|
||||||
|
email=form.email.data,
|
||||||
|
role='user',
|
||||||
|
photo='../static/img/Икона.png'
|
||||||
|
)
|
||||||
|
user.set_password(form.password.data)
|
||||||
|
session.add(user)
|
||||||
|
session.commit()
|
||||||
|
send_msg = False
|
||||||
|
return redirect('/login')
|
||||||
else:
|
else:
|
||||||
user = User(
|
return render_template('confirmation_reg.html', title='Подтверждение', form=conf,
|
||||||
name=form.name.data,
|
message='Коды не совпадают')
|
||||||
surname=form.surname.data,
|
return render_template('confirmation_reg.html', title='Подтверждение', form=conf, message='')
|
||||||
login=form.login.data,
|
else:
|
||||||
age=form.age.data,
|
conf = Confirmation()
|
||||||
about=form.about.data,
|
if not send_msg:
|
||||||
email=form.email.data,
|
secret_code = secret_key()
|
||||||
role='user',
|
mail(f'Ваш секретный код: {secret_code}', help_arg_2, 'Moona Код')
|
||||||
photo='../static/img/Икона.png'
|
send_msg = True
|
||||||
)
|
print(secret_code)
|
||||||
user.set_password(form.password.data)
|
if conf.validate_on_submit():
|
||||||
session.add(user)
|
if str(conf.code_key.data).strip() == str(secret_code).strip():
|
||||||
session.commit()
|
user = session.query(User).filter(User.id == current_user.id).first()
|
||||||
send_msg = False
|
user.email = help_arg_2
|
||||||
return redirect('/login')
|
help_arg_2 = 'EditEmail'
|
||||||
else:
|
session.commit()
|
||||||
return render_template('confirmation_reg.html', title='Подтверждение', form=conf,
|
send_msg = False
|
||||||
message='Коды не совпадают')
|
return redirect('/profile')
|
||||||
return render_template('confirmation_reg.html', title='Подтверждение', form=conf, message='')
|
return render_template('confirmation_reg.html', title='Подтверждение', form=conf, message='')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/register', methods=['GET', 'POST'])
|
@app.route('/register', methods=['GET', 'POST'])
|
||||||
|
|||||||
@ -48,9 +48,9 @@ summary {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-top: 25px;
|
|
||||||
background-color: #7fc3ff;
|
background-color: #7fc3ff;
|
||||||
border-radius: 22px;
|
border-radius: 50px;
|
||||||
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
.my_author, .my_post_zag {
|
.my_author, .my_post_zag {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@ -36,16 +36,19 @@ table {
|
|||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
width: 20%;
|
width: 20%;
|
||||||
}
|
}
|
||||||
.user_posts {
|
|
||||||
margin-top: 50px;
|
|
||||||
}
|
|
||||||
.user_posts {
|
.user_posts {
|
||||||
width: 35%;
|
width: 35%;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
margin-top: 50px;
|
||||||
}
|
}
|
||||||
.logout_btn {
|
.logout_btn {
|
||||||
width: 96%;
|
width: 96%;
|
||||||
margin-right: 2%;
|
margin-right: 2%;
|
||||||
margin-left: 2%;
|
margin-left: 2%;
|
||||||
|
}
|
||||||
|
#my_post1 {
|
||||||
|
background-color: #7fc3ff;
|
||||||
|
border-radius: 50px;
|
||||||
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ table {
|
|||||||
}
|
}
|
||||||
.post {
|
.post {
|
||||||
background-color: #7fc3ff;
|
background-color: #7fc3ff;
|
||||||
border-radius: 22px;
|
border-radius: 50px;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
height: 95%;
|
height: 95%;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
|
|||||||
@ -30,19 +30,21 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if message != '' %}
|
||||||
|
<div class="alert alert-danger" role="alert">{{ message }}</div>
|
||||||
|
{% endif %}
|
||||||
<div class="user_posts">
|
<div class="user_posts">
|
||||||
<h1 class="post_zag">Опубликованные посты</h1>
|
<h1 class="post_zag">Опубликованные посты</h1>
|
||||||
{% if pub_post != [] %}
|
{% if pub_post != [] %}
|
||||||
{% for item in pub_post %}
|
{% for item in pub_post %}
|
||||||
<div class="card-body post">
|
<div class="card-body" id="my_post1">
|
||||||
<details>
|
<details>
|
||||||
<summary>
|
<summary style="color:#ffffff">{% if item.name != None %}
|
||||||
{% if item.name != None %}
|
<h2 class="card-title" id="my_post_zag1" style="color:#c5f1ff">{{item.name}}</h2>
|
||||||
<h2 class="card-title post_zag" style="color:#c5f1ff">{{item.name}}</h2>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</summary>
|
</summary>
|
||||||
{% if item.text != None %}
|
{% if item.text != None %}
|
||||||
<strong class="card-text" style="color:#ffffff">{{item.text}}</strong>
|
<strong class="card-text" id="my_text1" style="color:#ffffff">{{item.text}}</strong>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</details>
|
</details>
|
||||||
{% if emotion_pub[loop.index0]['pos_emot'] != None %}
|
{% if emotion_pub[loop.index0]['pos_emot'] != None %}
|
||||||
@ -51,14 +53,12 @@
|
|||||||
<summary class="emot_block">
|
<summary class="emot_block">
|
||||||
<strong class="emot_block">Позитивные эмоции</strong>
|
<strong class="emot_block">Позитивные эмоции</strong>
|
||||||
</summary>
|
</summary>
|
||||||
<p></p>
|
|
||||||
{% for item2 in emotion_pub[loop.index0]['pos_emot'] %}
|
{% for item2 in emotion_pub[loop.index0]['pos_emot'] %}
|
||||||
<strong class="alert alert-success" role="alert"
|
<strong class="alert alert-success" role="alert"
|
||||||
style="border-radius: 22px;">{{item2}}</strong>
|
style="border-radius: 22px;">{{item2}}</strong>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
<p></p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if emotion_pub[loop.index0]['nig_emot'] != None %}
|
{% if emotion_pub[loop.index0]['nig_emot'] != None %}
|
||||||
<div class="nig_emot">
|
<div class="nig_emot">
|
||||||
@ -73,20 +73,29 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
<p></p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.photo != None %}
|
{% if item.photo != None %}
|
||||||
<p></p>
|
|
||||||
<div class="photo">
|
<div class="photo">
|
||||||
<img width="90%" src="{{ item.photo }}"
|
<img width="90%" src="{{ item.photo }}"
|
||||||
style="border-radius: 22px;">
|
style="border-radius: 22px;">
|
||||||
</div>
|
</div>
|
||||||
<p></p>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if current_user.is_authenticated %}
|
{% if emotion_pub[loop.index0]['link'] != None %}
|
||||||
|
<details>
|
||||||
|
<summary class="emot_block">
|
||||||
|
<strong class="emot_block">Ссылки</strong>
|
||||||
|
</summary>
|
||||||
|
{% for item2 in emotion_pub[loop.index0]['link'] %}
|
||||||
|
<div class="link">
|
||||||
|
<a class="alert alert-light" role="alert" href="{{ item2 }}" style="border-radius: 22px;">Ссылка
|
||||||
|
{{ loop.index }}</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</details>
|
||||||
|
{% endif %}
|
||||||
<div class="like">
|
<div class="like">
|
||||||
<a type="button"
|
<a type="button"
|
||||||
href="/new_like/{{current_user.id}}/{{item.id}}/profile">
|
href="/new_like/{{current_user.id}}/{{item.id}}/diary">
|
||||||
{% if emotion_pub[loop.index0]['is_like'] %}
|
{% if emotion_pub[loop.index0]['is_like'] %}
|
||||||
<img src="../static/img/like_add.png" width="117" height="100">
|
<img src="../static/img/like_add.png" width="117" height="100">
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -97,27 +106,9 @@
|
|||||||
<p style="color:#ffffff">{{emotion_pub[loop.index0]['like']}}</p>
|
<p style="color:#ffffff">{{emotion_pub[loop.index0]['like']}}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
<div class="my_author"><img src="../{{ current_user.photo }}" width="40" height="40"
|
||||||
{% if emotion_pub[loop.index0]['link'] != None %}
|
style="border-radius: 22px">
|
||||||
<details>
|
<strong style="color: #ffffff">{{ current_user.name }}</strong>
|
||||||
<summary class="emot_block">
|
|
||||||
<strong class="emot_block">Ссылки</strong>
|
|
||||||
</summary>
|
|
||||||
<p></p>
|
|
||||||
{% for item2 in emotion_pub[loop.index0]['link'] %}
|
|
||||||
<div class="link">
|
|
||||||
<a class="alert alert-light" role="alert" href="{{ item2 }}" style="border-radius: 22px;">Ссылка
|
|
||||||
{{ loop.index }}</a>
|
|
||||||
</div>
|
|
||||||
<p></p>
|
|
||||||
{% endfor %}
|
|
||||||
</details>
|
|
||||||
{% endif %}
|
|
||||||
<div class="author" style="style=position:absolute; width:148px; height:44px; left:255px; -webkit-border-radius:
|
|
||||||
22px;-moz-border-radius: 22px;border-radius: 22px; border:2px solid #FFFFFF; background-color:#1daff0; top:
|
|
||||||
98px;"><img src="../{{ emotion_pub[loop.index0]['author'].photo }}" width="40" height="40"
|
|
||||||
style="border-radius: 22px">
|
|
||||||
<strong style="color: #ffffff">{{ emotion_pub[loop.index0]['author'].name }}</strong>
|
|
||||||
</div>
|
</div>
|
||||||
<strong style="color:#ffffff">{{item.date}}</strong>
|
<strong style="color:#ffffff">{{item.date}}</strong>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user