def __call__(self, value): splitted_value = value.replace(">", "").split("<") # INFO - G.M - 2019-09-16 - email only if len(splitted_value) == 1: Email.__call__(self, splitted_value[0]) # INFO - G.M - 2019-09-16 - name <*****@*****.**> case elif len(splitted_value) == 2: Email.__call__(self, splitted_value[1]) else: message = self._format_error(value) raise ValidationError(message) return value
def _check_email(self, value): recipients = clean_recipients(value) for recipient in recipients: email = recipient[1] if isinstance(recipient, tuple) else recipient # Validate email with Marshmallow validator = Email() validator(email)
def is_valid_email(value: str) -> bool: # noqa: D103 try: validator = Email() validator(value) return True except ValidationError: return False
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User include_relationships = True load_instance = True fields = ( "id", "first_name", "password", "last_name", "email", "username", "avatar", "bio", "timestamp", "confirmation", "posts", ) dump_only = ("id", "confirmation", "timestamp") password = ma.String(load_only=True) email = ma.Email(required=True, validate=Email()) posts = Nested("PostSchema", many=True, only=("title", "id"), dump_only=True) @pre_dump def _pre_dump(self, user, **kwargs): user.confirmation = [user.most_recent_confirmation] return user
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = ["password"] email = ma.String(required=True, validate=[Length(min=4), Email()]) password = ma.String(required=True, validate=Length(min=6))
class UpdateUserSchema(Schema): """Validate update user input""" name = fields.Str(validate=Length(min=5, max=255)) display_name = fields.Str(validate=Length(max=255)) email = fields.Str(validate=[Length(max=255), Email()]) password = fields.Str(validate=Length(min=6, max=64)) enabled = fields.Boolean() role_id = fields.Str(validate=Length(max=64))
def validate_email(value: str, silently=False): try: Email()(value) except ValidationError as e: if silently: return False raise SystemExit(e.messages[0]) return True
class LoggedInUserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = ["password"] email = ma.String(required=True, validate=[Length(min=4), Email()]) username = ma.String(required=True, validate=[Length(min=1)]) f_name = ma.String(required=True, validate=[Length(min=2)]) l_name = ma.String(required=True, validate=[Length(min=2)]) password = ma.String(required=True, validate=Length(min=6))
class UserSchema(ma.SQLAlchemyAutoSchema): # Generates Schema automatically class Meta: model = User # Generate Schema using the User Model load_only = [ "password" ] # This will load the password but it wont send it to the front end email = ma.String(required=True, validate=[ Length(min=4), Email() ]) # The email is required and must be at least 4 chars long password = ma.String(required=True, validate=Length( min=6)) # The password is required and must be at least 6 chars long
class CreateUserSchema(Schema): """Validate create user input""" name = fields.Str(required=True, validate=Length(min=5, max=255)) display_name = fields.Str(validate=Length(max=255)) email = fields.Str(validate=[Length(max=255), Email()]) password = fields.Str(required=True, validate=Length(min=6, max=64)) enabled = fields.Boolean() role_id = fields.Str(validate=Length(max=64)) @post_load def make_user(self, data): return User.from_dict(data)
class UserSchema(ma.Schema): id = ma.String(dump_only=True) user_id = ma.String(load_only=True) first_name = ma.String(max_length=100, required=True, validate=Length(max=100)) last_name = ma.String(max_length=100, required=True, validate=Length(max=100)) email = ma.String(max_length=150, required=True, validate=[Email(), Length(max=150)]) username = ma.String(max_length=50, required=True, validate=Length(max=50)) phone = ma.String(max_length=30, required=True, validate=Length(max=30)) class Meta: model = User additional = ("last_seen", "member_since", "password") dateformat = '%Y-%m-%dT%H:%M:%S%z' model_fields_kwargs = { 'member_since': { 'dump_only': True }, 'last_seen': { 'dump_only': True }, 'password': { 'load_only': True } } _links = ma.Hyperlinks({ "self": ma.URLFor("api.user_api", user_id="<id>"), "collection": ma.URLFor("api.user_api") }) @validates_schema def validate_unique_fields(self, data, **kwargs): errors = {} user = User.objects(email__iexact=data['email']).first() if data.get('user_id', None) is None else \ User.objects(email__iexact=data['email'], id__ne=data['user_id']).first() if user is not None: errors['email'] = ["Email already exist."] print(user.id, data.get('id', None)) user = User.objects(username__iexact=data['username']).first() if data.get('user_id', None) is None else \ User.objects(username__iexact=data['username'], id__ne=data['user_id']).first() if user is not None: errors['username'] = ["Username already exist."] if errors: raise ValidationError(errors)
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = [ "f_name", "l_name", "email", "state", "post_code", "address", "country", "password" ] email = ma.String(required=True, validate=[Length(min=4), Email()]) username = ma.String(required=True, validate=[Length(min=1)]) f_name = ma.String(required=True, validate=[Length(min=2)]) l_name = ma.String(required=True, validate=[Length(min=2)]) password = ma.String(required=True, validate=Length(min=6))
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = ["password"] username = ma.String(required=True, validate=Length(min=4)) first_name = ma.String(required=True, validate=Length(min=2)) last_name = ma.String(required=True, validate=Length(min=2)) created_at = ma.DateTime(required=True) dob = ma.DateTime(required=True) email = ma.String(required=True, validate=Email()) mobile = ma.String() city = ma.String(required=True) country = ma.String(required=True) password = ma.String(required=True)
def validate_user(user, username_validation): if username_validation == USERNAME_VALIDATION_OPTIONS.disabled: return elif username_validation == USERNAME_VALIDATION_OPTIONS.email: Email('Invalid email address.').__call__(user) elif username_validation == USERNAME_VALIDATION_OPTIONS.principal: _validate_principal(user) elif len(user) > 32: raise ValidationError('Username is too long.') elif username_validation == USERNAME_VALIDATION_OPTIONS.useradd: _validate_user_useradd(user) elif username_validation == USERNAME_VALIDATION_OPTIONS.debian: _validate_user_debian(user) else: raise ValidationError('Invalid username validator.')
class UserSchema(ma.SQLAlchemyAutoSchema): class Meta: model = User load_only = [ "first_name", "last_name", "email", "password" ] load_instance = True email = ma.String(required=True, validate=[Length(min=4), Email()]) username = ma.String(required=True, validate=[Length(min=1)]) first_name = ma.String(required=True, validate=[Length(min=2)]) last_name = ma.String(required=True, validate=[Length(min=2)]) password = ma.String(required=True, validate=Length(min=6))
class UserModelSchema(ma.SQLAlchemySchema): email = fields.Str(required=True, validate=Email()) name = fields.Str(required=True, validate=[Length(min=3), Regexp(r'^[ A-Za-z]+$', error="Invalid Name")]) username = fields.Str(required=True, validate=Length(min=3)) password = fields.Str(required=True, validate=Length(min=8)) address = fields.Str(required=True, validate=Length(min=3)) state = fields.Str(required=True, validate=[Length(min=3), Regexp(r'^[ A-Za-z]+$', error="Invalid State")]) country = fields.Str(required=True, validate=[Length(min=3), Regexp(r'^[ A-Za-z]+$', error="Invalid Country")]) pan = fields.Str(required=True, validate=Length(min=8)) contactNo = fields.Str(required=True, validate=[Length(equal=10), Regexp(r'^[0-9]+$', error="Invalid Contact Number")]) dob = fields.Str(required=True, validate=Length(min=3)) account_type = fields.Str(required=True, validate=[Length(min=3), Regexp(r'^[ A-Za-z]+$', error="Invalid Account Type")]) class Meta: fields = ('email', 'name', 'username', 'password', 'address', 'state', 'country', 'pan', 'contactNo', 'dob', 'account_type')
class RoleSchema(BaseSchema): name = String(validate=Length(min=3)) email = String(validate=Email()) api_key = String(dump_only=True) type = String(dump_only=True) # foreign_id = String(dump_only=True) # is_admin = Boolean(dump_only=True) @post_dump def transient(self, data): pk = str(data.get('id')) data['links'] = {'self': url_for('roles_api.view', id=pk)} data['writeable'] = str(request.authz.id) == pk if not data['writeable']: data.pop('api_key', None) data.pop('email', None) return data
class SubmitSupportEnquiryRequest: email: str = field(metadata=dict(validate=Email())) phone: str message: str subject_type: str = field(metadata=dict(data_key='subjectType')) subject: str # Whether or not to send a recipe (email) to the user recipe: bool # Reference link/URL link: str = None # File upload file_name: str = field(default=None, metadata=dict(data_key='fileName')) file_source: str = field(default=None, metadata=dict(data_key='fileSource'))
def validate_user(user, username_validation, username_blacklist=None): if username_blacklist: if re.match(username_blacklist, user) is not None: raise ValidationError('Username contains invalid characters.') if username_validation == USERNAME_VALIDATION_OPTIONS.disabled: return elif username_validation == USERNAME_VALIDATION_OPTIONS.email: Email('Invalid email address.').__call__(user) elif username_validation == USERNAME_VALIDATION_OPTIONS.principal: _validate_principal(user) elif len(user) > 32: raise ValidationError('Username is too long.') elif username_validation == USERNAME_VALIDATION_OPTIONS.useradd: _validate_user_useradd(user) elif username_validation == USERNAME_VALIDATION_OPTIONS.debian: _validate_user_debian(user) else: raise ValidationError('Invalid username validator.')
class RoleSchema(Schema, DatedSchema): id = String(dump_only=True) name = String(validate=Length(min=3)) email = String(validate=Email()) api_key = String(dump_only=True) type = String(dump_only=True) foreign_id = String(dump_only=True) is_admin = Boolean(dump_only=True) @post_dump def transient(self, data): data['$uri'] = url_for('roles_api.view', id=data.get('id')) writeable = False if str(request.authz.id) == str(data.get('id')): writeable = True data['$writeable'] = writeable if not request.authz.is_admin and not writeable: data.pop('email') if not writeable: data.pop('api_key') return data
class LoginSchema(Schema): email = String(validate=Email(), required=True) password = String(validate=Length(min=3))
class RoleCodeCreateSchema(Schema): email = String(validate=Email(), required=True)
def test_generate_random_emails(): emails = generate_random_emails(2) assert len(emails) == 2 assert Email()(emails[0]) == emails[0]
class User_Schema(ma.SQLAlchemyAutoSchema): class Meta: model = User user_email = ma.String(required=True, validate=Email()) user_encrypted_password = ma.String(required=True, validate=Length(8))
class RoleInviteSchema(Schema, DatedSchema): email = String(validate=Email(), required=True)
from __future__ import absolute_import from marshmallow import Schema, fields, validates from marshmallow.validate import Email from .validates import application_name_validate, cluster_name_validate _email_validator = Email() class Clusters(Schema): application_name = fields.String( required=True, validate=application_name_validate, ) clusters = fields.List( fields.String(required=True, validate=cluster_name_validate)) class EventSubscribeSchema(Schema): service = fields.Dict() config = fields.Dict() switch = fields.Dict() service_info = fields.Dict() _clusters_schema = Clusters(strict=True) def _validate_clusters(self, value): for application_name, clusters in value.items(): self._clusters_schema.validate( dict(application_name=application_name, clusters=clusters))
class RoleCreateSchema(Schema, DatedSchema): email = String(validate=Email(), required=True) name = String() password = String(validate=Length(min=Role.PASSWORD_MIN_LENGTH), required=True) code = String(required=True)
class InviteRequestSchema(Schema): name = fields.String(required=True, validate=Length(min=3)) email = fields.String(required=True, validate=Email())
class LoginRequestSchema(Schema): email = fields.String(required=True, validate=Email()) password = fields.String(required=True, validate=Length(min=8, max=25))
class CreateStaffRequestSchema(Schema): fullname = fields.String(required=True, validate=Length(min=3)) email = fields.String(required=True, validate=Email()) password = fields.String(required=True, validate=Length(min=8, max=25))