2022-12-23 17:08:33 +00:00
|
|
|
from flask import (
|
|
|
|
abort,
|
|
|
|
redirect,
|
|
|
|
render_template,
|
|
|
|
send_from_directory,
|
|
|
|
url_for
|
|
|
|
)
|
2023-04-11 09:46:33 +00:00
|
|
|
from flask_login import current_user
|
|
|
|
from app.models import User
|
2022-09-02 11:07:30 +00:00
|
|
|
from . import bp
|
2023-03-14 10:44:15 +00:00
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
|
2023-10-24 14:11:08 +00:00
|
|
|
@bp.route('')
|
|
|
|
def users():
|
|
|
|
return redirect(url_for('main.social_area', _anchor='users'))
|
2023-03-14 10:44:15 +00:00
|
|
|
|
2022-09-02 11:07:30 +00:00
|
|
|
|
2023-10-24 14:11:08 +00:00
|
|
|
@bp.route('/<hashid:user_id>')
|
|
|
|
def user(user_id):
|
|
|
|
user = User.query.get_or_404(user_id)
|
2024-04-11 12:33:47 +00:00
|
|
|
if not (user.is_public or user == current_user or current_user.is_administrator):
|
2023-10-24 14:11:08 +00:00
|
|
|
abort(403)
|
|
|
|
return render_template(
|
|
|
|
'users/user.html.j2',
|
|
|
|
title=user.username,
|
|
|
|
user=user
|
|
|
|
)
|
2022-09-02 11:07:30 +00:00
|
|
|
|
|
|
|
|
2023-10-24 14:11:08 +00:00
|
|
|
@bp.route('/<hashid:user_id>/avatar')
|
|
|
|
def user_avatar(user_id):
|
|
|
|
user = User.query.get_or_404(user_id)
|
2024-04-11 12:33:47 +00:00
|
|
|
if not (user.is_public or user == current_user or current_user.is_administrator):
|
2023-10-24 14:11:08 +00:00
|
|
|
abort(403)
|
|
|
|
if user.avatar is None:
|
|
|
|
return redirect(url_for('static', filename='images/user_avatar.png'))
|
|
|
|
return send_from_directory(
|
2024-03-07 14:49:04 +00:00
|
|
|
user.avatar.path.parent,
|
|
|
|
user.avatar.path.name,
|
2023-10-24 14:11:08 +00:00
|
|
|
as_attachment=True,
|
2024-04-30 06:41:29 +00:00
|
|
|
download_name=user.avatar.filename,
|
2023-10-24 14:11:08 +00:00
|
|
|
mimetype=user.avatar.mimetype
|
|
|
|
)
|