def create_signup_code(self, commit=True):
     email = self.cleaned_data["email"]
     expiry = datetime.now() + timedelta(hours=1)
     code = sha_constructor("%s%s%s%s" % (
         settings.SECRET_KEY,
         email,
         str(expiry),
         settings.SECRET_KEY,
     )).hexdigest()
     signup_code = SignupCode(code=code, email=email, max_uses=1, expiry=expiry)
     if commit:
         signup_code.save()
     return signup_code
Exemple #2
0
 def create_signup_code(self, commit=True):
     email = self.cleaned_data["email"]
     expiry = datetime.now() + timedelta(hours=1)
     bits = [
         settings.SECRET_KEY,
         email,
         str(expiry),
     ]
     if self.group:
         bits.append("%s%s" % (self.group._meta, self.group.pk))
     code = sha_constructor("".join(bits)).hexdigest()
     signup_code = SignupCode(code=code, email=email, max_uses=1, expiry=expiry)
     if commit:
         signup_code.save()
     return signup_code
Exemple #3
0
 def create_signup_code(self, commit=True):
     email = self.cleaned_data["email"]
     expiry = datetime.now() + timedelta(hours=1)
     code = sha_constructor("%s%s%s%s" % (
         settings.SECRET_KEY,
         email,
         str(expiry),
         settings.SECRET_KEY,
     )).hexdigest()
     signup_code = SignupCode(code=code,
                              email=email,
                              max_uses=1,
                              expiry=expiry)
     if commit:
         signup_code.save()
     return signup_code
    def test_accept_invite(self):
        """
        test the user's ability to accept their token
        """

        #print help(self)
        # Create an invitation
        email = "*****@*****.**"
        expiry = datetime.datetime.now() + datetime.timedelta(hours=1)
        code = sha_constructor("%s%s%s%s" % (
            settings.SECRET_KEY,
            email,
            str(expiry),
            settings.SECRET_KEY,
        )).hexdigest()
        signup_code = SignupCode(code=code,
                                 email=email,
                                 max_uses=1,
                                 expiry=expiry)
        signup_code.save()

        # First the invitee tries a bad signup_code
        data = {"code": "12345"}
        response = self.client.get(reverse("test_signup"), data)
        print response
        self.assertContains(response, "Incorrect Code")

        # Now they remember the code and try the right one
        data = {"code": signup_code.code}
        response = self.client.get(reverse("test_signup"), data, follow=True)

        self.assertContains(response, "id_username")
        self.assertContains(response, "id_email")
        self.assertContains(response, "id_password")

        # User now creates their account
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": "abc1234",
            "password2": "abc1234",
            "signup_code": signup_code.code,
            "submit": "Sign Up »"
        }
        response = self.client.post(reverse("test_signup"), data, follow=True)
        print User.objects.all()
Exemple #5
0
 def create_signup_code(self, commit=True):
     email = self.cleaned_data["email"]
     expiry = datetime.now() + timedelta(hours=1)
     bits = [
         settings.SECRET_KEY,
         email,
         str(expiry),
     ]
     if self.group:
         bits.append("%s%s" % (self.group._meta, self.group.pk))
     code = sha_constructor("".join(bits)).hexdigest()
     signup_code = SignupCode(code=code,
                              email=email,
                              max_uses=1,
                              expiry=expiry)
     if commit:
         signup_code.save()
     return signup_code
Exemple #6
0
 def test_accept_invite(self):
     """
     test the user's ability to accept their token
     """
     
     #print help(self)
     # Create an invitation
     email = "*****@*****.**"
     expiry = now() + datetime.timedelta(hours=1)
     code = sha_constructor("%s%s%s%s" % (
         settings.SECRET_KEY,
         email,
         str(expiry),
         settings.SECRET_KEY,
     )).hexdigest()
     signup_code = SignupCode(code=code, email=email, max_uses=1, expiry=expiry)
     signup_code.save()
     
     # First the invitee tries a bad signup_code
     data = { "code":"12345" }
     response = self.client.get(reverse("test_signup"), data)
     print response
     self.assertContains(response, "Incorrect Code")
     
     # Now they remember the code and try the right one
     data = { "code" : signup_code.code }
     response = self.client.get(reverse("test_signup"), data, follow=True)
     
     self.assertContains(response, "id_username")
     self.assertContains(response, "id_email")
     self.assertContains(response, "id_password")
     
     # User now creates their account
     data = { "username" : "joe",
              "email": "*****@*****.**",
              "password1": "abc1234",
              "password2": "abc1234",
              "signup_code":signup_code.code,
              "submit":"Sign Up »"
             }
     response = self.client.post(reverse("test_signup"), data, follow=True)
     print User.objects.all()