Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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 post(self):
     session = Session()
     mailbox = MailboxModel()
     session.add(mailbox)
     session.commit()
     return mailbox