mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-27 08:20:34 +00:00
Some changes for profile
This commit is contained in:
@ -29,41 +29,50 @@ def before_request():
|
||||
@bp.route('/<hashid:user_id>')
|
||||
def profile(user_id):
|
||||
user = User.query.get_or_404(user_id)
|
||||
user_data = user.to_json_serializeable()
|
||||
if not user.is_public and user != current_user:
|
||||
abort(403)
|
||||
return render_template('profile/profile_page.html.j2',
|
||||
user=user,
|
||||
user_data=user_data)
|
||||
|
||||
@bp.route('/<hashid:user_id>/avatars/<hashid:avatar_id>')
|
||||
def avatar_download(user_id, avatar_id):
|
||||
avatar_file = Avatar.query.filter_by(user_id = user_id, id = avatar_id).first_or_404()
|
||||
if not (avatar_file and avatar_file.filename):
|
||||
abort(404)
|
||||
return send_from_directory(
|
||||
os.path.dirname(avatar_file.path),
|
||||
os.path.basename(avatar_file.path),
|
||||
as_attachment=True,
|
||||
attachment_filename=avatar_file.filename,
|
||||
mimetype=avatar_file.mimetype
|
||||
return render_template(
|
||||
'profile/profile.html.j2',
|
||||
user=user.to_json_serializeable(),
|
||||
)
|
||||
|
||||
@bp.route('/<hashid:user_id>/avatars/<hashid:avatar_id>', methods=['DELETE'])
|
||||
def delete_avatar(avatar_id, user_id):
|
||||
|
||||
@bp.route('/<hashid:user_id>/avatar')
|
||||
def profile_avatar(user_id):
|
||||
user = User.query.get_or_404(user_id)
|
||||
if user.avatar is None:
|
||||
abort(404)
|
||||
if not user.is_public and not (user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
return send_from_directory(
|
||||
os.path.dirname(user.avatar.path),
|
||||
os.path.basename(user.avatar.path),
|
||||
as_attachment=True,
|
||||
attachment_filename=user.avatar.filename,
|
||||
mimetype=user.avatar.mimetype
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/<hashid:user_id>/avatar', methods=['DELETE'])
|
||||
def delete_profile_avatar(user_id):
|
||||
def _delete_avatar(app, avatar_id):
|
||||
with app.app_context():
|
||||
avatar_file = Avatar.query.get(avatar_id)
|
||||
avatar_file.delete()
|
||||
avatar = Avatar.query.get(avatar_id)
|
||||
avatar.delete()
|
||||
db.session.commit()
|
||||
|
||||
user = User.query.get_or_404(user_id)
|
||||
if user.avatar is None:
|
||||
abort(404)
|
||||
thread = Thread(
|
||||
target=_delete_avatar,
|
||||
args=(current_app._get_current_object(), avatar_id)
|
||||
args=(current_app._get_current_object(), user.avatar.id)
|
||||
)
|
||||
thread.start()
|
||||
return {}, 202
|
||||
|
||||
@bp.route('/<hashid:user_id>/edit-profile', methods=['GET', 'POST'])
|
||||
|
||||
@bp.route('/<hashid:user_id>/edit', methods=['GET', 'POST'])
|
||||
def edit_profile(user_id):
|
||||
user = User.query.get_or_404(user_id)
|
||||
edit_profile_settings_form = EditProfileSettingsForm(
|
||||
@ -79,16 +88,13 @@ def edit_profile(user_id):
|
||||
data=current_user.to_json_serializeable(),
|
||||
prefix='edit-public-profile-information-form'
|
||||
)
|
||||
|
||||
if edit_profile_settings_form.validate_on_submit():
|
||||
current_user.email = edit_profile_settings_form.email.data
|
||||
current_user.username = edit_profile_settings_form.username.data
|
||||
db.session.commit()
|
||||
message = Markup(f'Profile settings updated')
|
||||
flash(message, 'success')
|
||||
flash('Profile settings updated')
|
||||
return redirect(url_for('.profile', user_id=user.id))
|
||||
if (edit_privacy_settings_form.submit.data
|
||||
and edit_privacy_settings_form.validate()):
|
||||
if edit_privacy_settings_form.submit.data and edit_privacy_settings_form.validate():
|
||||
current_user.is_public = edit_privacy_settings_form.is_public.data
|
||||
if edit_privacy_settings_form.show_email.data:
|
||||
current_user.add_profile_privacy_setting(ProfilePrivacySettings.SHOW_EMAIL)
|
||||
@ -117,12 +123,13 @@ def edit_profile(user_id):
|
||||
current_user.website = edit_public_profile_information_form.website.data
|
||||
current_user.full_name = edit_public_profile_information_form.full_name.data
|
||||
db.session.commit()
|
||||
message = Markup(f'Profile settings updated')
|
||||
flash(message, 'success')
|
||||
flash('Profile settings updated')
|
||||
return redirect(url_for('.profile', user_id=user.id))
|
||||
return render_template('profile/edit_profile.html.j2',
|
||||
return render_template(
|
||||
'profile/edit_profile.html.j2',
|
||||
edit_profile_settings_form=edit_profile_settings_form,
|
||||
edit_privacy_settings_form=edit_privacy_settings_form,
|
||||
edit_public_profile_information_form=edit_public_profile_information_form,
|
||||
user=user,
|
||||
title='Edit Profile')
|
||||
title='Edit Profile'
|
||||
)
|
||||
|
Reference in New Issue
Block a user