Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# User Schemas 

2from src import ma 

3 

4from src.model import UserModel 

5from src.utils import SQLAlchemyAutoSchema, DTOSchema 

6 

7# Validations with Marshmallow 

8from marshmallow import fields 

9from marshmallow.validate import Regexp, Length, Email 

10 

11# Validations with Marshmallow 

12from marshmallow import fields 

13from marshmallow.validate import Regexp, Length, Email 

14 

15from src.utils import DTOSchema 

16 

17 

18class UserMeta: 

19 model = UserModel 

20 

21 

22class UserBase(SQLAlchemyAutoSchema): 

23 role = ma.Nested("RoleBase") 

24 

25 class Meta(UserMeta): 

26 fields = ("uuid", "email", "username", "preferences_defined", "role") 

27 

28 

29class UserObject(SQLAlchemyAutoSchema): 

30 groups = ma.Nested("GroupBase", many=True) 

31 invitations = ma.Nested("GroupBase", many=True) 

32 owned_groups = ma.Nested("GroupBase", many=True) 

33 

34 class Meta(UserMeta): 

35 fields = ("uuid", "email", "username", "preferences_defined", 

36 "groups", "invitations", "owned_groups") 

37 

38 

39class UserFullObject(SQLAlchemyAutoSchema): 

40 groups = ma.Nested("GroupBase", many=True) 

41 invitations = ma.Nested("GroupBase", many=True) 

42 owned_groups = ma.Nested("GroupBase", many=True) 

43 

44 liked_genres = ma.Nested("GenreBase", many=True) 

45 

46 linked_services = ma.Nested("ExternalBase", many=True) 

47 

48 meta_user_content = ma.Nested("MetaUserContentItem", many=True) 

49 

50 class Meta(UserMeta): 

51 fields = ("uuid", "email", "username", "preferences_defined", "groups", "invitations", 

52 "owned_groups", "liked_genres", "linked_services", "meta_user_content") 

53 

54 

55class UpdateUserDataSchema(DTOSchema): 

56 """ /auth/register [POST] 

57 /user/update [PATCH] 

58 

59 Parameters: 

60 - Email 

61 - Username (Str) 

62 - Password (Str) 

63 """ 

64 email = fields.Email(validate=[Length(min=5, max=64)]) 

65 username = fields.Str( 

66 validate=[ 

67 Length(min=4, max=15), 

68 Regexp( 

69 r"^([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)$", 

70 error="Invalid username!", 

71 ), 

72 ], 

73 ) 

74 password = fields.Str( 

75 validate=[ 

76 Length(min=8, max=128), 

77 Regexp( 

78 r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}", 

79 error="Password must contain at least minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character !" 

80 ), 

81 ], 

82 )