inital
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""Schemas package."""
|
||||
from app.schemas.user_schema import UserSchema, UserUpdateSchema, ChangePasswordSchema
|
||||
from app.schemas.auth_schema import (
|
||||
RegisterSchema,
|
||||
LoginSchema,
|
||||
RefreshTokenSchema,
|
||||
ForgotPasswordSchema,
|
||||
ResetPasswordSchema,
|
||||
)
|
||||
from app.schemas.organization_schema import (
|
||||
OrganizationSchema,
|
||||
OrganizationCreateSchema,
|
||||
OrganizationUpdateSchema,
|
||||
OrganizationMemberSchema,
|
||||
InviteMemberSchema,
|
||||
UpdateMemberRoleSchema,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"UserSchema",
|
||||
"UserUpdateSchema",
|
||||
"ChangePasswordSchema",
|
||||
"RegisterSchema",
|
||||
"LoginSchema",
|
||||
"RefreshTokenSchema",
|
||||
"ForgotPasswordSchema",
|
||||
"ResetPasswordSchema",
|
||||
"OrganizationSchema",
|
||||
"OrganizationCreateSchema",
|
||||
"OrganizationUpdateSchema",
|
||||
"OrganizationMemberSchema",
|
||||
"InviteMemberSchema",
|
||||
"UpdateMemberRoleSchema",
|
||||
]
|
||||
@@ -0,0 +1,57 @@
|
||||
"""Authentication schemas for validation."""
|
||||
from marshmallow import Schema, fields, validate, validates_schema, ValidationError
|
||||
|
||||
|
||||
class RegisterSchema(Schema):
|
||||
"""Schema for user registration."""
|
||||
|
||||
email = fields.Email(required=True)
|
||||
password = fields.Str(
|
||||
required=True,
|
||||
validate=validate.Length(min=8, max=128),
|
||||
)
|
||||
password_confirm = fields.Str(required=True)
|
||||
full_name = fields.Str(allow_none=True, validate=validate.Length(max=255))
|
||||
|
||||
@validates_schema
|
||||
def validate_passwords_match(self, data, **kwargs):
|
||||
"""Validate that passwords match."""
|
||||
if data.get("password") != data.get("password_confirm"):
|
||||
raise ValidationError("Passwords do not match", field_name="password_confirm")
|
||||
|
||||
|
||||
class LoginSchema(Schema):
|
||||
"""Schema for user login."""
|
||||
|
||||
email = fields.Email(required=True)
|
||||
password = fields.Str(required=True, validate=validate.Length(min=1))
|
||||
remember_me = fields.Bool(missing=False)
|
||||
|
||||
|
||||
class RefreshTokenSchema(Schema):
|
||||
"""Schema for token refresh."""
|
||||
|
||||
refresh_token = fields.Str(required=True)
|
||||
|
||||
|
||||
class ForgotPasswordSchema(Schema):
|
||||
"""Schema for forgot password request."""
|
||||
|
||||
email = fields.Email(required=True)
|
||||
|
||||
|
||||
class ResetPasswordSchema(Schema):
|
||||
"""Schema for password reset."""
|
||||
|
||||
token = fields.Str(required=True)
|
||||
password = fields.Str(
|
||||
required=True,
|
||||
validate=validate.Length(min=8, max=128),
|
||||
)
|
||||
password_confirm = fields.Str(required=True)
|
||||
|
||||
@validates_schema
|
||||
def validate_passwords_match(self, data, **kwargs):
|
||||
"""Validate that passwords match."""
|
||||
if data.get("password") != data.get("password_confirm"):
|
||||
raise ValidationError("Passwords do not match", field_name="password_confirm")
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Organization schemas for validation."""
|
||||
from marshmallow import Schema, fields, validate
|
||||
|
||||
|
||||
class OrganizationSchema(Schema):
|
||||
"""Schema for Organization model."""
|
||||
|
||||
id = fields.Str(dump_only=True)
|
||||
name = fields.Str(required=True, validate=validate.Length(min=1, max=255))
|
||||
slug = fields.Str(required=True, validate=validate.Length(min=1, max=255))
|
||||
description = fields.Str(allow_none=True)
|
||||
logo_url = fields.Url(allow_none=True, validate=validate.Length(max=512))
|
||||
is_active = fields.Bool(dump_only=True)
|
||||
created_at = fields.DateTime(dump_only=True)
|
||||
updated_at = fields.DateTime(dump_only=True)
|
||||
|
||||
|
||||
class OrganizationCreateSchema(Schema):
|
||||
"""Schema for creating an organization."""
|
||||
|
||||
name = fields.Str(required=True, validate=validate.Length(min=1, max=255))
|
||||
slug = fields.Str(required=True, validate=validate.Length(min=1, max=255))
|
||||
description = fields.Str(allow_none=True)
|
||||
logo_url = fields.Url(allow_none=True, validate=validate.Length(max=512))
|
||||
|
||||
|
||||
class OrganizationUpdateSchema(Schema):
|
||||
"""Schema for updating an organization."""
|
||||
|
||||
name = fields.Str(validate=validate.Length(min=1, max=255))
|
||||
description = fields.Str(allow_none=True)
|
||||
logo_url = fields.Url(allow_none=True, validate=validate.Length(max=512))
|
||||
|
||||
|
||||
class OrganizationMemberSchema(Schema):
|
||||
"""Schema for Organization Member."""
|
||||
|
||||
id = fields.Str(dump_only=True)
|
||||
user_id = fields.Str(dump_only=True)
|
||||
organization_id = fields.Str(dump_only=True)
|
||||
role = fields.Str(dump_only=True)
|
||||
joined_at = fields.DateTime(dump_only=True)
|
||||
created_at = fields.DateTime(dump_only=True)
|
||||
|
||||
|
||||
class InviteMemberSchema(Schema):
|
||||
"""Schema for inviting a member to an organization."""
|
||||
|
||||
email = fields.Email(required=True)
|
||||
role = fields.Str(
|
||||
required=True,
|
||||
validate=validate.OneOf(["owner", "admin", "member", "guest"])
|
||||
)
|
||||
|
||||
|
||||
class UpdateMemberRoleSchema(Schema):
|
||||
"""Schema for updating a member's role."""
|
||||
|
||||
role = fields.Str(
|
||||
required=True,
|
||||
validate=validate.OneOf(["owner", "admin", "member", "guest"])
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
"""User schemas for validation and serialization."""
|
||||
from marshmallow import Schema, fields, validate, validates, ValidationError
|
||||
from app.utils.constants import UserStatus
|
||||
|
||||
|
||||
class UserSchema(Schema):
|
||||
"""Schema for User model."""
|
||||
|
||||
id = fields.Str(dump_only=True)
|
||||
email = fields.Email(required=True)
|
||||
email_verified = fields.Bool(dump_only=True)
|
||||
full_name = fields.Str(allow_none=True, validate=validate.Length(max=255))
|
||||
avatar_url = fields.Url(allow_none=True, validate=validate.Length(max=512))
|
||||
status = fields.Str(dump_only=True)
|
||||
last_login_at = fields.DateTime(dump_only=True)
|
||||
created_at = fields.DateTime(dump_only=True)
|
||||
updated_at = fields.DateTime(dump_only=True)
|
||||
|
||||
|
||||
class UserUpdateSchema(Schema):
|
||||
"""Schema for updating user profile."""
|
||||
|
||||
full_name = fields.Str(allow_none=True, validate=validate.Length(max=255))
|
||||
avatar_url = fields.Url(allow_none=True, validate=validate.Length(max=512))
|
||||
|
||||
|
||||
class ChangePasswordSchema(Schema):
|
||||
"""Schema for changing password."""
|
||||
|
||||
current_password = fields.Str(required=True, validate=validate.Length(min=1))
|
||||
new_password = fields.Str(
|
||||
required=True,
|
||||
validate=validate.Length(min=8, max=128),
|
||||
)
|
||||
new_password_confirm = fields.Str(required=True)
|
||||
|
||||
@validates("new_password")
|
||||
def validate_password_strength(self, value):
|
||||
"""Validate password strength."""
|
||||
if len(value) < 8:
|
||||
raise ValidationError("Password must be at least 8 characters long")
|
||||
if not any(char.isdigit() for char in value):
|
||||
raise ValidationError("Password must contain at least one digit")
|
||||
if not any(char.isupper() for char in value):
|
||||
raise ValidationError("Password must contain at least one uppercase letter")
|
||||
if not any(char.islower() for char in value):
|
||||
raise ValidationError("Password must contain at least one lowercase letter")
|
||||
Reference in New Issue
Block a user