diff options
author | Zachary Sloan | 2013-06-13 22:45:01 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-06-13 22:45:01 +0000 |
commit | 78998b9400bba9ecc9fdd5e50eef1405bb3625c1 (patch) | |
tree | 88da507baa1ccda96165a908257d891204259d3b /wqflask/flask_security/registerable.py | |
parent | aac1dd2f9c5b216b24c6e35676ba5d50f9d5d3c2 (diff) | |
parent | 0e633460f37cb9b7c23805c4c31b1044e0704d1b (diff) | |
download | genenetwork2-78998b9400bba9ecc9fdd5e50eef1405bb3625c1.tar.gz |
Merge /home/sam/gene into flask
Conflicts:
wqflask/wqflask/templates/index_page.html
Merging the code on Sam's branch onto my own
Diffstat (limited to 'wqflask/flask_security/registerable.py')
-rw-r--r-- | wqflask/flask_security/registerable.py | 43 |
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 |