Always normalize accounts, before even storing them
authorSverre Rabbelier <srabbelier@gmail.com>
Thu, 26 Feb 2009 16:55:23 +0000
changeset 1522 983b126f5aca
parent 1521 bb086732bf7f
child 1523 1e6ac8f61a97
Always normalize accounts, before even storing them Patch by: Sverre Rabbelier
app/soc/logic/cleaning.py
app/soc/logic/models/user.py
--- a/app/soc/logic/cleaning.py	Thu Feb 26 16:54:44 2009 +0000
+++ b/app/soc/logic/cleaning.py	Thu Feb 26 16:55:23 2009 +0000
@@ -222,12 +222,9 @@
 
   @check_field_is_empty(field_name)
   def wrapped(self):
-    email_adress = self.cleaned_data.get(field_name).lower()
+    email_adress = self.cleaned_data[field_name]
+    return users.User(email_adress)
 
-    # get the user account for this email
-    user_account = users.User(email_adress)
-
-    return user_account
   return wrapped
 
 
--- a/app/soc/logic/models/user.py	Thu Feb 26 16:54:44 2009 +0000
+++ b/app/soc/logic/models/user.py	Thu Feb 26 16:55:23 2009 +0000
@@ -146,6 +146,17 @@
 
     return ['link_id']
 
+  def _createField(self, entity_properties, name):
+    """Normalize the account before storing it.
+    """
+
+    value = entity_properties[name]
+
+    if (name == 'account'):
+      # normalize all accounts before doing anything with the value
+      value = accounts.normalizeAccount(value)
+      entity_properties[name] = value
+
   def _updateField(self, entity, entity_properties, name):
     """Special case logic for account.
 
@@ -174,15 +185,12 @@
       sidebar.flush(entity.account)
 
     if (name == 'account'):
-      if (str(entity.account) != str(value)):
+      # normalize all accounts before doing anything with the value
+      value = accounts.normalizeAccount(value)
+      entity_properties[name] = value
+
+      if entity.account != value:
         entity.former_accounts.append(entity.account)
-      elif entity.account != value:
-        # this occurs when the account ends in the auth domain, e.g.:
-        # if the auth domain is "example.com", then the following would
-        # would put us here:
-        # entity.account = users.User('foo@example.com')
-        # value = 'foo'
-        return False
 
     return True