示例#1
0
def register(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user=form.save(commit=False)
            user.set_password(form.cleaned_data['password'])
            user.is_active=False
            user.save()
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            email_subject = 'Account confirmation'
            activation_key=str(uuid.uuid4());
            key_expires = datetime.datetime.today() + datetime.timedelta(2)
            user=AuthUser.objects.get(username=username)
            new_profile = UserActivationProfile(user=user, activation_key=activation_key,
                                                      key_expires=key_expires)
            new_profile.save()
            email_body = "Hey %s, thanks for signing up. To activate your account, click this link within \
            48hours http://127.0.0.1:8000/accounts/confirm/%s" % (username, activation_key)
            
            send_mail(email_subject, email_body, '*****@*****.**',
                      [email], fail_silently=False)
            
            return HttpResponseRedirect('/register/success/')
    else:
        form=RegistrationForm();
    return render(request,'blog/registration.html',{'form':form})
示例#2
0
def register(request):
    args={}
    args.update(csrf(request))
    variables=None
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user=form.save(commit=False)
            user.set_password(form.cleaned_data['password'])
            user.is_active=False
            user.save()
            fname=form.cleaned_data['first_name']
            username=form.cleaned_data['username']
            email=form.cleaned_data['email']
            email_subject="Account confirmation"
            activation_key=str(uuid.uuid4())
            email_body="Dear %s,\n Thanks for signing up.\n To activate your account\n, click this link within 24 haurs \nhttp://kundansable.pythonanywhere.com/accounts/confirm/%s" % (fname,activation_key)
            key_expires=timezone.now() + datetime.timedelta(1)
            user=AuthUser.objects.get(username=username)
            new_profile=UserActivationProfile(user=user, activation_key=activation_key, key_expires=key_expires)
            new_profile.save()
    
            send_mail(email_subject, email_body,'*****@*****.**',[email],fail_silently=False)
           
            return HttpResponseRedirect('/register/success/')
    else:
        form = RegistrationForm()
    return render(request,'blog/register.html',{'form':form})
示例#3
0
def register(request):
    args = {}
    args.update(csrf(request))
    variables = None
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.set_password(form.cleaned_data["password"])
            user.is_active = False
            user.save()
            username = form.cleaned_data["username"]
            email = form.cleaned_data["email"]
            email_subject = "Account confirmation"
            activation_key = str(uuid.uuid4())
            email_body = (
                "hey %s, thanks for signing up. to activate your account, click this link within 24 haurs http://127.0.0.1:8000/accounts/confirm/%s"
                % (username, activation_key)
            )
            key_expires = datetime.datetime.today() + datetime.timedelta(1)
            user = AuthUser.objects.get(username=username)
            new_profile = UserActivationProfile(user=user, activation_key=activation_key, key_expires=key_expires)
            new_profile.save()

            send_mail(email_subject, email_body, "*****@*****.**", [email], fail_silently=False)

            return HttpResponseRedirect("/register/success/")
    else:
        form = RegistrationForm()
    return render(request, "blog/register.html", {"form": form})