summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-09-29 15:37:57 +0200
committerNico von Geyso <Nico.Geyso@FU-Berlin.de>2012-09-29 15:37:57 +0200
commitbf63617665d53081f3c57965a0c3dcada81a6b19 (patch)
tree1a79e4cc7b84a55dde5291bc74359b0b4cff627d
parent2de0d141ccb66844643ee7b881a8ce86128279e7 (diff)
parent12a6678d280733bd420923b49608d62f8f920ab1 (diff)
downloadweb-bf63617665d53081f3c57965a0c3dcada81a6b19.tar.gz
web-bf63617665d53081f3c57965a0c3dcada81a6b19.tar.bz2
web-bf63617665d53081f3c57965a0c3dcada81a6b19.zip
Merge branch 'master' of ssh://git.spline.de/account-web
-rwxr-xr-xcontrib/create_account.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/contrib/create_account.py b/contrib/create_account.py
index cb4392a..17e4646 100755
--- a/contrib/create_account.py
+++ b/contrib/create_account.py
@@ -6,8 +6,8 @@ sys.path.append(dirname(dirname(abspath(__file__))))
from account import AccountService, NoSuchUserError
from app import app
-from flask import g, url_for
-from utils import make_confirmation
+from flask import g, render_template, url_for
+from utils import make_confirmation, send_mail
"""
Create an account.
@@ -18,10 +18,11 @@ blacklist is not checked.
The user can click the link and enter a password to finish account creation.
Usage:
- $0 username email
+ $0 username mail Send an activation mail.
+ $0 -p username mail Only print the link.
"""
-def main(username, mail):
+def main(username, mail, print_only=False):
service = AccountService(app.config['LDAP_HOST'], app.config['LDAP_BASE_DN'],
app.config['LDAP_ADMIN_USER'], app.config['LDAP_ADMIN_PASS'],
app.all_services)
@@ -43,7 +44,18 @@ def main(username, mail):
confirm_token = make_confirmation('register', (username, mail))
confirm_link = url_for('register_complete', token=confirm_token, _external=True)
- print confirm_link
+ if print_only:
+ print confirm_link
+ return
+
+ body = render_template('mail/register.txt', username=username,
+ mail=mail, link=confirm_link)
+
+ send_mail(mail, u'E-Mail-Adresse bestätigen', body,
+ sender=app.config.get('MAIL_CONFIRM_SENDER'))
+
+ print 'Mail versandt.'
+
class CreationError(ValueError):
@@ -51,11 +63,18 @@ class CreationError(ValueError):
if __name__ == '__main__':
+ try:
+ sys.argv.remove('-p')
+ except ValueError:
+ print_only = False
+ else:
+ print_only = True
+
if len(sys.argv) == 3:
#XXX: I have the strong feeling that could be done better
try:
with app.test_request_context(base_url='http://%s/' % (app.config['SERVER_NAME'] or 'localhost')):
- main(*sys.argv[1:])
+ main(sys.argv[1], sys.argv[2], print_only=print_only)
except CreationError, e:
print 'Error:', e
else: