def validate(self): if not FlaskForm.validate(self): return False # Cannot allow this Organization name, because it would cause issues on backend if self.organization_name.data == 'global': self.organization_name.errors.append( 'Cannot allow this Organization name for secret reasons, shush.' ) return False # TODO: remove these uniqueness checks after introduction of unique constraint # in ETCD storage class on backend client = get_service_client() # Check if organization exists on backend response = client.organization.list() if response.status > 200: self.organization_name.errors.append( 'Can not contact backend at this time.') return False organizations = response.data organization_names = [org['name'] for org in organizations] organization_namespaces = [o['namespace'] for o in organizations] if self.organization_name.data in organization_names or slugify( self.organization_name.data) in organization_namespaces: self.organization_name.errors.append( 'Organization {} already exists.'.format( self.organization_name.data)) return False # Check if e-mail and username exists on backend response = client.user.list() if response.status > 200: self.email.errors.append('Can not contact backend at this time.') return False users = response.data user_emails = [u['email'] for u in users if 'email' in u] if self.email.data in user_emails: self.email.errors.append('This e-mail is already registered.') return False user_usernames = [u['username'] for u in users] if self.email.data in user_usernames: self.email.errors.append('This username is already registered.') return False return True
def validate(self): if not FlaskExtendableForm.validate(self): return False # TODO: remove these uniqueness checks after introduction of unique constraint # in ETCD storage class on backend client = get_service_client() # Check if e-mail exists on backend response = client.user.list() if response.status > 200: self.email.errors.append('Can not contact backend at this time.') return False users = response.data user_emails = [u['email'] for u in users if 'email' in u] if self.email.data not in user_emails: self.email.errors.append('This e-mail is not registered.') return False return True
def _get_kqueen_service_client(self): return get_service_client()