Changeset - 02bdf2f296ff
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 15 years ago 2010-11-18 23:07:04
marcin@python-works.com
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
4 files changed with 67 insertions and 18 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/celerylib/tasks.py
Show inline comments
 
@@ -246,25 +246,25 @@ def send_email(recipients, subject, body
 
    :param recipients: list of recipients, it this is empty the defined email
 
        address from field 'email_to' is used instead
 
    :param subject: subject of the mail
 
    :param body: body of the mail
 
    """
 
    log = send_email.get_logger()
 
    email_config = dict(config.items('DEFAULT'))
 

	
 
    if not recipients:
 
        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')
 
    passwd = email_config.get('smtp_password')
 
    mail_server = email_config.get('smtp_server')
 
    mail_port = email_config.get('smtp_port')
 
    tls = str2bool(email_config.get('smtp_use_tls'))
 
    ssl = str2bool(email_config.get('smtp_use_ssl'))
 

	
 
    try:
 
        m = SmtpMailer(mail_from, user, passwd, mail_server,
 
                       mail_port, ssl, tls)
rhodecode/model/forms.py
Show inline comments
 
@@ -67,26 +67,52 @@ def ValidUsername(edit, old_data):
 
                old_un = UserModel().get(old_data.get('user_id')).username
 

	
 
            if old_un != value or not edit:
 
                if UserModel().get_by_username(value, cache=False):
 
                    raise formencode.Invalid(_('This username already exists') ,
 
                                             value, state)
 

	
 
    return _ValidUsername
 

	
 
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 = {
 
            'invalid_password':_('invalid password'),
 
            'invalid_login':_('invalid user name'),
 
            'disabled_account':_('Your account is disabled')
 

	
 
            }
 
    #error mapping
 
    e_dict = {'username':messages['invalid_login'],
 
              'password':messages['invalid_password']}
 
    e_dict_disable = {'username':messages['disabled_account']}
 
@@ -272,36 +298,52 @@ class LoginForm(formencode.Schema):
 
                                )
 

	
 

	
 
    #chained validators have access to all data
 
    chained_validators = [ValidAuth]
 

	
 
def UserForm(edit=False, old_data={}):
 
    class _UserForm(formencode.Schema):
 
        allow_extra_fields = True
 
        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):
 
        allow_extra_fields = True
 
        filter_extra_fields = True
 
        email = All(ValidSystemEmail(), Email(not_empty=True))
 
    return _PasswordResetForm
 

	
 
def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
 
    class _RepoForm(formencode.Schema):
 
        allow_extra_fields = True
 
        filter_extra_fields = False
rhodecode/public/css/style.css
Show inline comments
 
@@ -1318,52 +1318,50 @@ text-align:right;
 
margin:0;
 
padding:10px 0 0;
 
}
 
 
#login div.form div.links {
 
clear:both;
 
overflow:hidden;
 
margin:10px 0 0;
 
padding:0 0 2px;
 
}
 
 
#register div.title {
 
width:420px;
 
clear:both;
 
overflow:hidden;
 
position:relative;
 
background:#003367 url("../images/header_inner.png") repeat-x;
 
margin:0 auto;
 
padding:0;
 
}
 
 
#register div.inner {
 
width:380px;
 
background:#FFF;
 
border-top:none;
 
border-bottom:none;
 
margin:0 auto;
 
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;
 
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;
 
border-right:1px solid #eaeaea;
 
border-bottom:1px solid #eaeaea;
 
color:#000;
 
font-family:Lucida Grande, Verdana, Lucida Sans Regular, Lucida Sans Unicode, Arial, sans-serif;
 
font-size:11px;
 
margin:0;
 
padding:7px 7px 6px;
 
}
 
 
@@ -2226,25 +2224,25 @@ border-bottom:1px solid #c4c4c4;
 
color:#4A4A4A;
 
font-weight:700;
 
margin:0;
 
padding:6px 8px;
 
}
 
 
#content div.box div.pagination ul.pager li.disabled,#content div.box div.pagination-wh a.disabled {
 
color:#B4B4B4;
 
padding:6px;
 
}
 
 
#login,#register {
 
width:420px;
 
width:520px;
 
margin:10% auto 0;
 
padding:0;
 
}
 
 
#login div.color,#register div.color {
 
clear:both;
 
overflow:hidden;
 
background:#FFF;
 
margin:10px auto 0;
 
padding:3px 3px 3px 0;
 
}
 
rhodecode/templates/register.html
Show inline comments
 
@@ -6,73 +6,82 @@
 
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
 
        <link rel="icon" href="/images/hgicon.png" type="image/png" />
 
        <meta name="robots" content="index, nofollow"/>
 
            
 
        <!-- stylesheets -->
 
        <link rel="stylesheet" type="text/css" href="/css/style.css" media="screen" />
 

	
 
    </head>
 
    <body>
 
		<div id="register">
 
			
 
			<div class="title top-left-rounded-corner top-right-rounded-corner">
 
				<h5>${_('Sign Up to rhodecode')}</h5>
 
				<h5>${_('Sign Up to RhodeCode')}</h5>
 
			</div>
 
			<div class="inner">
 
			    ${h.form(url('register'))}
 
			    <div class="form">
 
			        <!-- fields -->
 
			        <div class="fields">
 
			             <div class="field">
 
			                <div class="label">
 
			                    <label for="username">${_('Username')}:</label>
 
			                </div>
 
			                <div class="input">
 
			                    ${h.text('username')}
 
			                    ${h.text('username',class_="medium")}
 
			                </div>
 
			             </div>
 
			            
 
			             <div class="field">
 
			                <div class="label">
 
			                    <label for="password">${_('New Password')}:</label>
 
			                    <label for="password">${_('Password')}:</label>
 
			                </div>
 
			                <div class="input">
 
			                    ${h.password('password')}
 
			                    ${h.password('password',class_="medium")}
 
			                </div>
 
			             </div>
 
			            
 
                         
 
                         <div class="field">
 
                            <div class="label">
 
                                <label for="password">${_('Re-enter password')}:</label>
 
                            </div>
 
                            <div class="input">
 
                                ${h.password('password_confirmation',class_="medium")}
 
                            </div>
 
                         </div>
 
                         			            
 
			             <div class="field">
 
			                <div class="label">
 
			                    <label for="name">${_('First Name')}:</label>
 
			                </div>
 
			                <div class="input">
 
			                    ${h.text('name')}
 
			                    ${h.text('name',class_="medium")}
 
			                </div>
 
			             </div>
 
			            
 
			             <div class="field">
 
			                <div class="label">
 
			                    <label for="lastname">${_('Last Name')}:</label>
 
			                </div>
 
			                <div class="input">
 
			                    ${h.text('lastname')}
 
			                    ${h.text('lastname',class_="medium")}
 
			                </div>
 
			             </div>
 
			            
 
			             <div class="field">
 
			                <div class="label">
 
			                    <label for="email">${_('Email')}:</label>
 
			                </div>
 
			                <div class="input">
 
			                    ${h.text('email')}
 
			                    ${h.text('email',class_="medium")}
 
			                </div>
 
			             </div>
 
			                        
 
			            <div class="buttons">
 
				            <div class="nohighlight">
 
				              ${h.submit('sign_up','Sign Up',class_="ui-button ui-widget ui-state-default ui-corner-all")}
 
				              %if c.auto_active:
 
							  	<div class="activation_msg">${_('Your account will be activated right after registration')}</div>
 
							  %else:
 
							  	<div class="activation_msg">${_('Your account must wait for activation by administrator')}</div>
 
							  %endif
 
				            </div>
0 comments (0 inline, 0 general)