Example #1
0
def create():
    if not request.get_json():
        return jsonify({'error': 'Data should be in json format'}), 400

    if is_spam(request.get_json()):
        abort(400)

    content = request.get_json().get('content', '')
    if not content:
        return jsonify({'error': 'There was no content'}), 400
    feedback = Feedback(content=content)
    db.session.add(feedback)
    db.session.commit()

    message = Message(
        sender='*****@*****.**',
        recipients=FEEDBACK_RECIPIENTS,
        charset='utf8',
        subject='Kerrokantasi palaute',
        body=feedback.content
    )
    mail.send(message)

    return jsonify({
        'feedback': {
            'id': feedback.id,
            'content': feedback.content
        }
    }), 201
Example #2
0
def send_registration_mail(user):
    email_hash = account_activation_serializer.dumps(user.email)

    confirmation_url = (
        'https://kerrokantasi.hel.fi' +
        url_for('auth.activate_account', activation_hash=email_hash)
    )
    with current_app.test_request_context():
        context = {
            'user': user,
            'confirmation_url': confirmation_url,
        }
        message = Message(
            recipients=[user.email],
            charset='utf8',
            subject=render_template(
                'email/registration_subject.txt'
            ),
            body=render_template(
                'email/registration.txt',
                **context
            ).encode('utf8')
        )
        mail.send(message)