Пример #1
0
 def post_feedback(self):
     form = FeedbackForm(csrf_enabled=False)
     if not form.validate():
         abort(400, form_errors=form.errors)
     FeedbackRecord(
         user=g.authorized.userid,
         message=form.message.data,
         score=form.score.data,
     ).save()
     message = "Score: %(score)s\n\n%(message)s" % form.data
     send_email(app.config['FEEDBACK_RECIPIENT'], message, format='text', subject='Feedback')
Пример #2
0
def _send_email_or_log(user, template, **ctx):
    try:
        body = template.render(
            email_sender=app.config['DEFAULT_EMAIL_SOURCE'],
            assets=app.config.get('ASSETS_URL', ''),
            user=user,
            **ctx
        )
        email.send_email(user.email, body)
        app.logger.info("Sent %s email to user %s <%s>",
                        template.name[:-5], user.id, user.email)
    except Exception as e:
        app.logger.error("Problem sending email to user %s: %s", user.id, e)
Пример #3
0
def share_content(userid, object_type, object_id, recipient_email):
    link = ShareLink.create(userid, object_type, object_id)
    object = SHARE_OBJECT_TYPE_MAP[object_type].query.get(object_id)
    user = User.query.get(userid)

    # Send email
    template = email.env.get_template('share.html')
    if app.config.get('DOLLY') and object_type == 'channel':
        top_videos = VideoInstance.query.filter_by(channel=object.id).\
            join(Video, (Video.id == VideoInstance.video) & (Video.visible == True)).\
            order_by(VideoInstance.position, VideoInstance.date_added.desc()).limit(3)
    else:
        top_videos = []
    body = template.render(
        recipient=recipient_email,
        sender=user,
        link=link,
        object_type=object_type,
        object_type_name=OBJECT_NAME_MAP[object_type],
        object=object,
        top_videos=top_videos,
    )
    email.send_email(recipient_email, body)

    recipient_user = User.query.filter(func.lower(User.email) == recipient_email.lower()).first()
    if recipient_user:
        # Create user notification
        message_body = dict(user=commands._notification_user_info(user))
        if object_type == 'channel':
            message_body['channel'] = commands._notification_channel_info(object, own=False)
            message_type = 'channel_shared'
        else:
            message_body['video'] = commands._notification_video_info(object, object.video_channel)
            message_type = 'video_shared'
        UserNotification(
            user=recipient_user.id,
            date_created=link.date_created,
            message_type=message_type,
            message=json.dumps(message_body, separators=(',', ':')),
        ).save()

        # Create an association the other way
        try:
            create_reverse_email_friend_association(user, recipient_user)
        except Exception as e:
            app.logger.error('Failed to create reverse email association: %s', e)
            db.session.rollback()
        else:
            db.session.commit()
Пример #4
0
def send_password_reset(userid):
    user = User.query.get(userid)
    if not user.email:
        app.logger.warning("Can't reset password for %s: no email address", user.id)
        return

    token = create_access_token(user.id, '', 86400)
    url = url_for('reset_password') + '?token=' + token
    template = email_env.get_template('reset.html')
    body = template.render(
        reset_link=url,
        user=user,
        email_sender=app.config['DEFAULT_EMAIL_SOURCE'],
    )
    send_email(user.email, body)