Show More
@@ -107,7 +107,9 b' def authfunc(environ, username, password' | |||||
107 | #since ldap is searching in case insensitive check if this user is still |
|
107 | #since ldap is searching in case insensitive check if this user is still | |
108 | #not in our system |
|
108 | #not in our system | |
109 | username = username.lower() |
|
109 | username = username.lower() | |
110 |
|
|
110 | user_obj = user_model.get_by_username(username, cache=False, | |
|
111 | case_insensitive=True) | |||
|
112 | if user_obj is not None: | |||
111 | return False |
|
113 | return False | |
112 |
|
114 | |||
113 | from rhodecode.model.settings import SettingsModel |
|
115 | from rhodecode.model.settings import SettingsModel |
@@ -67,7 +67,8 b' def ValidUsername(edit, old_data):' | |||||
67 | old_un = UserModel().get(old_data.get('user_id')).username |
|
67 | old_un = UserModel().get(old_data.get('user_id')).username | |
68 |
|
68 | |||
69 | if old_un != value or not edit: |
|
69 | if old_un != value or not edit: | |
70 |
if UserModel().get_by_username(value |
|
70 | if UserModel().get_by_username(value, cache=False, | |
|
71 | case_insensitive=True): | |||
71 | raise formencode.Invalid(_('This username already exists') , |
|
72 | raise formencode.Invalid(_('This username already exists') , | |
72 | value, state) |
|
73 | value, state) | |
73 |
|
74 | |||
@@ -183,7 +184,8 b' def ValidForkType(old_data):' | |||||
183 |
|
184 | |||
184 | def to_python(self, value, state): |
|
185 | def to_python(self, value, state): | |
185 | if old_data['repo_type'] != value: |
|
186 | if old_data['repo_type'] != value: | |
186 |
raise formencode.Invalid(_('Fork have to be the same type as original'), |
|
187 | raise formencode.Invalid(_('Fork have to be the same type as original'), | |
|
188 | value, state) | |||
187 | return value |
|
189 | return value | |
188 | return _ValidForkType |
|
190 | return _ValidForkType | |
189 |
|
191 | |||
@@ -220,7 +222,8 b' class ValidPerms(formencode.validators.F' | |||||
220 | except Exception: |
|
222 | except Exception: | |
221 | msg = self.message('perm_new_user_name', |
|
223 | msg = self.message('perm_new_user_name', | |
222 | state=State_obj) |
|
224 | state=State_obj) | |
223 |
raise formencode.Invalid(msg, value, state, |
|
225 | raise formencode.Invalid(msg, value, state, | |
|
226 | error_dict={'perm_new_user_name':msg}) | |||
224 | return value |
|
227 | return value | |
225 |
|
228 | |||
226 | class ValidSettings(formencode.validators.FancyValidator): |
|
229 | class ValidSettings(formencode.validators.FancyValidator): | |
@@ -316,7 +319,8 b' def UserForm(edit=False, old_data={}):' | |||||
316 | class _UserForm(formencode.Schema): |
|
319 | class _UserForm(formencode.Schema): | |
317 | allow_extra_fields = True |
|
320 | allow_extra_fields = True | |
318 | filter_extra_fields = True |
|
321 | filter_extra_fields = True | |
319 |
username = All(UnicodeString(strip=True, min=1, not_empty=True), |
|
322 | username = All(UnicodeString(strip=True, min=1, not_empty=True), | |
|
323 | ValidUsername(edit, old_data)) | |||
320 | if edit: |
|
324 | if edit: | |
321 | new_password = All(UnicodeString(strip=True, min=6, not_empty=False)) |
|
325 | new_password = All(UnicodeString(strip=True, min=6, not_empty=False)) | |
322 | admin = StringBoolean(if_missing=False) |
|
326 | admin = StringBoolean(if_missing=False) | |
@@ -335,7 +339,8 b' def RegisterForm(edit=False, old_data={}' | |||||
335 | class _RegisterForm(formencode.Schema): |
|
339 | class _RegisterForm(formencode.Schema): | |
336 | allow_extra_fields = True |
|
340 | allow_extra_fields = True | |
337 | filter_extra_fields = True |
|
341 | filter_extra_fields = True | |
338 |
username = All(ValidUsername(edit, old_data), |
|
342 | username = All(ValidUsername(edit, old_data), | |
|
343 | UnicodeString(strip=True, min=1, not_empty=True)) | |||
339 | password = All(UnicodeString(strip=True, min=6, not_empty=True)) |
|
344 | password = All(UnicodeString(strip=True, min=6, not_empty=True)) | |
340 | password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True)) |
|
345 | password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True)) | |
341 | active = StringBoolean(if_missing=False) |
|
346 | active = StringBoolean(if_missing=False) | |
@@ -358,7 +363,8 b' def RepoForm(edit=False, old_data={}, su' | |||||
358 | class _RepoForm(formencode.Schema): |
|
363 | class _RepoForm(formencode.Schema): | |
359 | allow_extra_fields = True |
|
364 | allow_extra_fields = True | |
360 | filter_extra_fields = False |
|
365 | filter_extra_fields = False | |
361 |
repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), |
|
366 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), | |
|
367 | ValidRepoName(edit, old_data)) | |||
362 | description = UnicodeString(strip=True, min=1, not_empty=True) |
|
368 | description = UnicodeString(strip=True, min=1, not_empty=True) | |
363 | private = StringBoolean(if_missing=False) |
|
369 | private = StringBoolean(if_missing=False) | |
364 | repo_type = OneOf(supported_backends) |
|
370 | repo_type = OneOf(supported_backends) | |
@@ -372,7 +378,8 b' def RepoForkForm(edit=False, old_data={}' | |||||
372 | class _RepoForkForm(formencode.Schema): |
|
378 | class _RepoForkForm(formencode.Schema): | |
373 | allow_extra_fields = True |
|
379 | allow_extra_fields = True | |
374 | filter_extra_fields = False |
|
380 | filter_extra_fields = False | |
375 |
fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), |
|
381 | fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), | |
|
382 | ValidRepoName(edit, old_data)) | |||
376 | description = UnicodeString(strip=True, min=1, not_empty=True) |
|
383 | description = UnicodeString(strip=True, min=1, not_empty=True) | |
377 | private = StringBoolean(if_missing=False) |
|
384 | private = StringBoolean(if_missing=False) | |
378 | repo_type = All(ValidForkType(old_data), OneOf(supported_backends)) |
|
385 | repo_type = All(ValidForkType(old_data), OneOf(supported_backends)) | |
@@ -382,7 +389,8 b' def RepoSettingsForm(edit=False, old_dat' | |||||
382 | class _RepoForm(formencode.Schema): |
|
389 | class _RepoForm(formencode.Schema): | |
383 | allow_extra_fields = True |
|
390 | allow_extra_fields = True | |
384 | filter_extra_fields = False |
|
391 | filter_extra_fields = False | |
385 |
repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), |
|
392 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), | |
|
393 | ValidRepoName(edit, old_data)) | |||
386 | description = UnicodeString(strip=True, min=1, not_empty=True) |
|
394 | description = UnicodeString(strip=True, min=1, not_empty=True) | |
387 | private = StringBoolean(if_missing=False) |
|
395 | private = StringBoolean(if_missing=False) | |
388 |
|
396 |
@@ -48,9 +48,13 b' class UserModel(object):' | |||||
48 | return user.get(user_id) |
|
48 | return user.get(user_id) | |
49 |
|
49 | |||
50 |
|
50 | |||
51 | def get_by_username(self, username, cache=False): |
|
51 | def get_by_username(self, username, cache=False, case_insensitive=False): | |
52 | user = self.sa.query(User)\ |
|
52 | ||
53 | .filter(User.username == username) |
|
53 | if case_insensitive: | |
|
54 | user = self.sa.query(User).filter(User.username.ilike(username)) | |||
|
55 | else: | |||
|
56 | user = self.sa.query(User)\ | |||
|
57 | .filter(User.username == username) | |||
54 | if cache: |
|
58 | if cache: | |
55 | user = user.options(FromCache("sql_cache_short", |
|
59 | user = user.options(FromCache("sql_cache_short", | |
56 | "get_user_%s" % username)) |
|
60 | "get_user_%s" % username)) |
General Comments 0
You need to be logged in to leave comments.
Login now