mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development
This commit is contained in:
commit
a3c049c4ed
@ -5,7 +5,7 @@ from . import auth
|
||||
from .forms import (LoginForm, ResetPasswordForm, ResetPasswordRequestForm,
|
||||
RegistrationForm)
|
||||
from .. import db
|
||||
from ..email import send_email
|
||||
from ..email import create_message, send_async
|
||||
from ..models import User
|
||||
import os
|
||||
import shutil
|
||||
@ -17,8 +17,7 @@ def before_request():
|
||||
Checks if a user is unconfirmed when visiting specific sites. Redirects to
|
||||
unconfirmed view if user is unconfirmed.
|
||||
"""
|
||||
if (current_user.is_authenticated
|
||||
and not current_user.confirmed
|
||||
if (current_user.is_authenticated and not current_user.confirmed
|
||||
and request.blueprint != 'auth'
|
||||
and request.endpoint != 'static'):
|
||||
return redirect(url_for('auth.unconfirmed'))
|
||||
@ -69,8 +68,9 @@ def register():
|
||||
shutil.rmtree(user_dir)
|
||||
os.mkdir(user_dir)
|
||||
token = user.generate_confirmation_token()
|
||||
send_email(user.email, 'Confirm Your Account',
|
||||
'auth/email/confirm', token=token, user=user)
|
||||
msg = create_message(user.email, 'Confirm Your Account',
|
||||
'auth/email/confirm', token=token, user=user)
|
||||
send_async(msg)
|
||||
flash('A confirmation email has been sent to you by email.')
|
||||
return redirect(url_for('auth.login'))
|
||||
return render_template('auth/register.html.j2',
|
||||
@ -105,8 +105,9 @@ def unconfirmed():
|
||||
@login_required
|
||||
def resend_confirmation():
|
||||
token = current_user.generate_confirmation_token()
|
||||
send_email(current_user.email, 'Confirm Your Account',
|
||||
'auth/email/confirm', token=token, user=current_user)
|
||||
msg = create_message(current_user.email, 'Confirm Your Account',
|
||||
'auth/email/confirm', token=token, user=current_user)
|
||||
send_async(msg)
|
||||
flash('A new confirmation email has been sent to you by email.')
|
||||
return redirect(url_for('auth.unconfirmed'))
|
||||
|
||||
@ -116,23 +117,23 @@ def reset_password_request():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('main.dashboard'))
|
||||
reset_password_request_form = ResetPasswordRequestForm(
|
||||
prefix='reset-password-request-form'
|
||||
)
|
||||
prefix='reset-password-request-form')
|
||||
if reset_password_request_form.validate_on_submit():
|
||||
submitted_email = reset_password_request_form.email.data
|
||||
user = User.query.filter_by(email=submitted_email.lower()).first()
|
||||
if user:
|
||||
token = user.generate_reset_token()
|
||||
send_email(user.email, 'Reset Your Password',
|
||||
'auth/email/reset_password', token=token, user=user)
|
||||
msg = create_message(user.email, 'Reset Your Password',
|
||||
'auth/email/reset_password', token=token,
|
||||
user=user)
|
||||
send_async(msg)
|
||||
flash('An email with instructions to reset your password has been '
|
||||
'sent to you.')
|
||||
return redirect(url_for('auth.login'))
|
||||
return render_template(
|
||||
'auth/reset_password_request.html.j2',
|
||||
reset_password_request_form=reset_password_request_form,
|
||||
title='Password Reset'
|
||||
)
|
||||
title='Password Reset')
|
||||
|
||||
|
||||
@auth.route('/reset/<token>', methods=['GET', 'POST'])
|
||||
|
@ -5,16 +5,20 @@ def delete_corpus_(app, corpus_id):
|
||||
with app.app_context():
|
||||
corpus = Corpus.query.get(corpus_id)
|
||||
if corpus is None:
|
||||
raise Exception('Corpus {} not found!'.format(corpus_id))
|
||||
corpus.delete()
|
||||
# raise Exception('Corpus {} not found!'.format(corpus_id))
|
||||
pass
|
||||
else:
|
||||
corpus.delete()
|
||||
|
||||
|
||||
def delete_corpus_file_(app, corpus_file_id):
|
||||
with app.app_context():
|
||||
corpus_file = CorpusFile.query.get(corpus_file_id)
|
||||
if corpus_file is None:
|
||||
raise Exception('Corpus file {} not found!'.format(corpus_file_id))
|
||||
corpus_file.delete()
|
||||
# raise Exception('Corpus file {} not found!'.format(corpus_file_id))
|
||||
pass
|
||||
else:
|
||||
corpus_file.delete()
|
||||
|
||||
|
||||
def edit_corpus_file_(app, corpus_file_id):
|
||||
@ -22,4 +26,5 @@ def edit_corpus_file_(app, corpus_file_id):
|
||||
corpus_file = CorpusFile.query.get(corpus_file_id)
|
||||
if corpus_file is None:
|
||||
raise Exception('Corpus file {} not found!'.format(corpus_file_id))
|
||||
corpus_file.insert_metadata()
|
||||
else:
|
||||
corpus_file.insert_metadata()
|
||||
|
22
app/email.py
22
app/email.py
@ -4,18 +4,24 @@ from threading import Thread
|
||||
from . import mail
|
||||
|
||||
|
||||
def send_async_email(app, msg):
|
||||
def create_message(recipient, subject, template, **kwargs):
|
||||
app = current_app._get_current_object()
|
||||
sender = app.config['NOPAQUE_MAIL_SENDER']
|
||||
subject_prefix = app.config['NOPAQUE_MAIL_SUBJECT_PREFIX']
|
||||
msg = Message('{} {}'.format(subject_prefix, subject),
|
||||
recipients=[recipient], sender=sender)
|
||||
msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
|
||||
msg.html = render_template('{}.html.j2'.format(template), **kwargs)
|
||||
return msg
|
||||
|
||||
|
||||
def send(app, msg):
|
||||
with app.app_context():
|
||||
mail.send(msg)
|
||||
|
||||
|
||||
def send_email(to, subject, template, **kwargs):
|
||||
def send_async(msg):
|
||||
app = current_app._get_current_object()
|
||||
msg = Message(
|
||||
'{} {}'.format(app.config['NOPAQUE_MAIL_SUBJECT_PREFIX'], subject),
|
||||
recipients=[to], sender=app.config['NOPAQUE_MAIL_SENDER'])
|
||||
msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
|
||||
msg.html = render_template('{}.html.j2'.format(template), **kwargs)
|
||||
thread = Thread(target=send_async_email, args=(app, msg))
|
||||
thread = Thread(target=send, args=(app, msg))
|
||||
thread.start()
|
||||
return thread
|
||||
|
@ -6,6 +6,7 @@ from .. import logger
|
||||
from ..auth.forms import LoginForm
|
||||
from ..models import User
|
||||
|
||||
|
||||
@main.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
login_form = LoginForm(prefix='login-form')
|
||||
|
@ -47,8 +47,7 @@ def settings():
|
||||
edit_email_form=edit_email_form,
|
||||
edit_password_form=edit_password_form,
|
||||
edit_general_settings_form=edit_general_settings_form,
|
||||
title='Settings'
|
||||
)
|
||||
title='Settings')
|
||||
|
||||
|
||||
@profile.route('/delete', methods=['GET', 'POST'])
|
||||
|
Loading…
Reference in New Issue
Block a user