class UserModel(Model): _name = 'users' id = IntType(required=False) first_name = StringType(required=True) last_name = StringType(required=False, default='') type = ModelType(UserType, required=True) descr = StringType(required=False, default='') user_photo = StringType(required=False, default='') user_photos = StringType(required=False, default='') email = EmailType(required=True) nickname = StringType(required=True) password = StringType(required=True) create_time = DateTimeType(required=True, default=datetime.now()) users_add = One2One(UserAddModel)
class ContactPoint(Model): class Options: serialize_when_none = False name = StringType(required=True) name_en = StringType() name_ru = StringType() email = EmailType() telephone = StringType() faxNumber = StringType() url = URLType() def validate_email(self, data, value): if not value and not data.get('telephone'): raise ValidationError(u"telephone or email should be present")
class SignupDataModel(Model): email = EmailType(min_length=3, max_length=30, required=True, metadata=ValidatorDoc('Email')) username = StringType(min_length=2, max_length=30, metadata=ValidatorDoc('Username')) password = StringType(required=True, min_length=6, max_length=64, metadata=ValidatorDoc('Password')) nickname = StringType(min_length=2, max_length=10, metadata=ValidatorDoc('Nickname'))
class UserModel(Model): firstname = StringType(required=True) firstname.serialized_name = "First Name" firstname.max_length = 40 lastname = StringType(required=True) lastname.serialized_name = "Last Name" lastname.max_length = 40 email = EmailType(required=True) email.serialized_name = "Email" phone = StringType(required=False, serialized_name='Phone Number', max_length=30)
class SignupRequestByEmailDataModel(Model): """ 申请进行邮箱注册 """ email = EmailType(min_length=3, max_length=config.USER_EMAIL_MAX, required=True, validators=[email_exists_check], metadata=ValidatorDoc('邮箱')) password = StringType(required=True, min_length=6, max_length=64, metadata=ValidatorDoc('密码')) nickname = StringType(min_length=2, max_length=10, metadata=ValidatorDoc('昵称'))
class Login(Model): federated_platform = StringType(choices=["Facebook", "Google", "GitHub"]) federated_token = StringType() email = EmailType() password = StringType() def validate_email(self, data, value): if data["federated_token"] is None: if value is None: raise ValidationError( "either a federated login or an email address is required") def validate_password(self, data, value): if data["email"] is not None: if value is None: raise ValidationError( "email address must be accompanied by a password")
class Login(Model): federated_platform = StringType(choices=['Facebook', 'Google', 'GitHub']) federated_token = StringType() email = EmailType() password = StringType() def validate_email(self, data, value): if data['federated_token'] is None: if value is None: raise ValidationError( 'either a federated login or an email address is required') def validate_password(self, data, value): if data['email'] is not None: if value is None: raise ValidationError( 'email address must be accompanied by a password')
class ResponseServiceAccount(Model): name = KubeName(required=True, min_length=3) email = EmailType(required=True) keys = DictType(ArrowType, required=True) state = EnumType(ResourceState, required=True) created_at = ArrowType(required=True) @classmethod def from_database(cls, service_account): model = cls() model.name = service_account.name model.email = service_account.email model.keys = service_account.keys model.state = service_account.state model.created_at = service_account.created_at return model
class Email(Embs): address = EmailType(required=True, description='Email Address') note = StringType(description='note') meta = { '_c': 'Email', } @property def vNam(self): dNam = 'typ_' + self.typ + ': ' + self.address.lower() dNam += ' (Primary)' if self.prim else '' dNam += (' ' + self.note) if self.note else '' return dNam @property def vNamS(self): return (self.typ + ':' + self.address).lower()
class NewUser(Model): """ Parameter to create a new user. only name and password are required a ``NewContact`` can be attached when creating user """ contact = ModelType(NewContact) main_user_id = UUIDType() name = StringType(required=True) params = DictType(StringType()) password = StringType(required=True) recovery_email = EmailType(required=True) settings = ModelType(Settings, default=lambda: {}) class Options: serialize_when_none = False
class SignerModel(Model): id = IntType() name = StringType() email = EmailType() role = StringType() order = IntType() pin = StringType() message = StringType() signed = BoolIntType() signed_timestamp = TimestampType() required = BoolIntType() declined = BoolIntType() sent = BoolIntType() viewed = BoolIntType() status = StringType() embedded_signing_url = StringType() deliver_email = BoolIntType() class Options: serialize_when_none = False
class Login(Model): """Representation of the login information for an add account request.""" federated_platform = StringType(choices=["Facebook", "Google", "GitHub"]) federated_token = StringType() email = EmailType() password = StringType() def validate_email(self, data, value): # pylint: disable=no-self-use """If email address is used to login, it must be specified.""" if data["federated_token"] is None: if value is None: raise ValidationError( "either a federated login or an email address is required") def validate_password(self, data, value): # pylint: disable=no-self-use """If email address is used to login, the password must be supplied.""" if data.get("email") is not None: if value is None: raise ValidationError( "email address must be accompanied by a password")
class Alias(Model, Resource): resource_id = IntType() href = URLType() domain = ModelType(Domain) name = StringType(validators=[is_email_left_part]) redirect_to = EmailType() is_enabled = BooleanType() collection = ModelType(Collection) rule = ModelType(Rule) @serializable def domain_id(self): return self.domain.resource_id @serializable def whitelist(self): if hasattr(self.rule, 'condition_value'): return self.rule.condition_value def __init__(self, name, domain, redirect_to, **kwargs): resource_id = kwargs.pop('resource_id', None) href = kwargs.pop('href', None) is_enabled = kwargs.pop('is_enabled', False) collection = kwargs.pop('collection', None) rule = kwargs.pop('rule', None) super(Alias, self).__init__(**kwargs) self.resource_id = resource_id self.href = href self.domain = domain self.name = name self.redirect_to = redirect_to self.is_enabled = is_enabled self.collection = collection if rule is not None: self.rule = rule def __str__(self): return "{}@{}".format(self.name, self.domain.name)
class ContactPoint(Model): name = StringType(required=True) name_en = StringType() name_ru = StringType() email = EmailType() telephone = StringType() faxNumber = StringType() url = URLType() def validate_email(self, data, value): if not value and not data.get("telephone"): raise ValidationError("telephone or email should be present") def validate_telephone(self, data, value): try: root = get_schematics_document(data["__parent__"]) except AttributeError: pass else: apply_validation = get_first_revision_date(root, default=get_now()) >= VALIDATE_TELEPHONE_FROM if value and re.match("^(\+)?[0-9]{2,}(,( )?(\+)?[0-9]{2,})*$", value) is None and apply_validation: raise ValidationError(u"wrong telephone format (could be missed +)")
class UserModel(BaseModel): _id = EmailType(required=True) password = StringType(required=True, min_length=6, max_length=50) name = StringType(required=True) MONGO_COLLECTION = 'accounts' @property def email(self): return self._id @email.setter def email(self, value): self._id = value @classmethod def process_query(cls, params): params = dict(params) if 'email' in params: params['_id'] = params.pop('email') return params def validate(self, *args, **kwargs): try: return super(UserModel, self).validate(*args, **kwargs) except ModelValidationError as e: if '_id' in e.messages: e.messages['email'] = e.messages.pop('_id') raise def check_password(self, entered_password): return check_password(entered_password, self.password) def set_password(self, plaintext): self.password = make_password(plaintext) def insert(self, *args, **kwargs): return super(UserModel, self).insert(*args, **kwargs)
class Email(Model): address = EmailType(required=True) status = StringType(choices=['valid', 'pending']) activation_code = StringType() class Options: serialize_when_none = False roles = { 'safe': blacklist('activation_code'), } def activate_with_code(code): if code == self.activation_code: self.status = 'valid' self.activation_code = None def gravatar_url(self, size=40, default=None): if default is None: default = 'mm' gravatar_url = "http://www.gravatar.com/avatar/{hash}?{args}" return gravatar_url.format(hash=hashlib.md5( self.address.lower()).hexdigest(), args=urllib.urlencode({ 'd': default, 's': str(size) })) @property def uniquify(self): """Removes dots and +XXX from Gmail addresses.""" ua = self.address.lower() if 'gmail.com' not in ua: return ua gmail_regex = re.compile('[%s]' % re.escape(string.punctuation)) ua = ua.split('@')[0].split('+')[0] # first split on @, then on + ua = gmail_regex.sub('', ua) return '{user}@gmail.com'.format(user=ua)
class FileModel(Model): filename = StringType( serialized_name = "File Name", max_length=255) size = IntType( serialized_name = "File Size" ) content_type = StringType( serialized_name = "File Type" ) public_id = UUIDType( serialized_name = "Published Object ID" ) object_id = ObjectIdType( serialized_name = 'Internal Object ID') owner = EmailType( serialized_name = "Owner ID") public = BooleanType ( default=True, serialized_name = "Publicly Visible")
class Party(BaseModel): metadata = dict( label='party', description= 'A party is a person, project or organization related to a package.') type = StringType(choices=PARTY_TYPES) type.metadata = dict(label='party type', description='the type of this party: One of: ' + ', '.join(PARTY_TYPES)) name = StringType() name.metadata = dict(label='name', description='Name of this party.') url = URLType() name.metadata = dict( label='url', description='URL to a primary web page for this party.') email = EmailType() email.metadata = dict(label='email', description='Email for this party.') class Options: fields_order = 'type', 'name', 'email', 'url'
class Data(Model): a = EmailType()
class ContactPoint(BaseContactPoint): email = EmailType(required=True) telephone = StringType(required=True)
'min_length': 3, 'max_length': config.USER_EMAIL_MAX, 'metadata': ValidatorDoc('邮箱') } _nickname_type_kwargs = { 'min_length': min(config.USER_NICKNAME_CN_FOR_REG_MIN, config.USER_NICKNAME_FOR_REG_MIN), 'max_length': config.USER_NICKNAME_FOR_REG_MAX, 'validators': [nickname_check, nickname_exists_check], 'metadata': ValidatorDoc('昵称') } email_type = EmailType(**_email_type_kwargs) email_type_required = EmailType(required=True, **_email_type_kwargs) nickname_type = StringType(**_nickname_type_kwargs) nickname_type_required = StringType(required=True, **_nickname_type_kwargs) class RequestResetPasswordDataModel(Model): """ 申请重置密码 """ email = email_type_required nickname = nickname_type_required class ValidatePasswordResetPostDataModel(Model):
class User(Model): user_id = ObjectId() email = EmailType(required=True) name = StringType(required=True) password = StringType(required=True)
class UserSchema(Model): email = EmailType(required=True)
class RequestOAuthToken(Model): email = EmailType(required=True) password = StringType(min_length=1, required=True) otp_code = StringType()
class User(Model): username = StringType(min_length=2, max_length=20, required=True) email = EmailType(max_length=30, required=True)
def test_email_type_with_invalid_email(self): with self.assertRaises(ValidationError): EmailType().validate(u'sdfg\U0001f636\U0001f46e')
class User(Model): id = UUIDType(auto_fill=True) username = StringType(min_length=2, max_length=20, required=True) email = EmailType(max_length=30, required=True)
def test_email_type_with_invalid_email(): with pytest.raises(ValidationError): EmailType().validate(u'sdfg\U0001f636\U0001f46e')
class User(XMLModel): email = EmailType()
class SignupConfirmByEmailDataModel(Model): email = EmailType(min_length=3, max_length=config.USER_EMAIL_MAX, required=True, metadata=ValidatorDoc('邮箱')) code = BlobType(required=True, metadata=ValidatorDoc('验证码'))