示例#1
0
def user_register(request):
    register_template = loader.get_template('register.html')

    if request.method == "POST":
        name = request.POST["name"]
        last_name = request.POST["lastName"]
        email = request.POST["email"]
        username = request.POST["username"]
        password = request.POST["password"]

        is_exist = User.objects.filter(email=email).count() > 0
        u = User(username=username, first_name=name, last_name=last_name, email=email)
        u.set_password(password)
        try:
            if is_exist:
                raise ValidationError("")
            u.full_clean()
        except ValidationError as e:
            if is_exist:
                context = RequestContext(request, {'error_message': "You have been registered with this email"})
            else:
                context = RequestContext(request, {'validation_error': e})
            return HttpResponse(register_template.render(context))
        u.is_active = False
        u.save()

        from Postchi.Mail import send_confirm_mail

        send_confirm_mail(u)  # Send Confirmation Link

        return HttpResponseRedirect(reverse('pending'))
    else:
        context = RequestContext(request)
        return HttpResponse(register_template.render(context))
示例#2
0
def confirm_again(request):
    if request.method == "POST":
        try:
            email = request.POST["email"]
            user = User.objects.get(email=email.strip())
            ConfirmMail.objects.filter(user_id=user.id).delete()
            send_confirm_mail(user)
            return HttpResponseRedirect(reverse('pending'))
        except Exception as e:
            return HttpResponseRedirect(reverse('exam:home'))
    else:

        template = loader.get_template('confirm_again.html')
        context = RequestContext(request)
        return HttpResponse(template.render(context))