示例#1
0
文件: views.py 项目: shula/citytree
    def register_new_account(s, request):
        registration_success_template = "accounts/registration_success.html"
        s.rform = RegisterForm(request.POST, prefix="register")

        if not s.rform.is_valid():
            s.status = "rform_not_valid"
            s.hash = request.POST["register-hash"]
        else:
            cleaned_data = s.rform.cleaned_data
            # TODO: hash gets out of sync
            if cleaned_data["hash"] != request.POST["hash2"]:
                import pdb

                pdb.set_trace()
            cleaned_data["hash"] = request.POST["hash2"]
            username = cleaned_data["username"]
            password = cleaned_data["password"]
            s.hash = cleaned_data["hash"]
            capcha_response = cleaned_data["capcha_response"]
            try:
                capcha_request = CapchaRequest.objects.get(hash=s.hash)
            except DoesNotExist:
                # known bug - try to work around it
                # s.response = HttpResponseRedirect('/accounts/login_and_register')
                s.status = "capcha_request not found for %s" % s.hash
                return
            # ok - it's the reversed. But just in case something screwi happens - I'm
            # willing to cut search space in half.
            if capcha_request.letters not in [capcha_response, unicode_reverse(capcha_response)]:
                s.rform.errors["capcha_response"] = [u"סליחה, התשובה לא מתקמפלת"]
                # reset capcha
                s.hash = new_capcha_request(
                    s.rform, reuse_hash=s.hash
                )  # yes, I reuse the hash for a different set of letters. Not really a problem I think? ok, it might be.
                # s.response = HttpResponseRedirect('/accounts/login_and_register/')
                return
            if User.objects.filter(username=username).count() != 0:
                s.rform.errors["username"] = [u"שם המשתמש תפוס"]
            if not password_check(password):
                s.rform.errors["password"] = [u"ססמה חייבת להיות לפחות 6 תווים, 4 שונים לפחות."]
            if len(s.rform.errors) == 0:
                print "no errors in reg form"
                capcha_request.delete()  # NOTE: only delete capcha if rest of form is ok. This means user doesn't have to resolve the capcha if the other information is wrong.
                email = s.rform.cleaned_data["email"]
                user = User.objects.create_user(username=username, email=email, password=password)
                user.first_name = cleaned_data["first_name"]
                user.last_name = cleaned_data["last_name"]
                user.save()
                cleaned_data["password"] = password
                send_email_to("accounts/create_acount_email.txt", email, "פרטי חשבון עץ בעיר", cleaned_data)
                s.template = registration_success_template
                # login already
                user = authenticate(username=username, password=password)
                login(request, user)
            else:
                s.status = "regfailed"
示例#2
0
文件: views.py 项目: shula/citytree
 def notify_on_registration(workshop_event, user_name, phone_number,
         email):
     send_email_to(template='workshop/user_registered_email.txt',
             to=settings.WORKSHOP_REGISTRATION_NOTIFICATION_EMAIL,
             subject="citytree: workshop %s, on the %s: '%s' registered" %
                 (workshop_event.workshop.name,
                  workshop_event.start_date.isoformat(),
                  user_name),
             context_dict = {
                 'user_name': user_name,
                 'workshop_event' : workshop_event,
                 'phone_number' : phone_number,
                 'email' : email,
                 },
             fail_silently = True)
示例#3
0
文件: views.py 项目: shula/citytree
def old_join(request):
    email = request.GET['q']
    site = Site.objects.get_current().name
    d = {'site': site, 'email':email}
    if not check_email(email):
        return render_to_response('mailinglist/join_error.html', d
            , context_instance = RequestContext(request))

    if MailingListSubscriber.objects.filter(email=email).count() == 0:
        mls = MailingListSubscriber(email=email, confirmed=False, confirm_code=make_random_hash())
        mls.save()
        d['confirm_code'] = mls.confirm_code
        send_email_to('mailinglist/request_confirmation.txt', email,
                loader.get_template('mailinglist/request_confirmation__subject.txt').render(Context({})), d, fail_silently=False)
        
    return render_to_response('mailinglist/join_confirm.html', d
        , context_instance=RequestContext(request))
示例#4
0
文件: models.py 项目: shula/citytree
 def email(self, comment, content_object):
     self._hash = make_random_hash()
     hide_hash = HashPoint.new(data=str(comment.id), comment='hide_comment')
     post = content_object # same thing
     if self.really_send_email_to_this_person is None:
         recipient_list = [post.author.email]
     else:
         recipient_list = [self.really_send_email_to_this_person]
     site = Site.objects.get_current().name
     from spamdetector.models import AllowedBanRequests
     AllowedBanRequests(ip_address = comment.ip_address, hash=self._hash).save()
     c = Context({ 'comment': comment,
                   'content_object': content_object,
                   'site': site,
                   'ban_hash': self._hash,
                   'hide_hash': hide_hash})
     subject = u'[%s] New comment posted on "%s"' % (site, content_object)
     send_email_to(template='cityblog/post_comment_notification_email.txt',
             to=recipient_list, subject=subject, context_dict=c,
             fail_silently=True)