132 if form.is_valid(): |
132 if form.is_valid(): |
133 form_id = form.cleaned_data.get('id') |
133 form_id = form.cleaned_data.get('id') |
134 |
134 |
135 if form_id: |
135 if form_id: |
136 # email provided, so attempt to look up user by email |
136 # email provided, so attempt to look up user by email |
137 user = models.user.logic.getFromFields(email=form_id.email()) |
137 user = models.user.logic.getForFields({'id': form_id}, unique=True) |
138 |
138 |
139 if user: |
139 if user: |
140 lookup_message = ugettext_lazy('User found by email.') |
140 lookup_message = ugettext_lazy('User found by email.') |
141 else: |
141 else: |
142 email_error = ugettext_lazy('User with that email not found.') |
142 email_error = ugettext_lazy('User with that email not found.') |
232 if not validate.isLinkNameFormatValid(link_name): |
232 if not validate.isLinkNameFormatValid(link_name): |
233 raise forms.ValidationError("This link name is in wrong format.") |
233 raise forms.ValidationError("This link name is in wrong format.") |
234 |
234 |
235 key_name = self.data.get('key_name') |
235 key_name = self.data.get('key_name') |
236 user = models.user.logic.getFromKeyName(key_name) |
236 user = models.user.logic.getFromKeyName(key_name) |
237 |
237 |
238 if user and user.link_name != link_name: |
238 linkname_user_exist = id_user.getUserFromLinkName(link_name) |
|
239 if (user and user.link_name != link_name) and linkname_user_exist: |
239 raise forms.ValidationError("This link name is already in use.") |
240 raise forms.ValidationError("This link name is already in use.") |
240 |
241 |
241 return link_name |
242 return link_name |
242 |
243 |
243 def clean_id(self): |
244 def clean_id(self): |
244 form_id = users.User(email=self.cleaned_data.get('id')) |
245 form_id = users.User(email=self.cleaned_data.get('id')) |
245 if not id_user.isIdAvailable( |
246 if not id_user.isIdAvailable( |
246 form_id, existing_key_name=self.data.get('key_name')): |
247 form_id, existing_key_name=self.data.get('key_name')): |
247 raise forms.ValidationError("This account is already in use.") |
248 raise forms.ValidationError("This account is already in use.") |
|
249 if models.user.logic.isFormerId(form_id): |
|
250 raise forms.ValidationError("This account is invalid. " |
|
251 "It exists as former id.") |
248 return form_id |
252 return form_id |
249 |
253 |
250 |
254 |
251 DEF_SITE_USER_PROFILE_EDIT_TMPL = 'soc/user/edit.html' |
255 DEF_SITE_USER_PROFILE_EDIT_TMPL = 'soc/user/edit.html' |
252 DEF_CREATE_NEW_USER_MSG = ' You can create a new user by visiting' \ |
256 DEF_CREATE_NEW_USER_MSG = ' You can create a new user by visiting' \ |
396 return link_name |
400 return link_name |
397 |
401 |
398 def clean_id(self): |
402 def clean_id(self): |
399 new_email = self.cleaned_data.get('id') |
403 new_email = self.cleaned_data.get('id') |
400 form_id = users.User(email=new_email) |
404 form_id = users.User(email=new_email) |
401 if models.user.logic.getFromFields(email=form_id.email()): |
405 if models.user.logic.getForFields({'id': form_id}, unique=True): |
402 raise forms.ValidationError("This account is already in use.") |
406 raise forms.ValidationError("This account is already in use.") |
|
407 if models.user.logic.isFormerId(form_id): |
|
408 raise forms.ValidationError("This account is invalid. " |
|
409 "It exists as former id.") |
403 return form_id |
410 return form_id |
404 |
411 |
405 |
412 |
406 DEF_SITE_CREATE_USER_PROFILE_TMPL = 'soc/user/edit.html' |
413 DEF_SITE_CREATE_USER_PROFILE_TMPL = 'soc/user/edit.html' |
407 |
414 |