Esempio n. 1
0
def send_verification_email(user, request):
    """
    Send the verification email to users to activate their accounts.

    Args:
    - user: a user object
    - request: the request
    """
    rendered_email = render_template(
        request, 'mediagoblin/auth/verification_email.txt',
        {'username': user.username,
         'verification_url': EMAIL_VERIFICATION_TEMPLATE.format(
                host=request.host,
                uri=request.urlgen('mediagoblin.auth.verify_email'),
                userid=unicode(user._id),
                verification_key=user.verification_key)})

    # TODO: There is no error handling in place
    send_email(
        mg_globals.app_config['email_sender_address'],
        [user.email],
        # TODO
        # Due to the distributed nature of GNU MediaGoblin, we should
        # find a way to send some additional information about the
        # specific GNU MediaGoblin instance in the subject line. For
        # example "GNU MediaGoblin @ Wandborg - [...]".
        'GNU MediaGoblin - Verify your email!',
        rendered_email)
Esempio n. 2
0
def _update_email(request, form, user):
    new_email = form.new_email.data
    users_with_email = User.query.filter_by(email=new_email).count()

    if users_with_email:
        form.new_email.errors.append(
            _('Sorry, a user with that email address'
              ' already exists.'))

    elif not users_with_email:
        verification_key = get_timed_signer_url(
            'mail_verification_token').dumps({
                'user': user.id,
                'email': new_email
            })

        rendered_email = render_template(
            request, 'mediagoblin/edit/verification.txt', {
                'username':
                user.username,
                'verification_url':
                EMAIL_VERIFICATION_TEMPLATE.format(
                    uri=request.urlgen('mediagoblin.edit.verify_email',
                                       qualified=True),
                    verification_key=verification_key)
            })

        email_debug_message(request)
        auth_tools.send_verification_email(user, request, new_email,
                                           rendered_email)
Esempio n. 3
0
def send_verification_email(user, request, email=None,
                            rendered_email=None):
    """
    Send the verification email to users to activate their accounts.

    Args:
    - user: a user object
    - request: the request
    """
    if not email:
        email = user.email

    if not rendered_email:
        verification_key = get_timed_signer_url('mail_verification_token') \
                .dumps(user.id)
        rendered_email = render_template(
            request, 'mediagoblin/auth/verification_email.txt',
            {'username': user.username,
            'verification_url': EMAIL_VERIFICATION_TEMPLATE.format(
                    uri=request.urlgen('mediagoblin.auth.verify_email',
                                       qualified=True),
                    verification_key=verification_key)})

    # TODO: There is no error handling in place
    send_email(
        mg_globals.app_config['email_sender_address'],
        [email],
        # TODO
        # Due to the distributed nature of GNU MediaGoblin, we should
        # find a way to send some additional information about the
        # specific GNU MediaGoblin instance in the subject line. For
        # example "GNU MediaGoblin @ Wandborg - [...]".
        'GNU MediaGoblin - Verify your email!',
        rendered_email)
Esempio n. 4
0
def send_fp_verification_email(user, request):
    """
    Send the verification email to users to change their password.

    Args:
    - user: a user object
    - request: the request
    """
    fp_verification_key = get_timed_signer_url('mail_verification_token') \
            .dumps(user.id)

    rendered_email = render_template(
        request, 'mediagoblin/plugins/basic_auth/fp_verification_email.txt',
        {'username': user.username,
         'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
             uri=request.urlgen('mediagoblin.plugins.basic_auth.verify_forgot_password',
                                qualified=True),
             fp_verification_key=fp_verification_key)})

    # TODO: There is no error handling in place
    send_email(
        mg_globals.app_config['email_sender_address'],
        [user.email],
        'GNU MediaGoblin - Change forgotten password!',
        rendered_email)
Esempio n. 5
0
def send_verification_email(user, request, email=None,
                            rendered_email=None):
    """
    Send the verification email to users to activate their accounts.

    Args:
    - user: a user object
    - request: the request
    """
    if not email:
        email = user.email

    if not rendered_email:
        verification_key = get_timed_signer_url('mail_verification_token') \
                .dumps(user.id)
        rendered_email = render_template(
            request, 'mediagoblin/auth/verification_email.txt',
            {'username': user.username,
            'verification_url': EMAIL_VERIFICATION_TEMPLATE.format(
                    uri=request.urlgen('mediagoblin.auth.verify_email',
                                       qualified=True),
                    verification_key=verification_key)})

    # TODO: There is no error handling in place
    send_email(
        mg_globals.app_config['email_sender_address'],
        [email],
        # TODO
        # Due to the distributed nature of GNU MediaGoblin, we should
        # find a way to send some additional information about the
        # specific GNU MediaGoblin instance in the subject line. For
        # example "GNU MediaGoblin @ Wandborg - [...]".
        'GNU MediaGoblin - Verify your email!',
        rendered_email)
Esempio n. 6
0
def send_comment_email(user, comment, media, request):
    """
    Sends comment email to user when a comment is made on their media.

    Args:
    - user: the user object to whom the email is sent
    - comment: the comment object referencing user's media
    - media: the media object the comment is about
    - request: the request
    """

    comment_url = request.urlgen(
                    'mediagoblin.user_pages.media_home.view_comment',
                    comment=comment.id,
                    user=media.get_uploader.username,
                    media=media.slug_or_id,
                    qualified=True) + '#comment'

    comment_author = comment.get_author.username

    rendered_email = render_template(
        request, 'mediagoblin/user_pages/comment_email.txt',
        {'username': user.username,
         'comment_author': comment_author,
         'comment_content': comment.content,
         'comment_url': comment_url})

    send_email(
        mg_globals.app_config['email_sender_address'],
        [user.email],
        '{instance_title} - {comment_author} '.format(
            comment_author=comment_author,
            instance_title=mg_globals.app_config['html_title']) \
                    + _('commented on your post'),
        rendered_email)
Esempio n. 7
0
def send_fp_verification_email(user, request):
    """
    Send the verification email to users to change their password.

    Args:
    - user: a user object
    - request: the request
    """
    fp_verification_key = get_timed_signer_url('mail_verification_token') \
            .dumps(user.id)

    rendered_email = render_template(
        request, 'mediagoblin/plugins/basic_auth/fp_verification_email.txt', {
            'username':
            user.username,
            'verification_url':
            EMAIL_FP_VERIFICATION_TEMPLATE.format(
                uri=request.urlgen(
                    'mediagoblin.plugins.basic_auth.verify_forgot_password',
                    qualified=True),
                fp_verification_key=fp_verification_key)
        })

    # TODO: There is no error handling in place
    send_email(mg_globals.app_config['email_sender_address'], [user.email],
               'GNU MediaGoblin - Change forgotten password!', rendered_email)
Esempio n. 8
0
def render_error(request, status=500, title=_('Oops!'),
                 err_msg=_('An error occured')):
    """Render any error page with a given error code, title and text body

    Title and description are passed through as-is to allow html. Make
    sure no user input is contained therein for security reasons. The
    description will be wrapped in <p></p> tags.
    """
    return Response(render_template(request, 'mediagoblin/error.html',
        {'err_code': status, 'title': title, 'err_msg': err_msg}),
        status=status)
Esempio n. 9
0
def render_error(request, status=500, title=_('Oops!'),
                 err_msg=_('An error occured')):
    """Render any error page with a given error code, title and text body

    Title and description are passed through as-is to allow html. Make
    sure no user input is contained therein for security reasons. The
    description will be wrapped in <p></p> tags.
    """
    return Response(render_template(request, 'mediagoblin/error.html',
        {'err_code': status, 'title': title, 'err_msg': err_msg}),
        status=status)
Esempio n. 10
0
def change_email(request):
    """ View to change the user's email """
    form = forms.ChangeEmailForm(request.method == 'POST' and request.form
                                 or None)
    user = request.user

    # If no password authentication, no need to enter a password
    if 'pass_auth' not in request.template_env.globals or not user.pw_hash:
        form.__delitem__('password')

    if request.method == 'POST' and form.validate():
        new_email = form.new_email.data
        users_with_email = User.query.filter(
            LocalUser.email == new_email).count()

        if users_with_email:
            form.new_email.errors.append(
                _('Sorry, a user with that email address'
                  ' already exists.'))

        if form.password and user.pw_hash and not check_password(
                form.password.data, user.pw_hash):
            form.password.errors.append(_('Wrong password'))

        if not form.errors:
            verification_key = get_timed_signer_url(
                'mail_verification_token').dumps({
                    'user': user.id,
                    'email': new_email
                })

            rendered_email = render_template(
                request, 'mediagoblin/edit/verification.txt', {
                    'username':
                    user.username,
                    'verification_url':
                    EMAIL_VERIFICATION_TEMPLATE.format(
                        uri=request.urlgen('mediagoblin.edit.verify_email',
                                           qualified=True),
                        verification_key=verification_key)
                })

            email_debug_message(request)
            auth_tools.send_verification_email(user, request, new_email,
                                               rendered_email)

            return redirect(request, 'mediagoblin.edit.account')

    return render_to_response(request, 'mediagoblin/edit/change_email.html', {
        'form': form,
        'user': user
    })
Esempio n. 11
0
def change_email(request):
    """ View to change the user's email """
    form = forms.ChangeEmailForm(request.form)
    user = request.user

    # If no password authentication, no need to enter a password
    if 'pass_auth' not in request.template_env.globals or not user.pw_hash:
        form.__delitem__('password')

    if request.method == 'POST' and form.validate():
        new_email = form.new_email.data
        users_with_email = User.query.filter(
            LocalUser.email==new_email
        ).count()

        if users_with_email:
            form.new_email.errors.append(
                _('Sorry, a user with that email address'
                    ' already exists.'))

        if form.password and user.pw_hash and not check_password(
                form.password.data, user.pw_hash):
            form.password.errors.append(
                _('Wrong password'))

        if not form.errors:
            verification_key = get_timed_signer_url(
                'mail_verification_token').dumps({
                    'user': user.id,
                    'email': new_email})

            rendered_email = render_template(
                request, 'mediagoblin/edit/verification.txt',
                {'username': user.username,
                    'verification_url': EMAIL_VERIFICATION_TEMPLATE.format(
                    uri=request.urlgen('mediagoblin.edit.verify_email',
                                    qualified=True),
                    verification_key=verification_key)})

            email_debug_message(request)
            auth_tools.send_verification_email(user, request, new_email,
                                            rendered_email)

            return redirect(request, 'mediagoblin.edit.account')

    return render_to_response(
        request,
        'mediagoblin/edit/change_email.html',
        {'form': form,
         'user': user})
Esempio n. 12
0
def send_comment_email(user, comment, media, request):
    """
    Sends comment email to user when a comment is made on their media.

    Args:
    - user: the user object to whom the email is sent
    - comment: the comment object referencing user's media
    - media: the media object the comment is about
    - request: the request
    """

    comment_url = (
        request.urlgen(
            "mediagoblin.user_pages.media_home.view_comment",
            comment=comment.id,
            user=media.get_uploader.username,
            media=media.slug_or_id,
            qualified=True,
        )
        + "#comment"
    )

    comment_author = comment.get_author.username

    rendered_email = render_template(
        request,
        "mediagoblin/user_pages/comment_email.txt",
        {
            "username": user.username,
            "comment_author": comment_author,
            "comment_content": comment.content,
            "comment_url": comment_url,
        },
    )

    send_email(
        mg_globals.app_config["email_sender_address"],
        [user.email],
        "{instance_title} - {comment_author} ".format(
            comment_author=comment_author, instance_title=mg_globals.app_config["html_title"]
        )
        + _("commented on your post"),
        rendered_email,
    )
Esempio n. 13
0
def generate_comment_message(user, comment, commentee, request):
    """
    Sends comment email to user when a comment is made on their media.

    Args:
    - user: the user object to whom the email is sent
    - comment: the comment wrapper object
    - commentee: the object the comment is on
    - request: the request
    """

    # Get the comment object associated to the wrapper
    comment_object = comment.comment()

    # Get the URL to the comment
    comment_url = request.urlgen(
        "mediagoblin.user_pages.media_home.view_comment",
        comment=comment.id,
        user=commentee.get_actor.username,
        media=commentee.slug_or_id, 
        qualified=True) + "#comment"

    comment_author = comment.comment().get_actor.username

    rendered_email = render_template(
        request, 'mediagoblin/user_pages/comment_email.txt',
        {'username': user.username,
         'comment_author': comment_author,
         'comment_content': comment_object.content,
         'comment_url': comment_url
        }
    )

    return {
        'from': mg_globals.app_config['email_sender_address'],
        'to': user.email,
        'subject': '{instance_title} - {comment_author} '.format(
            comment_author=comment_author,
            instance_title=mg_globals.app_config['html_title']) \
                    + _('commented on your post'),
        'body': rendered_email
    }
Esempio n. 14
0
def generate_comment_message(user, comment, commentee, request):
    """
    Sends comment email to user when a comment is made on their media.

    Args:
    - user: the user object to whom the email is sent
    - comment: the comment wrapper object
    - commentee: the object the comment is on
    - request: the request
    """

    # Get the comment object associated to the wrapper
    comment_object = comment.comment()

    # Get the URL to the comment
    comment_url = request.urlgen(
        "mediagoblin.user_pages.media_home.view_comment",
        comment=comment.id,
        user=commentee.get_actor.username,
        media=commentee.slug_or_id,
        qualified=True) + "#comment"

    comment_author = comment.comment().get_actor.username

    rendered_email = render_template(
        request, 'mediagoblin/user_pages/comment_email.txt', {
            'username': user.username,
            'comment_author': comment_author,
            'comment_content': comment_object.content,
            'comment_url': comment_url
        })

    return {
        'from': mg_globals.app_config['email_sender_address'],
        'to': user.email,
        'subject': '{instance_title} - {comment_author} '.format(
            comment_author=comment_author,
            instance_title=mg_globals.app_config['html_title']) \
                    + _('commented on your post'),
        'body': rendered_email
    }
Esempio n. 15
0
def send_fp_verification_email(user, request):
    """
    Send the verification email to users to change their password.

    Args:
    - user: a user object
    - request: the request
    """
    rendered_email = render_template(
        request, 'mediagoblin/auth/fp_verification_email.txt',
        {'username': user.username,
         'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
                host=request.host,
                uri=request.urlgen('mediagoblin.auth.verify_forgot_password'),
                userid=unicode(user.id),
                fp_verification_key=user.fp_verification_key)})

    # TODO: There is no error handling in place
    send_email(
        mg_globals.app_config['email_sender_address'],
        [user.email],
        'GNU MediaGoblin - Change forgotten password!',
        rendered_email)
Esempio n. 16
0
def send_comment_email(user, comment, media, request):
    """
    Sends comment email to user when a comment is made on their media.

    Args:
    - user: the user object to whom the email is sent
    - comment: the comment object referencing user's media
    - media: the media object the comment is about
    - request: the request
    """

    comment_url = request.urlgen(
        'mediagoblin.user_pages.media_home.view_comment',
        comment=comment.id,
        user=media.get_uploader.username,
        media=media.slug_or_id,
        qualified=True) + '#comment'

    comment_author = comment.get_author.username

    rendered_email = render_template(
        request, 'mediagoblin/user_pages/comment_email.txt', {
            'username': user.username,
            'comment_author': comment_author,
            'comment_content': comment.content,
            'comment_url': comment_url
        })

    send_email(
        mg_globals.app_config['email_sender_address'],
        [user.email],
        '{instance_title} - {comment_author} '.format(
            comment_author=comment_author,
            instance_title=mg_globals.app_config['html_title']) \
                    + _('commented on your post'),
        rendered_email)
Esempio n. 17
0
def _update_email(request, form, user):
    new_email = form.new_email.data
    users_with_email = User.query.filter_by(email=new_email).count()

    if users_with_email:
        form.new_email.errors.append(_("Sorry, a user with that email address" " already exists."))

    elif not users_with_email:
        verification_key = get_timed_signer_url("mail_verification_token").dumps({"user": user.id, "email": new_email})

        rendered_email = render_template(
            request,
            "mediagoblin/edit/verification.txt",
            {
                "username": user.username,
                "verification_url": EMAIL_VERIFICATION_TEMPLATE.format(
                    uri=request.urlgen("mediagoblin.edit.verify_email", qualified=True),
                    verification_key=verification_key,
                ),
            },
        )

        email_debug_message(request)
        auth_tools.send_verification_email(user, request, new_email, rendered_email)
Esempio n. 18
0
def render_to_response(request, template, context, status=200):
    """Much like Django's shortcut.render()"""
    return Response(
        render_template(request, template, context),
        status=status)
Esempio n. 19
0
def render_to_response(request, template, context, status=200):
    """Much like Django's shortcut.render()"""
    return Response(
        render_template(request, template, context),
        status=status)