class User(UsersMixin): def _validate_industries(field, value): for industry in value: yield from industry.industry.fetch(no_data=True) def _validate_invited_by(field, value): from models.utils import is_valid_invited_by if not (yield from is_valid_invited_by(value)): raise ValidationError('There is no such user or group code.') fullname = fields.StrField(required=True) email = fields.EmailField(unique=True, required=True) nickname = fields.StrField(unique=True, required=True, validate=validate.Regexp(r'[\w\d]+')) birthday = fields.DateTimeField(required=True, format=DATE_FORMAT) phone_numbers = fields.ListField( fields.StrField(validate=validate.Regexp(r'[+][\w\d]+')), required=True) photo = fields.StrField(required=True) bio = fields.StrField(required=False, validate=validate.Length(max=320)) organizations = fields.StrField(required=False, validate=validate.Length(max=320)) education = fields.StrField(required=False, validate=validate.Length(max=320)) personal_invite_code = fields.StrField( unique=True, required=True, validate=validate.Length(equal=INVITE_CODE_LENGTH)) social_links = fields.ListField(fields.EmbeddedField(SocialLink)) current_location = fields.EmbeddedField(Location) preferred_ways_to_meet = fields.ListField( fields.StrField(validate=validate.OneOf(PREFERRED_WAYS_TO_MEET)), unique=True) join_date = fields.DateTimeField(missing=datetime.utcnow()) is_active = fields.BoolField(missing=False) is_deleted = fields.BoolField() date_deleted = fields.DateTimeField() is_notifications_enabled = fields.BoolField(missing=True) skills = fields.ListField(fields.ReferenceField(Tag), required=True) interests = fields.ListField(fields.ReferenceField(Tag)) industries = fields.ListField(fields.EmbeddedField(Industry), required=True, io_validate=_validate_industries) languages = fields.ListField(fields.EmbeddedField(Language)) looking_for = fields.ListField(fields.ReferenceField(LookingFor)) bubbles = fields.ListField(fields.EmbeddedField(Bubble)) invited_type = fields.StrField(required=True, validate=validate.OneOf(INVITE_TYPE)) invited_by = fields.StrField(required=True, io_validate=_validate_invited_by)
class CafeEmployee(Document): username = fields.StringField(required=True, unique=True, validate=[ validate.Length(min=6), validate.Length(max=60), validate.Regexp(r"[a-zA-Z ']+") ]) password = fields.StringField(required=True, unique=True, validate=[ validate.Length(min=8), validate.Length(max=100), validate.Regexp(r"[a-zA-Z0-9 ']+") ]) id_cafe = fields.ReferenceField(Cafe) #fields.ObjectIdField # group = fields.IntegerField() token = fields.StringField(required=True) class Meta: collection = db.employee
class Permission(Document): codename = StringField( unique=True, allow_none=False, required=True, validate=validate.Regexp( r'^[a-z\-\.]+$', error="Field value can contain only 'a'-'z', '.', '-' characters.") ) description = StringField(allow_none=True) class Meta: indexes = [ '$codename', ]
class Microservice(Document): name = StringField(unique=True, allow_none=False, required=True) version = StringField( unique=False, allow_none=False, required=True, validate=validate.Regexp( r'^\d+\.\d+\.\d+$', error="Field value must match the `major.minor.patch` version semantics." ) ) permissions = ListField(ReferenceField(Permission)) class Meta: indexes = ['$name', ]
class RegisterUserSchema(UserSchema): phone = fields.StrField(required=True, validate=validate.Regexp(r'[+][\w\d]+')) industry = marshmallow_fields.Nested(IndustryTagSchema, required=True) skills = fields.ListField(fields.StrField(), required=True, validate=validate.Length(min=1, max=10)) interests = fields.ListField(fields.StrField(), validate=validate.Length(min=1, max=10)) class Meta: fields = ( 'email', 'password', 'fullname', 'nickname', 'birthday', 'phone', 'current_location', 'invited_type', 'invited_by', 'skills', 'interests', 'industry', ) dateformat = DATE_FORMAT @post_load def make_user(self, data): data['phone_numbers'] = [data.pop('phone')] industry = data.pop('industry') skills = data.pop('skills') interests = data.pop('interests') user = User(**data) user.set_password(data['password']) return { 'user': user, 'industry': industry, 'skills': skills, 'interests': interests, }
class User(Document): username = fields.StrField( required=True, unique=True, validate=[validate.Length(min=6, max=64), validate.Regexp(r'^\w+$')], error_messages={"unique": "Username already taken"}) passhash = BinaryField(required=True) passsalt = BinaryField(required=True) admin = fields.BoolField(default=False) signed_eula = fields.BoolField(default=False) # support for oauth via discord discord_id = fields.StrField(default=None) # potential other oauth? # might do github here. # we still force a password to exist on the account though. lockbox_token = fields.StrField( default=None) # not always present if not setup
class User(Document): # pylint: disable=abstract-method """ A user in the private database. """ token = fields.StrField(required=True, unique=True, validate=validate.Length(equal=64)) # The following 4 values could be unconfigured # Since the server only updates these after it validates credentials, # if both login and password exist, they're guaranteed to be valid credentials login = fields.StrField(required=False, unique=True, validate=validate.Regexp(r"\d+")) password = BinaryField(required=False) # Populated when credentials are set/updated # A value of null indicates either credentials are unset, # or the courses are in the process of being populated # An empty array indicates no courses found courses = fields.ListField(fields.ObjectIdField(), required=False, allow_none=True) # Should be set as soon as valid credentials are detected email = fields.EmailField(required=False, allow_none=True) active = fields.BoolField(default=True) errors = fields.ListField(fields.EmbeddedField(LockboxFailure), default=[]) last_fill_form_result = fields.EmbeddedField(FillFormResult, default=None, allow_none=True) grade = fields.IntField(required=False, allow_none=True, default=None) first_name = fields.StrField(required=False, allow_none=True, default=None, validate=lambda s: s is None or len(s)) last_name = fields.StrField(required=False, allow_none=True, default=None, validate=lambda s: s is None or len(s))
class Client(Document): phone_number = fields.StrField( validate=validate.Regexp(r'^[0-9 ]+$'))