Esempio n. 1
0
def add_recipient(thread_id):
    try:
        g.user.username
        if str(thread_id) not in g.user.get_threads():
            abort(401)
    except AttributeError:
        abort(401)
    username = request.form['username']
    if request.form['confirm'] == '1':
        try:
            t = Thread(redis=g.r, user=g.user)
            t.load(thread_id)
            t.parse_recipients(username)
            t.save()
            flash('Added recipient.', 'success')
        except InvalidRecipients:
            flash(u'Invalid recipient.', 'error')
        return redirect(url_for('frontend.view_thread', thread_id=thread_id))
    else:
        return render_template('confirm.html',
            _message='Are you sure you wish to add recipient %s to\
 this thread?' % username,
            _ok=url_for('frontend.add_recipient', thread_id=thread_id),
            _cancel=url_for('frontend.view_thread', thread_id=thread_id),
            _hiddens=[('username', username)]
        )
Esempio n. 2
0
def add_recipient(thread_id):
    try:
        g.user.username
        if str(thread_id) not in g.user.get_threads():
            abort(401)
    except AttributeError:
        abort(401)
    username = request.form['username']
    if request.form['confirm'] == '1':
        try:
            t = Thread(redis=g.r, user=g.user)
            t.load(thread_id)
            t.parse_recipients(username)
            t.save()
            flash('Added recipient.', 'success')
        except InvalidRecipients:
            flash(u'Invalid recipient.', 'error')
        return redirect(url_for('frontend.view_thread', thread_id=thread_id))
    else:
        return render_template(
            'confirm.html',
            _message='Are you sure you wish to add recipient %s to\
 this thread?' % username,
            _ok=url_for('frontend.add_recipient', thread_id=thread_id),
            _cancel=url_for('frontend.view_thread', thread_id=thread_id),
            _hiddens=[('username', username)])
Esempio n. 3
0
def send_message(recipient=False):
    try:
        g.user.username
    except AttributeError:
        abort(401)

    t = Thread(redis=g.r, user=g.user)
    m = Message(redis=g.r, key=False, user=g.user)
    if (recipient):
        try:
            t.parse_recipients(recipient)
        except InvalidRecipients:
            pass

    if request.method == 'POST':
        try:
            t.subject = request.form['subject']
            m.update(request.form)
            t.parse_recipients(request.form['recipients'])
            t.encryption = request.form['encryption']
            t.save()
            t.add_message(m)
            m.send()
            flash(
                'Your message has been successfully wired, \
                    and should arrive shortly.', 'success')
            return redirect(url_for('frontend.view_thread', thread_id=t.key))
        except MessageValidationError:
            for error in m.validation_errors:
                flash(error, 'error')
        except InvalidRecipients:
            for recipient in t.invalid_recipients:
                flash('%s is not a valid recipient' % recipient, 'error')
    return render_template('forms/message.html',
                           new=True,
                           message=m,
                           thread=t,
                           recipients=t.get_form_recipients())
Esempio n. 4
0
def send_message(recipient=False):
    try:
        g.user.username
    except AttributeError:
        abort(401)

    t = Thread(redis=g.r, user=g.user)
    m = Message(redis=g.r, key=False, user=g.user)
    if(recipient):
        try:
            t.parse_recipients(recipient)
        except InvalidRecipients:
            pass

    if request.method == 'POST':
        try:
            t.subject = request.form['subject']
            m.update(request.form)
            t.parse_recipients(request.form['recipients'])
            t.encryption = request.form['encryption']
            t.save()
            t.add_message(m)
            m.send()
            flash('Your message has been successfully wired, \
                    and should arrive shortly.', 'success')
            return redirect(url_for('frontend.view_thread', thread_id=t.key))
        except MessageValidationError:
            for error in m.validation_errors:
                flash(error, 'error')
        except InvalidRecipients:
            for recipient in t.invalid_recipients:
                flash('%s is not a valid recipient' % recipient, 'error')
    return render_template('forms/message.html',
        new=True,
        message=m,
        thread=t,
        recipients=t.get_form_recipients())