def account_recovery(): if request.method == 'POST': form = AccountRecoveryForm(request.form) else: form = AccountRecoveryForm() if form.validate_on_submit(): session = Session() status = False #There may be multiple accounts associated with this email. for user in session.query(User).filter( User.email == form.email.data).all(): if user.is_active(): status = send_account_recovery_mail(app, user) if status: flash( 'Account recovery instructions has been sent to %s' % user.email, 'success') else: flash('Unable to send confirmation to %s' % user.email, 'danger') return render_template('user/reset_password.html', form=form)
def setup(): session = Session() if session.query(User).filter(User.is_admin).count() > 0: return redirect(url_for('index')) if request.method == 'POST': form = CreateAdministratorForm(request.form) else: form = CreateAdministratorForm() if form.validate_on_submit(): session = Session() user = User(username=form.username.data, password=form.password.data) user.email = form.email.data user.is_admin = True user.needs_password_reset = False user.needs_activation = False session.add(user) session.commit() flash('Administrator user created. You may now log in.', 'success') return redirect(url_for('login')) else: flash('Please create an administrator user to get started.', 'info') return render_template('admin/setup.html', form=form)
def administrate_mailboxes(): session = Session() if request.method == 'POST': form = AssignMailboxForm(request.form) if form.validate_on_submit(): user = session.query(User).get(form.user.data) mailbox = session.query(Mailbox).get(form.mailbox.data) user.mailbox = mailbox session.commit() flash('Mailbox %d assigned to %s' % (mailbox.id, user.username), 'success') mailboxes = session.query(Mailbox).options(joinedload('user')).all() users = session.query(User).filter(User.is_admin == False).filter( User.mailbox == None).filter(User.needs_activation == False).all() return render_template('admin/mailboxes.html', mailboxes=mailboxes, users=users, form=AssignMailboxForm())
def user_profile(): if request.method == 'POST': form = UserEmailForm(request.form) else: form = UserEmailForm(obj=current_user) if form.validate_on_submit(): current_user.email = form.email.data session = object_session(current_user) if not session: session = Session() session.add(current_user) session.commit() flash('Email updated', 'success') return render_template('user/user_profile.html', form=form)
def create_user(): if request.method == 'POST': form = UserForm(request.form) else: form = UserForm() if form.validate_on_submit(): session = Session() user = User(username=form.username.data, password="") user.email = form.email.data user.needs_activation = True session.add(user) if send_user_confirmation_mail(app, user): flash( 'User created. Activation instructions has been sent to %s' % user.email, 'success') session.commit() else: flash('Unable to send confirmation to %s' % user.email, 'danger') return redirect(url_for('administrate_users')) return render_template('admin/create_user.html', form=form)
def view_mailbox(): if current_user.is_admin: abort(401) if current_user.mailbox == None: return render_template('view_mailbox.html') mailbox = current_user.mailbox if request.method == 'POST': form = MailboxLCDTextForm(request.form) else: form = MailboxLCDTextForm(obj=mailbox) if form.validate_on_submit(): session = object_session(mailbox) if not session: session = Session() session.add(mailbox) mailbox.display_text = '%s\n%s' % (form.first_line.data, form.second_line.data) print mailbox.display_text session.commit() flash('LCD updated', 'success') return render_template('view_mailbox.html', mailbox=mailbox, form=form)
def validate_email(self, field): session = Session() if session.query(User).filter(User.email == field.data).count() == 0: raise ValidationError('Could not find an account with that email.')
def validate_user(self, field): session = Session() if session.query(Mailbox).filter(User.id == field.data).count() == 0: raise ValidationError('Mailbox id out of range.')
def validate_username(self, field): session = Session() if session.query(User).filter(User.username == field.data).count() > 0: raise ValidationError('Username must be unique')
def administrate_users(): session = Session() users = session.query(User).filter(User.is_admin == False) return render_template('admin/users.html', users=users)
def load_user(user_id): session = Session() return session.query(User).get(user_id)
def get_list(self): session = Session() return session.query(MailboxModel).all()
def get_single(self, mailbox_id): session = Session() return get_or_404(session.query(MailboxModel), mailbox_id)
def post(self): session = Session() mailbox = MailboxModel() session.add(mailbox) session.commit() return mailbox