Almost there. You can now add, verify, and edit email entries. Just need to figure out interface/code for assigning emails to purposes.
This commit is contained in:
parent
38787c6a3b
commit
916512bc0d
4 changed files with 162 additions and 25 deletions
|
@ -8,15 +8,15 @@
|
|||
</head>
|
||||
<body>
|
||||
<h2>${_('Add Email')}</h2>
|
||||
<form action="${tg.url('/user/email/save/%s' % target.username)}" method="post" enctype="multipart/form-data">
|
||||
<form action="${tg.url('/user/email/create/%s' % target.username)}" method="post">
|
||||
<div class="field">
|
||||
<label for="email">${_('Email')}:</label>
|
||||
<label for="email">${_('Email:')}</label>
|
||||
<input type="text" id="email" name="email" />
|
||||
<!-- TODO: More generic documentation for adding an email -->
|
||||
<script type="text/javascript">var hb1 = new HelpBalloon({dataURL: '${tg.url('/help/get_help/user_primary_email')}'});</script>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="description">${_('Description')}:</label>
|
||||
<label for="description">${_('Description:')}</label>
|
||||
<input type="text" id="description" name="description" />
|
||||
<!-- TODO: Correct documentation for this -->
|
||||
<script type="text/javascript">var hb1 = new HelpBalloon({dataURL: '${tg.url('/help/get_help/user_primary_email')}'});</script>
|
||||
|
|
28
fas/fas/templates/user/email/edit.html
Normal file
28
fas/fas/templates/user/email/edit.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:py="http://genshi.edgewall.org/"
|
||||
xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<xi:include href="../../master.html" />
|
||||
<head>
|
||||
<title>${_('Edit Email')}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>${_('Edit Email')}</h2>
|
||||
<form action="${tg.url('/user/email/save/%s' % target.username)}" method="post">
|
||||
<div class="field">
|
||||
<label for="email">${_('Email:')}</label> <span>${email}</span>
|
||||
<input type="hidden" id="email" name="email" value="${email}" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="description">${_('Description:')}</label>
|
||||
<input type="text" id="description" name="description" value="${target.person_emails[email].description}" />
|
||||
<!-- TODO: Correct documentation for this -->
|
||||
<script type="text/javascript">var hb1 = new HelpBalloon({dataURL: '${tg.url('/help/get_help/user_primary_email')}'});</script>
|
||||
</div>
|
||||
<div class="field">
|
||||
<input type="submit" value="${_('Save!')}" />
|
||||
<a href="${tg.url('/user/email/manage')}">${_('Cancel')}</a>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -22,26 +22,35 @@
|
|||
<td><a href="mailto:${email.email}">${email.email}</a></td>
|
||||
<td>${email.description}</td>
|
||||
<td py:if="email.verified"><span class="approved">${_('Verified')}</span></td>
|
||||
<td py:if="not email.verified"><span class="unapproved">${_('Unverified')}</span> <a href="${tg.url('/email/verify')}">${_('Resend Verification')}</a></td>
|
||||
<td py:if="not email.verified"><span class="unapproved">${_('Unverified')}</span> (<a href="${tg.url('/email/verify')}">${_('Resend Verification')}</a>)</td>
|
||||
<td py:if="len(target.person_emails) > 1"><a href="${tg.url('/user/email/remove/%s/%s') % (target.username, email.email)}">${_('Remove')}</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3>Set Emails</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>${_('Email')}</th>
|
||||
<th>${_('Description')}</th>
|
||||
<th>${_('Purpose')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr py:for="purpose in target.email_purposes.values()">
|
||||
<td><a href="mailto:${purpose.email}">${purpose.email}</a></td>
|
||||
<td>${purpose.person_email.description}</td>
|
||||
<td>${purpose.purpose}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<form action="${tg.url('/user/email/map/%s' % target.username)}">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>${_('Email')}</th>
|
||||
<th>${_('Description')}</th>
|
||||
<th>${_('Purpose')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr py:for="purpose in target.email_purposes.values()">
|
||||
<td>
|
||||
<select id="email" name="email">
|
||||
<py:for each="person_email in target.person_emails.values()">
|
||||
<option py:if="person_email.verified" value="person_email.email" py:attrs="{'selected': purpose.email == person_email.email and 'selected' or None}">${person_email.email} (${person_email.description})</option>
|
||||
</py:for>
|
||||
</select>
|
||||
</td>
|
||||
<td>${purpose.person_email.description}</td>
|
||||
<td>${purpose.purpose}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -36,6 +36,13 @@ def generate_validtoken(length=32):
|
|||
token += random.choice(chars)
|
||||
return token
|
||||
|
||||
# Note: I'm making some of these controllers really, really hideous
|
||||
# (in the interest of allowing admins to modify pretty much everything)
|
||||
# Is this really necessary (as in, can tg-admin shell be "good enough?"
|
||||
# (I'm pretty much referring to passing the username around every
|
||||
# instead of just using the current logged on person.)
|
||||
|
||||
# I hope all of this doesn't end up being too convoluted for most users...
|
||||
class Email(controllers.Controller):
|
||||
|
||||
def __init__(self):
|
||||
|
@ -79,9 +86,68 @@ class Email(controllers.Controller):
|
|||
return dict(target=target)
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
# TODO: Validate!
|
||||
#@validate(validators=UserView())
|
||||
@error_handler(error)
|
||||
@expose(template="fas.templates.user.email.add", allow_json=True)
|
||||
@expose(template="fas.templates.user.email.edit")
|
||||
# TODO: Should the purpose-setting part be moved in into user/save?
|
||||
def edit(self, targetname, email):
|
||||
'''
|
||||
Display the form to edit an email
|
||||
'''
|
||||
username = turbogears.identity.current.user_name
|
||||
person = People.by_username(username)
|
||||
|
||||
if targetname:
|
||||
target = People.by_username(targetname)
|
||||
else:
|
||||
target = person
|
||||
|
||||
if not canEditUser(person, target):
|
||||
turbogears.flash(_('You cannot edit %s') % target.username )
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
return dict(email=email, target=target)
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
# TODO: Validate!
|
||||
#@validate(validators=UserView())
|
||||
@error_handler(error)
|
||||
@expose()
|
||||
# TODO: Should the purpose-setting part be moved in into user/save?
|
||||
def save(self, targetname, email, description):
|
||||
'''
|
||||
Save an email entry
|
||||
'''
|
||||
username = turbogears.identity.current.user_name
|
||||
person = People.by_username(username)
|
||||
|
||||
if targetname:
|
||||
target = People.by_username(targetname)
|
||||
else:
|
||||
target = person
|
||||
|
||||
if not canEditUser(person, target):
|
||||
turbogears.flash(_('You cannot edit %s') % target.username )
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
|
||||
try:
|
||||
person.person_emails[email].description = description
|
||||
except KeyError:
|
||||
turbogears.flash(_('No such email is associated with your user.'))
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
else:
|
||||
turbogears.flash(_('Your email has been saved.'))
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
# TODO: Validate!
|
||||
#@validate(validators=UserView())
|
||||
@error_handler(error)
|
||||
@expose(template="fas.templates.user.email.add")
|
||||
def add(self, targetname=None):
|
||||
'''
|
||||
Display the form to add an email
|
||||
|
@ -101,13 +167,47 @@ class Email(controllers.Controller):
|
|||
|
||||
return dict(target=target)
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
# TODO: Validate!
|
||||
#@validate(validators=UserView())
|
||||
@error_handler(error)
|
||||
@expose(allow_json=True)
|
||||
def remove(self, targetname, email):
|
||||
'''
|
||||
Remove an email
|
||||
'''
|
||||
username = turbogears.identity.current.user_name
|
||||
person = People.by_username(username)
|
||||
|
||||
if targetname:
|
||||
target = People.by_username(targetname)
|
||||
else:
|
||||
target = person
|
||||
|
||||
if not canEditUser(person, target):
|
||||
turbogears.flash(_('You cannot edit %s') % target.username )
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
|
||||
try:
|
||||
session.delete(target.person_emails[email])
|
||||
session.flush()
|
||||
except IntegrityError:
|
||||
turbogears.flash(_('You cannot delete an email that is in use.'))
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
else:
|
||||
turbogears.flash(_('The email \'%s\' has been removed.') % email )
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
@validate(validators=EmailSave())
|
||||
@error_handler(error)
|
||||
@expose(template="fas.templates.user.email.add", allow_json=True)
|
||||
def save(self, targetname, email, description):
|
||||
def create(self, targetname, email, description):
|
||||
'''
|
||||
Display the form to add an email
|
||||
Create an email entry.
|
||||
'''
|
||||
username = turbogears.identity.current.user_name
|
||||
person = People.by_username(username)
|
||||
|
@ -144,8 +244,8 @@ Go to this URL to verify that you own this email address: %s
|
|||
''') % validurl
|
||||
turbomail.enqueue(message)
|
||||
turbogears.flash(_('Your email has been added. Before you can use this email, you must verify it. The email you added should receive a message with instructions shortly.'))
|
||||
|
||||
return dict(target=target)
|
||||
turbogears.redirect('/user/email/manage')
|
||||
return dict()
|
||||
|
||||
return dict(target=target)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue