コード例 #1
0
ファイル: user.py プロジェクト: getpatchwork/patchwork
def link(request):
    context = {}

    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            conf = EmailConfirmation(type='userperson',
                                     user=request.user,
                                     email=form.cleaned_data['email'])
            conf.save()

            context['confirmation'] = conf

            try:
                send_mail('Patchwork email address confirmation',
                          render_to_string('patchwork/user-link.mail',
                                           context, request=request),
                          settings.DEFAULT_FROM_EMAIL,
                          [form.cleaned_data['email']])
            except smtplib.SMTPException:
                context['confirmation'] = None
                context['error'] = ('An error occurred during confirmation. '
                                    'Please try again later')
    else:
        form = EmailForm()

    context['linkform'] = form

    return render(request, 'patchwork/user-link.html', context)
コード例 #2
0
ファイル: user.py プロジェクト: Aleks1966/patchwork
def link(request):
    context = {}

    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            conf = EmailConfirmation(type='userperson',
                                     user=request.user,
                                     email=form.cleaned_data['email'])
            conf.save()

            context['confirmation'] = conf

            try:
                send_mail(
                    'Patchwork email address confirmation',
                    render_to_string('patchwork/user-link.mail',
                                     context,
                                     request=request),
                    settings.DEFAULT_FROM_EMAIL, [form.cleaned_data['email']])
            except smtplib.SMTPException:
                context['confirmation'] = None
                context['error'] = ('An error occurred during confirmation. '
                                    'Please try again later')
    else:
        form = EmailForm()

    context['linkform'] = form

    return render(request, 'patchwork/user-link.html', context)
コード例 #3
0
def settings(request):
    if request.method == 'POST':
        form = EmailForm(data=request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            is_optout = EmailOptout.objects.filter(email=email).count() > 0
            return render(request, 'patchwork/mail-settings.html', {
                'email': email,
                'is_optout': is_optout
            })

    else:
        form = EmailForm()
    return render(request, 'patchwork/mail-form.html', {'form': form})
コード例 #4
0
ファイル: user.py プロジェクト: Aleks1966/patchwork
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(instance=request.user.profile,
                               data=request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    context = {
        'bundles': request.user.bundles.all(),
        'profileform': form,
    }

    # This looks unsafe but is actually fine: it just gets the names
    # of tables and columns, not user-supplied data.
    #
    # An example of generated SQL is:
    # patchwork_person.email IN (SELECT email FROM patchwork_emailoptout)
    optout_query = '%s.%s IN (SELECT %s FROM %s)' % (
        Person._meta.db_table, Person._meta.get_field('email').column,
        EmailOptout._meta.get_field('email').column,
        EmailOptout._meta.db_table)
    people = Person.objects.filter(user=request.user) \
        .extra(select={'is_optout': optout_query})
    context['linked_emails'] = people
    context['linkform'] = EmailForm()
    context['api_token'] = request.user.profile.token
    if settings.ENABLE_REST_API:
        context['rest_api_enabled'] = True

    return render(request, 'patchwork/profile.html', context)
コード例 #5
0
def profile(request):
    if request.method == 'POST':
        form = UserProfileForm(instance=request.user.profile,
                               data=request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    # TODO(stephenfin): Add a related_name for User->Bundle
    context = {
        'bundles': Bundle.objects.filter(owner=request.user),
        'profileform': form,
    }

    # FIXME(stephenfin): This looks unsafe. Investigate.
    optout_query = '%s.%s IN (SELECT %s FROM %s)' % (
        Person._meta.db_table, Person._meta.get_field('email').column,
        EmailOptout._meta.get_field('email').column,
        EmailOptout._meta.db_table)
    people = Person.objects.filter(user=request.user) \
        .extra(select={'is_optout': optout_query})
    context['linked_emails'] = people
    context['linkform'] = EmailForm()

    return render(request, 'patchwork/profile.html', context)
コード例 #6
0
ファイル: mail.py プロジェクト: asl/llvm-patchwork
def settings(request):
    context = PatchworkRequestContext(request)
    if request.method == 'POST':
        form = EmailForm(data = request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            is_optout = EmailOptout.objects.filter(email = email).count() > 0
            context.update({
                'email': email,
                'is_optout': is_optout,
            })
            return render_to_response('patchwork/mail-settings.html', context)

    else:
        form = EmailForm()
    context['form'] = form
    return render_to_response('patchwork/mail-form.html', context)
コード例 #7
0
ファイル: mail.py プロジェクト: ykhuat/patchwork
def settings(request):
    context = PatchworkRequestContext(request)
    if request.method == 'POST':
        form = EmailForm(data=request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            is_optout = EmailOptout.objects.filter(email=email).count() > 0
            context.update({
                'email': email,
                'is_optout': is_optout,
            })
            return render_to_response('patchwork/mail-settings.html', context)

    else:
        form = EmailForm()
    context['form'] = form
    return render_to_response('patchwork/mail-form.html', context)
コード例 #8
0
ファイル: mail.py プロジェクト: alialnu/patchwork
def settings(request):
    if request.method == 'POST':
        form = EmailForm(data=request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            is_optout = EmailOptout.objects.filter(email=email).count() > 0
            context = {
                'email': email,
                'is_optout': is_optout,
            }
            return render(request, 'patchwork/mail-settings.html', context)
    else:
        form = EmailForm()

    context = {
        'form': form,
    }

    return render(request, 'patchwork/mail-form.html', context)
コード例 #9
0
ファイル: mail.py プロジェクト: wangxi11/patchwork
def _optinout(request, action):
    context = {}
    mail_template = 'patchwork/mails/%s-request.txt' % action
    mail_subject_template = 'patchwork/mails/%s-request-subject.txt' % action
    html_template = 'patchwork/%s-request.html' % action

    if request.method != 'POST':
        return HttpResponseRedirect(reverse(settings))

    form = EmailForm(data=request.POST)
    if not form.is_valid():
        context['error'] = ('There was an error in the form. Please review '
                            'and re-submit.')
        context['form'] = form
        return render(request, html_template, context)

    email = form.cleaned_data['email']
    if action == 'optin' and EmailOptout.objects.filter(
            email=email).count() == 0:
        context['error'] = ("The email address %s is not on the patchwork "
                            "opt-out list, so you don't need to opt back in" %
                            email)
        context['form'] = form
        return render(request, html_template, context)

    conf = EmailConfirmation(type=action, email=email)
    conf.save()

    context['confirmation'] = conf

    subject = render_to_string(mail_subject_template)
    message = render_to_string(mail_template, context, request=request)

    try:
        send_mail(subject, message, conf_settings.DEFAULT_FROM_EMAIL, [email])
    except smtplib.SMTPException:
        context['confirmation'] = None
        context['error'] = ('An error occurred during confirmation . '
                            'Please try again later.')
        context['admins'] = conf_settings.ADMINS

    return render(request, html_template, context)
コード例 #10
0
ファイル: mail.py プロジェクト: alialnu/patchwork
def _optinout(request, action, description):
    context = {}
    mail_template = 'patchwork/%s-request.mail' % action
    html_template = 'patchwork/%s-request.html' % action

    if request.method != 'POST':
        return HttpResponseRedirect(reverse(settings))

    form = EmailForm(data=request.POST)
    if not form.is_valid():
        context['error'] = ('There was an error in the %s form. Please '
                            'review the form and re-submit.' % description)
        context['form'] = form
        return render(request, html_template, context)

    email = form.cleaned_data['email']
    if action == 'optin' and \
            EmailOptout.objects.filter(email=email).count() == 0:
        context['error'] = ("The email address %s is not on the patchwork "
                            "opt-out list, so you don't need to opt back in" %
                            email)
        context['form'] = form
        return render(request, html_template, context)

    conf = EmailConfirmation(type=action, email=email)
    conf.save()

    context['confirmation'] = conf
    mail = render_to_string(mail_template, context, request=request)

    try:
        send_mail('Patchwork %s confirmation' % description, mail,
                  conf_settings.DEFAULT_FROM_EMAIL, [email])
        context['email_sent'] = True
    except smtplib.SMTPException:
        context['error'] = ('An error occurred during confirmation . '
                            'Please try again later.')
        context['admins'] = conf_settings.ADMINS

    return render(request, html_template, context)