def deleteDigestFromOtherUsers(self, user, digest): if digest: users = User.getByDigest(digest) for anotherUser in users: if anotherUser.email != user.email: anotherUser.hash = None anotherUser.save()
def getUserForEmailAndOrHash(self, digest: Digest, email: Union[str,None]): if email: user = User.getByEmail(email) self.checkUserAgainsDigest(digest, user) return user users = User.getByDigest(digest) self.assureExactlyOneUserInList(users) return users[0]
def getUserForEmailAndOrHash(self, digest, email): if email: user = User.getByEmail(email) self.deleteDigestFromOtherUsers(user, digest) self.checkUserAgainsDigest(digest, user) return user users = User.getByDigest(digest) self.assureExactlyOneUserInList(users) return users[0]
def getUserForEmailAndOrHash(self, digest: Digest, email: Union[str,None]): if email: user = User.getByEmail(email) if user is None: raise ReportedError([noSuchUser], 400) self.checkUserAgainsDigest(digest, user) return user users = User.getByDigest(digest) self.assureExactlyOneUserInList(users) return users[0]
def checkHashInOtherUsers(self, user: User, additionalInfo: dict, digest: Digest) -> None: if digest is None: return anotherUsers = User.getByDigest(digest) assuredCollision = False if anotherUsers: for aUser in anotherUsers: if self.handAssured(aUser): self.sendHashCollisionMail(aUser, assured=True, inAssurance=False) assuredCollision = True else: self.sendHashCollisionMail(aUser, assured=False, inAssurance=False) if assuredCollision: raise ReportedError([anotherUserUsingYourHash]) additionalInfo["message"] = anotherUserUsingYourHash
def deleteDigestFromOtherUsers(self, user: User) -> int: digest = user.hash numOfOthers = 0 assuredCollision = False if digest: users = User.getByDigest(digest) for anotherUser in users: if anotherUser.email != user.email: anotherUser.hash = None anotherUser.save() numOfOthers += 1 if self.handAssured(anotherUser): self.sendHashCollisionMail(anotherUser, assured=True, inAssurance=True) assuredCollision = True if assuredCollision: message = [otherUsersWithYourHash, numOfOthers] raise ReportedError(message) return numOfOthers
def _do_registration(self, form): additionalInfo = {} digest = form.digest.data if digest == '': digest = None if digest is not None: anotherUsers = User.getByDigest(form.digest.data) if anotherUsers: if self.isAnyoneHandAssurredOf(anotherUsers): raise ReportedError([anotherUserUsingYourHash], 400) additionalInfo["message"] = anotherUserUsingYourHash user = CredentialManager.create_user_with_creds( form.credentialType.data, form.identifier.data, form.secret.data, form.email.data, digest) self.sendPasswordVerificationEmail(user) user.set_authenticated() user.activate() r = self.loginUserInFramework(user) if r: return self.returnUserAndLoginCookie(user, additionalInfo)
def test_getByDigest_does_not_allow_null_digest(self): with self.assertRaises(ReportedError) as context: User.getByDigest(None) self.assertEqual(noHashGiven,context.exception.descriptor)