Example #1
0
def request_temp_login(request):
    if request.method == 'POST':
        form = TemporaryLoginRequestForm(request.POST)

        if form.is_valid():
            user = form.user_cache

            try:
                hash = get_object_or_404(ValidationHash, user=user, type='templogin')
                if hash.expiration < datetime.datetime.now():
                    hash.delete()
                    return request_temp_login(request)
            except:
                hash = ValidationHash.objects.create_new(user, 'templogin', [user.id])

            send_email(_("Temporary login link"), [user.email], "auth/temp_login_email.html", {
                'temp_login_code': hash,
                'user': user
            })

            request.user.message_set.create(message=_("An email has been sent with your temporary login key"))

            return HttpResponseRedirect(reverse('index'))
    else:
        form = TemporaryLoginRequestForm()

    return render_to_response(
            'auth/temp_login_request.html', {'form': form}, 
            context_instance=RequestContext(request))
Example #2
0
def send_validation_email(user):
    hash = ValidationHash.objects.create_new(user, 'email', [user.email])
    send_email(_("Email Validation"), [user.email], "auth/email_validation.html", {
        'validation_code': hash,
        'user': user
    })