now doing file uploads for ssh key and much better error handling
This commit is contained in:
parent
d41acad677
commit
d9305694e9
2 changed files with 25 additions and 3 deletions
|
@ -8,7 +8,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>${_('Edit Account (%s)') % target.username}</h2>
|
<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">
|
<div class="field">
|
||||||
<label for="human_name">${_('Human Name')}:</label>
|
<label for="human_name">${_('Human Name')}:</label>
|
||||||
<input type="text" id="human_name" name="human_name" value="${target.human_name}" />
|
<input type="text" id="human_name" name="human_name" value="${target.human_name}" />
|
||||||
|
@ -41,7 +41,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="ssh_key">${_('Public SSH Key')}:</label>
|
<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>
|
<script type="text/javascript">var hb19 = new HelpBalloon({dataURL: '${tg.url('/help/get_help/user_ssh_key')}'});</script>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
|
@ -54,6 +54,25 @@ class UnknownUser(validators.FancyValidator):
|
||||||
|
|
||||||
raise validators.Invalid(_("'%s' already exists.") % value, value, state)
|
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):
|
class ValidUsername(validators.FancyValidator):
|
||||||
'''Make sure that a username isn't blacklisted'''
|
'''Make sure that a username isn't blacklisted'''
|
||||||
def _to_python(self, value, state):
|
def _to_python(self, value, state):
|
||||||
|
@ -69,6 +88,7 @@ class UserSave(validators.Schema):
|
||||||
validators.String(not_empty=True, max=42),
|
validators.String(not_empty=True, max=42),
|
||||||
validators.Regex(regex='^[^\n:<>]+$'),
|
validators.Regex(regex='^[^\n:<>]+$'),
|
||||||
)
|
)
|
||||||
|
ssh_key = ValidSSHKey(max=5000)
|
||||||
#mail = validators.All(
|
#mail = validators.All(
|
||||||
# validators.Email(not_empty=True, strip=True, max=128),
|
# validators.Email(not_empty=True, strip=True, max=128),
|
||||||
# NonFedoraEmail(not_empty=True, strip=True, max=128),
|
# NonFedoraEmail(not_empty=True, strip=True, max=128),
|
||||||
|
@ -230,7 +250,8 @@ class User(controllers.Controller):
|
||||||
target.ircnick = ircnick
|
target.ircnick = ircnick
|
||||||
target.gpg_keyid = gpg_keyid
|
target.gpg_keyid = gpg_keyid
|
||||||
target.telephone = telephone
|
target.telephone = telephone
|
||||||
target.ssh_key = ssh_key
|
if ssh_key:
|
||||||
|
target.ssh_key = ssh_key
|
||||||
target.postal_address = postal_address
|
target.postal_address = postal_address
|
||||||
target.comments = comments
|
target.comments = comments
|
||||||
target.locale = locale
|
target.locale = locale
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue