File tree Expand file tree Collapse file tree
membersuite_api_client/security Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,11 +37,31 @@ def __str__(self):
3737 owner = self .owner ,
3838 session_id = self .session_id ))
3939
40- def get_username (self ):
40+ def generate_username (self ):
4141 """Return a username suitable for storing in auth.User.username.
4242
43+ Has to be <= 30 characters long. (Until we drop support for
44+ Django 1.4, after which we can define a custom User model with
45+ a larger username field.)
46+
47+ We want to incorporate the membersuite_id in the username.
48+ Those look like this:
49+
50+ 00000000-0032-c842-a28a-0b3c8b856f80
51+
52+ That's 36 characters, too long for username. Making the
53+ assumption that those leading zeroes will always be there in
54+ every ID. Since they're not needed to generate a unique
55+ value, they can go.
56+
57+ After chomping the zeroes, we're at 27 characters, so we
58+ insert "ms-" in the front.
59+
4360 """
44- return "_membersuite_id_{}" .format (self .membersuite_id )
61+ assert self .membersuite_id .startswith ("00000000-" )
62+ username = self .membersuite_id .replace ("00000000-" , '' )
63+ username = "ms-" + username
64+ return username
4565
4666 def get_individual (self , client ):
4767 """Return the Individual that owns this PortalUser.
You can’t perform that action at this time.
0 commit comments