# HG changeset patch # User Marcin Kuzminski # Date 2010-11-18 22:07:04 # Node ID 02bdf2f296ff76db8e35aa5e6e6c54b32ac20e4a # Parent 74975001a1aff2017db9272d267184dfb153c247 fixes #69 password confirmation for register dialog. Fixes appcrash when using some special characters in register field fixes app crash when no email config is enabled diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py --- a/rhodecode/lib/celerylib/tasks.py +++ b/rhodecode/lib/celerylib/tasks.py @@ -255,7 +255,7 @@ def send_email(recipients, subject, body recipients = [email_config.get('email_to')] def str2bool(v): - return v.lower() in ["yes", "true", "t", "1"] + return v.lower() in ["yes", "true", "t", "1"] if v else None mail_from = email_config.get('app_email_from') user = email_config.get('smtp_username') diff --git a/rhodecode/model/forms.py b/rhodecode/model/forms.py --- a/rhodecode/model/forms.py +++ b/rhodecode/model/forms.py @@ -76,8 +76,34 @@ def ValidUsername(edit, old_data): class ValidPassword(formencode.validators.FancyValidator): def to_python(self, value, state): + if value: - return get_crypt_password(value) + + if value.get('password'): + try: + value['password'] = get_crypt_password(value['password']) + except UnicodeEncodeError: + e_dict = {'password':_('Invalid characters in password')} + raise formencode.Invalid('', value, state, error_dict=e_dict) + + if value.get('password_confirmation'): + try: + value['password_confirmation'] = \ + get_crypt_password(value['password_confirmation']) + except UnicodeEncodeError: + e_dict = {'password_confirmation':_('Invalid characters in password')} + raise formencode.Invalid('', value, state, error_dict=e_dict) + + return value + +class ValidPasswordsMatch(formencode.validators.FancyValidator): + + def validate_python(self, value, state): + + if value['password'] != value['password_confirmation']: + e_dict = {'password_confirmation': + _('Password do not match')} + raise formencode.Invalid('', value, state, error_dict=e_dict) class ValidAuth(formencode.validators.FancyValidator): messages = { @@ -281,18 +307,34 @@ def UserForm(edit=False, old_data={}): filter_extra_fields = True username = All(UnicodeString(strip=True, min=1, not_empty=True), ValidUsername(edit, old_data)) if edit: - new_password = All(UnicodeString(strip=True, min=6, not_empty=False), ValidPassword) + new_password = All(UnicodeString(strip=True, min=6, not_empty=False)) admin = StringBoolean(if_missing=False) else: - password = All(UnicodeString(strip=True, min=6, not_empty=True), ValidPassword) + password = All(UnicodeString(strip=True, min=6, not_empty=True)) active = StringBoolean(if_missing=False) name = UnicodeString(strip=True, min=1, not_empty=True) lastname = UnicodeString(strip=True, min=1, not_empty=True) email = All(Email(not_empty=True), UniqSystemEmail(old_data)) + chained_validators = [ValidPassword] + return _UserForm -RegisterForm = UserForm +def RegisterForm(edit=False, old_data={}): + class _RegisterForm(formencode.Schema): + allow_extra_fields = True + filter_extra_fields = True + username = All(ValidUsername(edit, old_data), UnicodeString(strip=True, min=1, not_empty=True)) + password = All(UnicodeString(strip=True, min=6, not_empty=True)) + password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True)) + active = StringBoolean(if_missing=False) + name = UnicodeString(strip=True, min=1, not_empty=True) + lastname = UnicodeString(strip=True, min=1, not_empty=True) + email = All(Email(not_empty=True), UniqSystemEmail(old_data)) + + chained_validators = [ValidPasswordsMatch, ValidPassword] + + return _RegisterForm def PasswordResetForm(): class _PasswordResetForm(formencode.Schema): diff --git a/rhodecode/public/css/style.css b/rhodecode/public/css/style.css --- a/rhodecode/public/css/style.css +++ b/rhodecode/public/css/style.css @@ -1327,7 +1327,6 @@ padding:0 0 2px; } #register div.title { -width:420px; clear:both; overflow:hidden; position:relative; @@ -1337,7 +1336,6 @@ padding:0; } #register div.inner { -width:380px; background:#FFF; border-top:none; border-bottom:none; @@ -1346,7 +1344,7 @@ padding:20px; } #register div.form div.fields div.field div.label { -width:100px; +width:135px; float:left; text-align:right; margin:2px 10px 0 0; @@ -1354,7 +1352,7 @@ padding:5px 0 0 5px; } #register div.form div.fields div.field div.input input { -width:245px; +width:300px; background:#FFF; border-top:1px solid #b3b3b3; border-left:1px solid #b3b3b3; @@ -2235,7 +2233,7 @@ padding:6px; } #login,#register { -width:420px; +width:520px; margin:10% auto 0; padding:0; } diff --git a/rhodecode/templates/register.html b/rhodecode/templates/register.html --- a/rhodecode/templates/register.html +++ b/rhodecode/templates/register.html @@ -15,7 +15,7 @@
-
${_('Sign Up to rhodecode')}
+
${_('Sign Up to RhodeCode')}
${h.form(url('register'))} @@ -27,25 +27,34 @@
- ${h.text('username')} + ${h.text('username',class_="medium")}
- +
- ${h.password('password')} + ${h.password('password',class_="medium")}
- + +
+
+ +
+
+ ${h.password('password_confirmation',class_="medium")} +
+
+
- ${h.text('name')} + ${h.text('name',class_="medium")}
@@ -54,7 +63,7 @@
- ${h.text('lastname')} + ${h.text('lastname',class_="medium")}
@@ -63,7 +72,7 @@
- ${h.text('email')} + ${h.text('email',class_="medium")}