Ejemplo n.º 1
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            new_user = form.save()

            # Build the activation key
            salt = hashlib.md5(str(random.random())).hexdigest()[-5:]
            activation_key = hashlib.md5(salt+new_user.username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)
            new_activ = UserActivation(user=new_user,
                                       activation_key=activation_key,
                                       key_expires=key_expires)
            new_activ.save()

            # FIXME: move this to a template?
            # Send email with the activation information
            email_subject = _(u"Your FOSSAds Account")
            email_body = _(u"Hey %s, \n\n"
                           u"Thank you registered on the FOSSAds "
                           u"network.\n\n You can activate your account within "
                           u"two days, following this link:"
                           u"\n %s" % (
                               new_user.username,
                               settings.SITE_URL+'user/confirm/'+activation_key))
            send_mail(email_subject, email_body, settings.SITE_EMAIL,
                      [new_user.email])

            return render_to_response("register.html", {"thanks": True},
                                    context_instance=RequestContext(request))
    else:
        form = UserRegistrationForm()
    return render_to_response("register.html", {
        'form': form},
        context_instance=RequestContext(request))
Ejemplo n.º 2
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            new_user = form.save()

            # Build the activation key
            salt = hashlib.md5(str(random.random())).hexdigest()[-5:]
            activation_key = hashlib.md5(salt + new_user.username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)
            new_activ = UserActivation(user=new_user,
                                       activation_key=activation_key,
                                       key_expires=key_expires)
            new_activ.save()

            # FIXME: move this to a template?
            # Send email with the activation information
            email_subject = _(u"Your FOSSAds Account")
            email_body = _(
                u"Hey %s, \n\n"
                u"Thank you registered on the FOSSAds "
                u"network.\n\n You can activate your account within "
                u"two days, following this link:"
                u"\n %s" % (new_user.username, settings.SITE_URL +
                            'user/confirm/' + activation_key))
            send_mail(email_subject, email_body, settings.SITE_EMAIL,
                      [new_user.email])

            return render_to_response("register.html", {"thanks": True},
                                      context_instance=RequestContext(request))
    else:
        form = UserRegistrationForm()
    return render_to_response("register.html", {'form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 3
0
def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            new_user = form.save()

            # Build the activation key
            salt = hashlib.md5(str(random.random())).hexdigest()[-5:]
            activation_key = hashlib.md5(salt+new_user.username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)
            new_activ = UserActivation(user=new_user,
                                       activation_key=activation_key,
                                       key_expires=key_expires)
            new_activ.save()

            # FIXME: move this to a template?
            # Send email with the activation information
            email_subject = _(u"Contul tău cuZmeură")
            email_body = _(u"Salut %s, \n\n"
                           u"Îți mulțumim că te-ai înregistrat în rețeaua "
                           u"cuZmeură.\n\n Îți poți activa contul în "
                           u"următoarele două zile, urmând legătură aceasta:"
                           u"\n %s" % (
                               new_user.username,
                               settings.SITE_URL+'user/confirm/'+activation_key))
            send_mail(email_subject, email_body, settings.SITE_EMAIL,
                      [new_user.email])

            return render_to_response("register.html", {"thanks": True},
                                    context_instance=RequestContext(request))
    else:
        form = UserRegistrationForm()
    return render_to_response("register.html", {
        'form': form},
        context_instance=RequestContext(request))