def r_register(): """ Route for new users to register for accounts :return: template, form """ if current_user.is_authenticated: flash(_('Sie sind schon eingeloggt.')) return redirect(url_for('InstanceNemo.r_index')) form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data, default_locale=form.default_locale.data) user.set_password(form.password.data) db.session.add(user) db.session.commit() current_user.default_locale = form.default_locale.data refresh() flash(_('Sie sind nun registriert.')) return redirect(url_for('auth.r_login')) return current_app.config['nemo_app'].render( template='auth::register.html', title=_('Anmelden'), form=form, url=dict())
def r_reset_password(token): """ Route for the actual resetting of the password :param token: the token that was previously sent to the user through the r_reset_password_request route :return: template, form """ if current_user.is_authenticated: flash( _('Sie sind schon eingeloggt. Sie können Ihr Password hier ändern.' )) return redirect(url_for('auth.r_user', username=current_user.username)) user = User.verify_reset_password_token(token) if not user: return redirect(url_for('InstanceNemo.r_index')) form = ResetPasswordForm() if form.validate_on_submit(): user.set_password(form.password.data) db.session.commit() flash(_('Ihr Passwort wurde erfolgreich zurückgesetzt.')) return redirect(url_for('auth.r_login')) return current_app.config['nemo_app'].render( template='auth::reset_password.html', title=_('Passwort zurücksetzen'), form=form, url=dict())
def setUp(self): db.create_all() u = User(username="******", email="*****@*****.**", project_team=True) u.set_password('some_password') db.session.add(u) u = User(username="******", email="*****@*****.**", project_team=False) u.set_password('some_other_password') db.session.add(u) db.session.commit()
def send_password_reset_email(user: User): token = user.get_reset_password_token() send_email(_('[Formulae - Litterae - Chartae] Passwort zurücksetzen'), sender=current_app.config['ADMINS'][0], recipients=[user.email], text_body=render_template('email/reset_password.txt', user=user, token=token), html_body=render_template('email/reset_password.html', user=user, token=token))
def send_email_reset_email(user: User, new_email: str): token = user.get_reset_email_token(new_email) send_email(_('[Formulae - Litterae - Chartae] Emailadresse ändern'), sender=current_app.config['ADMINS'][0], recipients=[new_email], text_body=render_template('email/reset_email.txt', user=user, token=token), html_body=render_template('email/reset_email.html', user=user, token=token))
def r_reset_email(token): """ Route to confirm that the email should be reset I don't think I need an email reset route since this will be done on the User's user page. :param token: the token that was previously sent to the user through the r_reset_password_request route :return: template, form """ try: user, old_email, new_email = User.verify_reset_email_token(token) except TypeError: flash(_('Der Token ist nicht gültig. Versuchen Sie es erneut.')) return redirect(url_for('auth.r_user')) if not user or user.id != current_user.id or current_user.email != old_email: flash( _('Ihre Emailaddresse wurde nicht geändert. Versuchen Sie es erneut.' )) return redirect(url_for('auth.r_user')) else: user.email = new_email db.session.commit() flash( _('Ihr Email wurde erfolgreich geändert. Sie lautet jetzt') + ' {}.'.format(new_email)) return redirect(url_for('auth.r_user'))