Пример #1
0
def reset(request):
    """
    Prompt a user for their email address.
    """
    if request.method == 'POST':
        form = ResetForm(data=request.POST)
        if form.is_valid():
            key = ConfirmationKey(user=form.user)
            key.save()
            template = render_to_string(
                'accounts/emails/reset.txt', {
                    'user':
                    key.user,
                    'url':
                    request.build_absolute_uri(
                        reverse('accounts:reset_confirm',
                                kwargs={'key': key.key})),
                })
            send_mail('2buntu Password Reset', template,
                      '2buntu <*****@*****.**>', [key.user.email])
            messages.info(
                request,
                "An email has been sent to the address you provided with instructions on completing the password reset procedure."
            )
            return redirect('home')
    else:
        form = ResetForm()
    return render(
        request, 'form.html', {
            'title': 'Reset Password',
            'form': form,
            'description':
            "Please fill in the form below to begin the password reset procedure.",
            'action': 'Continue',
        })
Пример #2
0
def register(request):
    """
    Present a registration form for new users.
    """
    if request.method == 'POST':
        form = RegistrationForm(data=request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.email = form.cleaned_data['email']
            user.is_active = False
            user.save()
            key = ConfirmationKey(user=user)
            key.save()
            template = render_to_string('accounts/emails/register.txt', {
                'user': user,
                'url': request.build_absolute_uri(reverse('accounts:register_confirm', kwargs={'key': key.key})),
            })
            send_mail('2buntu Registration', template, '2buntu <*****@*****.**>', [user.email])
            messages.info(request, "Please check the email address you provided for instructions on activating your account.")
            return redirect('home')
    else:
        form = RegistrationForm()
    return render(request, 'form.html', {
        'title': 'Register',
        'form': form,
        'description': "Please fill in the form below to create your account.",
        'action': 'Register',
    })
def reset(request):
    """Prompt a user for their email address."""
    if request.method == 'POST':
        form = ResetForm(data=request.POST)
        if form.is_valid():
            key = ConfirmationKey(user=form.user)
            key.save()
            template = render_to_string('emails/reset.txt', {
                'user': key.user,
                'url':  request.build_absolute_uri(reverse('accounts:reset_confirm', kwargs={'key': key.key,})),
            })
            send_mail('2buntu Password Reset', template, '2buntu <*****@*****.**>', [key.user.email,])
            messages.info(request, "An email has been sent to the address you provided with instructions on completing the password reset procedure.")
            return redirect('home')
    else:
        form = ResetForm()
    return render(request, 'form.html', {
        'title':       'Reset Password',
        'form':        form,
        'description': "Please fill in the form below to begin the password reset procedure.",
        'action':      'Continue',
    })