Example #1
0
 def create_from_registration(cls, name, email, password):
     user = cls.select().where(cls.email == email)
     if user.exists():
         raise EmailExistsException('account with given email already exists')
     return cls.create(
         join_date=datetime.utcnow(),
         name=name,
         email=email,
         password=generate_password_hash(password),
         email_validated=False,
         email_validation_secret=str(Identifier.new_random()),
         recovery_requested=False
     )
Example #2
0
 def test_checksum(self):
     """
     Test that the checksum catches any single-digit mistake
     """
     identifier = Identifier.new_random()
     string = str(identifier)
     for i in range(len(string)):
         while True:
             ch = random.choice(DIGITS)
             if ch != string[i]:
                 break
         invalid = string[0:i] + ch + string[i+1:]
         self.assertEqual(len(string), len(invalid))
         with self.assertRaises(InvalidChecksum):
             Identifier(invalid)
Example #3
0
 def go():
     email = 'vbraun.name+{0}@gmail.com'.format(Identifier.new_random())
     registrationdata = json.dumps(dict(
         name='Volker Braun',
         email=email,
         password='******'
     ))
     # Create account
     resp = yield from self.session.post('http://localhost:8080/api/v1/auth/register', data=registrationdata)
     self.assertEqual(resp.status, 200)
     # Try to login without validating email
     resp = yield from self.session.get('http://localhost:8080/api/v1/debug/user/{0}'.format(email))
     self.assertEqual(resp.status, 200)
     data = yield from resp.json()
     self.assertEqual(set(data.keys()), set(['success', 'user']))
     self.assertTrue(data['success'])
     self.assertEqual(data['user']['email'], email)
     self.assertEqual(data['user']['name'], 'Volker Braun')
     self.assertFalse(data['user']['email_validated'])
     self.assertFalse(data['user']['recovery_requested'])
     resp.close()
Example #4
0
 def test_random(self):
     for i in range(1000):
         self.check_identifier(Identifier.new_random())