def _validate(self, data): if not data: flash(_('The verification token is invalid or expired.'), 'error') return False, None user = User.get(data['user_id']) if not user or user != self.user: flash(_('This token is for a different Indico user. Please login with the correct account'), 'error') return False, None existing = UserEmail.find_first(is_user_deleted=False, email=data['email']) if existing and not existing.user.is_pending: if existing.user == self.user: flash(_('This email address is already attached to your account.')) else: flash(_('This email address is already in use by another account.'), 'error') return False, existing.user return True, existing.user if existing else None