@@ -83,12 +83,29 @@ def __init__(self, id_type=IdentityTypes.adobeID, email=None, username=None, dom
8383 self .id_type = id_type
8484 self .email = None
8585 self .domain = domain
86+ if username is not None :
87+ if email and username .lower () == email .lower ():
88+ # ignore the username if it's the same as the email (policy default)
89+ username = None
90+ if domain :
91+ self .domain = domain
92+ elif id_type is not IdentityTypes .federatedID :
93+ raise ArgumentError ("Username must match email except for Federated ID" )
8694 if email is not None :
95+ if '@' not in email :
96+ raise ArgumentError ("Invalid email address: %s" % email )
8797 self .email = email
88- if self .domain is None :
98+ if not self .domain :
8999 atpos = email .index ('@' )
90100 self .domain = email [atpos + 1 :]
91- if id_type == IdentityTypes .adobeID :
101+ elif not username :
102+ raise ArgumentError ("No user identity specified." )
103+ elif not domain :
104+ raise ArgumentError ("Both username and domain must be specified" )
105+
106+ if username :
107+ Action .__init__ (self , user = username , domain = self .domain , ** kwargs )
108+ elif id_type == IdentityTypes .adobeID :
92109 # by default if two users have the same email address, the UMAPI server will prefer the matching
93110 # Federated or Enterprise ID user; so we use the undocumented option to prefer the AdobeID match
94111 Action .__init__ (self , user = email , useAdobeID = True , ** kwargs )
@@ -116,6 +133,8 @@ def create(self, first_name=None, last_name=None, country=None, email=None,
116133 raise ArgumentError ("You must specify email when creating a user" )
117134 elif self .email is None :
118135 self .email = email
136+ elif self .email .lower () != email .lower ():
137+ raise ArgumentError ("Specified email (%s) doesn't match user's email (%s)" % (email , self .email ))
119138 create_params ["email" ] = self .email
120139 if on_conflict in IfAlreadyExistsOptions .__members__ :
121140 on_conflict = IfAlreadyExistsOptions [on_conflict ]
@@ -145,6 +164,8 @@ def update(self, email=None, username=None, first_name=None, last_name=None, cou
145164 :param country: new country for this user
146165 :return: the User, so you can do User(...).update(...).add_to_groups(...)
147166 """
167+ if self .id_type != IdentityTypes .federatedID and email != username :
168+ raise ArgumentError ("Username and email address must match except for Federated ID types" )
148169 updates = {}
149170 for k , v in six .iteritems (dict (email = email , username = username ,
150171 firstname = first_name , lastname = last_name ,
0 commit comments