aboutsummaryrefslogtreecommitdiff
path: root/wqflask/flask_security/registerable.py
diff options
context:
space:
mode:
authorZachary Sloan2013-06-20 22:20:23 +0000
committerZachary Sloan2013-06-20 22:20:23 +0000
commit4ffee373494170e708678039dca132f1bd729ab1 (patch)
treea9d6054380f5a9d612a4d1d88889f68ea4923a75 /wqflask/flask_security/registerable.py
parent939058c4a3b668037974f2876b072c4be008da26 (diff)
parent52ac4b6e1c014801080cbbcad53df868058d2657 (diff)
downloadgenenetwork2-4ffee373494170e708678039dca132f1bd729ab1.tar.gz
Merge branch 'flask'
Diffstat (limited to 'wqflask/flask_security/registerable.py')
-rw-r--r--wqflask/flask_security/registerable.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/wqflask/flask_security/registerable.py b/wqflask/flask_security/registerable.py
new file mode 100644
index 00000000..4e9f357d
--- /dev/null
+++ b/wqflask/flask_security/registerable.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+"""
+ flask.ext.security.registerable
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Flask-Security registerable module
+
+ :copyright: (c) 2012 by Matt Wright.
+ :license: MIT, see LICENSE for more details.
+"""
+
+from flask import current_app as app
+from werkzeug.local import LocalProxy
+
+from .confirmable import generate_confirmation_link
+from .signals import user_registered
+from .utils import do_flash, get_message, send_mail, encrypt_password, \
+ config_value
+
+# Convenient references
+_security = LocalProxy(lambda: app.extensions['security'])
+
+_datastore = LocalProxy(lambda: _security.datastore)
+
+
+def register_user(**kwargs):
+ confirmation_link, token = None, None
+ kwargs['password'] = encrypt_password(kwargs['password'])
+ user = _datastore.create_user(**kwargs)
+ _datastore.commit()
+
+ if _security.confirmable:
+ confirmation_link, token = generate_confirmation_link(user)
+ do_flash(*get_message('CONFIRM_REGISTRATION', email=user.email))
+
+ user_registered.send(dict(user=user, confirm_token=token),
+ app=app._get_current_object())
+
+ if config_value('SEND_REGISTER_EMAIL'):
+ send_mail(config_value('EMAIL_SUBJECT_REGISTER'), user.email, 'welcome',
+ user=user, confirmation_link=confirmation_link)
+
+ return user