mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Move auth.settings to a new package (profile) as profile.index
This commit is contained in:
		@@ -61,41 +61,3 @@ class PasswordResetForm(FlaskForm):
 | 
			
		||||
class PasswordResetRequestForm(FlaskForm):
 | 
			
		||||
    email = StringField('Email', validators=[DataRequired(), Email()])
 | 
			
		||||
    submit = SubmitField('Reset Password')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ChangePasswordForm(FlaskForm):
 | 
			
		||||
    """
 | 
			
		||||
    Form to change information of currently logged in User. User can change
 | 
			
		||||
    informations about him on his own.
 | 
			
		||||
    """
 | 
			
		||||
    old_password = PasswordField('Old password', validators=[DataRequired()])
 | 
			
		||||
    new_password = PasswordField(
 | 
			
		||||
        'New password',
 | 
			
		||||
        validators=[
 | 
			
		||||
            DataRequired(),
 | 
			
		||||
            EqualTo('new_password2', message='Passwords must match.')
 | 
			
		||||
        ]
 | 
			
		||||
    )
 | 
			
		||||
    new_password2 = PasswordField(
 | 
			
		||||
        'Confirm new password',
 | 
			
		||||
        validators=[
 | 
			
		||||
            DataRequired(),
 | 
			
		||||
            EqualTo('new_password', message='Passwords must match.')
 | 
			
		||||
        ]
 | 
			
		||||
    )
 | 
			
		||||
    submit = SubmitField('Update Password')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class EditProfileForm(FlaskForm):
 | 
			
		||||
    email = StringField('Change Email',
 | 
			
		||||
                        validators=[Length(0, 254), DataRequired()])
 | 
			
		||||
    submit = SubmitField('Change Email')
 | 
			
		||||
 | 
			
		||||
    def __init__(self, user, *args, **kwargs):
 | 
			
		||||
        super(EditProfileForm, self).__init__(*args, **kwargs)
 | 
			
		||||
        self.user = user
 | 
			
		||||
 | 
			
		||||
    def validate_email(self, field):
 | 
			
		||||
        if field.data != self.user.email and \
 | 
			
		||||
                User.query.filter_by(email=field.data).first():
 | 
			
		||||
            raise ValidationError('Email already registered!')
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,11 @@
 | 
			
		||||
from flask import (flash, redirect, render_template, request, url_for,
 | 
			
		||||
                   current_app)
 | 
			
		||||
from flask import flash, redirect, render_template, request, url_for
 | 
			
		||||
from flask_login import current_user, login_required, login_user, logout_user
 | 
			
		||||
from . import auth
 | 
			
		||||
from .. import db
 | 
			
		||||
from .forms import (ChangePasswordForm, LoginForm, PasswordResetForm,
 | 
			
		||||
                    PasswordResetRequestForm, RegistrationForm, EditProfileForm)
 | 
			
		||||
from .forms import (LoginForm, PasswordResetForm, PasswordResetRequestForm,
 | 
			
		||||
                    RegistrationForm)
 | 
			
		||||
from ..email import send_email
 | 
			
		||||
from ..models import User
 | 
			
		||||
import threading
 | 
			
		||||
from app.utils import background_delete_user
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@auth.route('/login', methods=['GET', 'POST'])
 | 
			
		||||
@@ -133,46 +130,3 @@ def password_reset(token):
 | 
			
		||||
            return redirect(url_for('main.index'))
 | 
			
		||||
    return render_template('auth/reset_password.html.j2', form=form,
 | 
			
		||||
                           title='Password Reset')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@auth.route('/settings', methods=['GET', 'POST'])
 | 
			
		||||
@login_required
 | 
			
		||||
def settings():
 | 
			
		||||
    """
 | 
			
		||||
    View where loged in User can change own User information like Password etc.
 | 
			
		||||
    """
 | 
			
		||||
    change_password_form = ChangePasswordForm()
 | 
			
		||||
    if change_password_form.validate_on_submit():
 | 
			
		||||
        if current_user.verify_password(change_password_form.old_password.data):
 | 
			
		||||
            current_user.password = change_password_form.new_password.data
 | 
			
		||||
            db.session.add(current_user)
 | 
			
		||||
            db.session.commit()
 | 
			
		||||
            flash('Your password has been updated.')
 | 
			
		||||
            return redirect(url_for('auth.settings'))
 | 
			
		||||
        else:
 | 
			
		||||
            flash('Invalid password.')
 | 
			
		||||
    change_profile_form = EditProfileForm(user=current_user)
 | 
			
		||||
    if change_profile_form.validate_on_submit():
 | 
			
		||||
        current_user.email = change_profile_form.email.data
 | 
			
		||||
        db.session.add(current_user._get_current_object())
 | 
			
		||||
        db.session.commit()
 | 
			
		||||
        flash('Your email has been updated.')
 | 
			
		||||
    change_profile_form.email.data = current_user.email
 | 
			
		||||
    return render_template(
 | 
			
		||||
        'auth/settings.html.j2',
 | 
			
		||||
        change_password_form=change_password_form,
 | 
			
		||||
        change_profile_form=change_profile_form,
 | 
			
		||||
        title='Settings'
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@auth.route('/settings/delete_self', methods=['GET', 'POST'])
 | 
			
		||||
@login_required
 | 
			
		||||
def delete_self():
 | 
			
		||||
    delete_thread = threading.Thread(target=background_delete_user,
 | 
			
		||||
                                     args=(current_app._get_current_object(),
 | 
			
		||||
                                           current_user.id))
 | 
			
		||||
    delete_thread.start()
 | 
			
		||||
    logout_user()
 | 
			
		||||
    flash('Your account has been deleted!')
 | 
			
		||||
    return redirect(url_for('main.index'))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user