Merge branch 'master' of ssh://git.fedorahosted.org/git/fedora-infrastructure

This commit is contained in:
Ricky Zhou (周家杰) 2008-03-06 17:24:38 -05:00
commit d42c1ca9f5
3 changed files with 32 additions and 5 deletions

View file

@ -8,7 +8,7 @@
</head>
<body>
<h2>${_('Edit Account (%s)') % target.username}</h2>
<form action="${tg.url('/user/save/%s' % target.username)}" method="post">
<form action="${tg.url('/user/save/%s' % target.username)}" method="post" enctype="multipart/form-data">
<div class="field">
<label for="human_name">${_('Human Name')}:</label>
<input type="text" id="human_name" name="human_name" value="${target.human_name}" />
@ -41,7 +41,8 @@
</div>
<div class="field">
<label for="ssh_key">${_('Public SSH Key')}:</label>
<textarea id="ssh_key" name="ssh_key">${target.ssh_key}</textarea>
<!--<textarea id="ssh_key" rows='3' cols='50' name="ssh_key">${target.ssh_key}</textarea>-->
<input type="file" name="ssh_key" id="ssh_key"/>
<script type="text/javascript">var hb19 = new HelpBalloon({dataURL: '${tg.url('/help/get_help/user_ssh_key')}'});</script>
</div>
<div class="field">

View file

@ -22,7 +22,7 @@
<py:if test="personal"><dt>${_('Telephone Number:')}</dt><dd>${person.telephone}&nbsp;</dd></py:if>
<py:if test="personal"><dt>${_('Postal Address:')}</dt><dd>${person.postal_address}&nbsp;</dd></py:if>
<py:if test="personal"><dt>${_('Public SSH Key:')}</dt>
<dd py:if="person.ssh_key">title="${person.ssh_key}">${person.ssh_key[:10]}&nbsp;</dd>
<dd py:if="person.ssh_key" title="${person.ssh_key}">${person.ssh_key[:20]}....&nbsp;</dd>
<dd py:if="not person.ssh_key">No ssh key provided&nbsp;</dd>
</py:if>
<dt>${_('Comments:')}</dt><dd>${person.comments}&nbsp;</dd>

View file

@ -54,6 +54,25 @@ class UnknownUser(validators.FancyValidator):
raise validators.Invalid(_("'%s' already exists.") % value, value, state)
class ValidSSHKey(validators.FancyValidator):
''' Make sure the ssh key uploaded is valid '''
def _to_python(self, value, state):
return value.file.read()
def validate_python(self, value, state):
# value = value.file.read()
print dir(value)
email_pattern = "[a-zA-Z0-9\.\+\-_]+@[a-zA-Z0-9\.\-]+"
keylines = value.split('\n')
print "KEYLINES: %s" % keylines
for keyline in keylines:
if not keyline:
continue
keyline = keyline.strip()
m = re.match('ssh-[dr]s[as] [^ ]+ ' + email_pattern, keyline)
if not m or m.end() < len(keyline):
raise validators.Invalid(_('Error - Not a valid ssh key: %s') % keyline, value, state)
class ValidUsername(validators.FancyValidator):
'''Make sure that a username isn't blacklisted'''
def _to_python(self, value, state):
@ -69,6 +88,7 @@ class UserSave(validators.Schema):
validators.String(not_empty=True, max=42),
validators.Regex(regex='^[^\n:<>]+$'),
)
ssh_key = ValidSSHKey(max=5000)
#mail = validators.All(
# validators.Email(not_empty=True, strip=True, max=128),
# NonFedoraEmail(not_empty=True, strip=True, max=128),
@ -213,7 +233,7 @@ class User(controllers.Controller):
@validate(validators=UserSave())
@error_handler(error)
@expose(template='fas.templates.user.edit')
def save(self, targetname, human_name, telephone, postal_address, email, ircnick=None, gpg_keyid=None, comments='', locale='en', timezone='UTC'):
def save(self, targetname, human_name, telephone, postal_address, email, ssh_key=None, ircnick=None, gpg_keyid=None, comments='', locale='en', timezone='UTC'):
username = turbogears.identity.current.user_name
target = targetname
person = People.by_username(username)
@ -230,6 +250,8 @@ class User(controllers.Controller):
target.ircnick = ircnick
target.gpg_keyid = gpg_keyid
target.telephone = telephone
if ssh_key:
target.ssh_key = ssh_key
target.postal_address = postal_address
target.comments = comments
target.locale = locale
@ -385,7 +407,11 @@ forward to working with you!
turbogears.flash(_("You are already logged in."))
turbogears.redirect('/user/view/%s', turbogears.identity.current.user_name)
return dict()
person = People.by_username(username)
try:
person = People.by_username(username)
except InvalidRequestError:
turbogears.flash(_('Username email combo does not exist!'))
turbogears.redirect('/user/resetpass')
if username and email:
if not email == person.emails['primary']:
turbogears.flash(_("username + email combo unknown."))