Skip to content

Commit

Permalink
Removed unnecessary CustomUserManager() declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingthio committed Sep 16, 2017
1 parent 3a3054d commit 38d2110
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 127 deletions.
27 changes: 14 additions & 13 deletions docs/source/api_db_adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ while shielding the Flask-User code from the underlying implementation.
.. autoclass:: flask_user.db_adapters.db_adapter_interface.DbAdapterInterface
:special-members: __init__

Example implementation
----------------------
Here's the `SQLDbAdapter() implementation on github <https://github.com/lingthio/Flask-User/blob/master/flask_user/db_adapters/sql_db_adapter.py>`_.
.. _CustomDbAdapters:

Customizing Flask-User
----------------------
::
Implementing a CustomDbAdapter
------------------------------
You can write you own DbAdapter implementation by defining a CustomDbAdapter class
and configure Flask-User to use this class like so::

# Customize Flask-User
class CustomUserManager(UserManager):

def customize(self, app):
# Use the CustomDbAdapter
self.db_adapter = CustomDbAdapter(app)
# Define a CustomDbAdapter
from flask_user.db_adapters import DbAdapterInterface
class CustomDbAdapter(DbAdapterInterface):
...

# Setup Flask-User
user_manager = CustomUserManager(app, db, User)
user_manager = UserManager(app, db, User)

# Customize Flask-User
user_manager.db_adapter = CustomDbAdapter(app)

For an example, see `the SQLDbAdapter() implementation <https://github.com/lingthio/Flask-User/blob/master/flask_user/db_adapters/sql_db_adapter.py>`_.
28 changes: 15 additions & 13 deletions docs/source/api_email_adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ while shielding the Flask-User code from the underlying implementation.
def send_email_message(...):
# use self.sender_name and self.sender_email here...

Example implementation
----------------------
Here's the `SMTPEmailAdapter() implementation on github <https://github.com/lingthio/Flask-User/blob/master/flask_user/email_adapters/smtp_email_adapter.py>`_.
.. _CustomEmailAdapters:

Customizing Flask-User
----------------------
::
Implementing a CustomEmailAdapter
---------------------------------
You can write you own EmailAdapter implementation by defining a CustomEmailAdapter class
and configure Flask-User to use this class like so::

# Customize Flask-User
class CustomUserManager(UserManager):

def customize(self, app):
# Use the CustomEmailAdapter
self.email_adapter = CustomEmailAdapter(app)
# Define a CustomEmailAdapter
from flask_user.email_adapters import EmailAdapterInterface
class CustomEmailAdapter(EmailAdapterInterface):
...

# Setup Flask-User
user_manager = CustomUserManager(app, db, User)
user_manager = UserManager(app, db, User)

# Customize Flask-User
user_manager.email_adapter = CustomDbAdapter(app)

For an example, see `the SMTPEmailAdapter() implementation <https://github.com/lingthio/Flask-User/blob/master/flask_user/email_adapters/smtp_email_adapter.py>`_.
20 changes: 1 addition & 19 deletions docs/source/configuring_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,12 @@ Configuring settings

--------

Flask-User default features and settings can overridden in one of two ways:

1) By changing the settings in the application config file::
Flask-User default features and settings can overridden through the app config::

# Customize Flask-User settings
USER_ENABLE_EMAIL = True
USER_ENABLE_USERNAME = False

2) By changing the setting in the ``UserManager.customize()``::

# Customize Flask-User
class CustomUserManager(UserManager):

def customize(self, app):

# Customize Flask-User settings
self.USER_ENABLE_EMAIL = True
self.USER_ENABLE_USERNAME = False

# Setup Flask-User
user_manager = CustomUserManager(app, db, User)

``UserManager.customize()`` settings take precedence over the application config file settings.

Flask-User settings
-------------------

Expand Down
92 changes: 17 additions & 75 deletions docs/source/customizing_advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,103 +15,45 @@ Developers can customize the EmailManager, the PasswordManager, and the TokenMan
# Customize the EmailManager
from flask_user import EmailManager
class CustomEmailManager(EmailManager):
pass
...

# Customize the PasswordManager
from flask_user import PasswordManager
class CustomPasswordManager(PasswordManager):
pass
...

# Customize the TokenManager
from flask_user import TokenManager
class CustomTokenManager(TokenManager):
pass

# Customize Flask-User
class CustomUserManager(UserManager):

def customize(self, app):

# Customize Flask-User managers
self.email_manager = CustomEmailManager(app)
self.password_manager = CustomPasswordManager(app, 'bcrypt')
self.token_manager = CustomTokenManager(app)
...

# Setup Flask-User
user_manager = CustomUserManager(app, db, User)
user_manager = UserManager(app, db, User)

# Customize Flask-User managers
user_manager.email_manager = CustomEmailManager(app)
user_manager.password_manager = CustomPasswordManager(app, 'bcrypt')
user_manager.token_manager = CustomTokenManager(app)

.. seealso::

| :ref:`EmailManager`,
| :ref:`PasswordManager`, and
| :ref:`TokenManager`.
.. _CustomDbAdapters:

Custom DbAdapters
=================

Flask-User uses DbAdapters to manage user records in various databases.

Flask-User ships with the following DbAdapters:

- ``SQLDbAdapter()`` for SQL databases using SQLAlchemy
- ``MongoDbAdapter()`` for MongoDB database using MongoEngine

Flask-User allows developers to implement a custom DbAdapter that
conforms to the :ref:`DbAdapterInterface`::

# Define a custom DbAdapter
from flask_user.email_adapters import DbAdapter
class CustomDbAdapter(DbAdapter):
pass

# Customize Flask-User
class CustomUserManager(UserManager):

def customize(self, app):
# Use the CustomDbAdapter
self.db_adapter = CustomDbAdapter(app, db)

# Setup Flask-User
user_manager = CustomUserManager(app, db, User)

Here's the `SQLDbAdapter() implementation on github <https://github.com/lingthio/Flask-User/blob/master/flask_user/db_adapters/sql_db_adapter.py>`_.


.. _CustomEmailAdapters:

Custom EmailAdapters
====================

Flask-User uses EmailAdapters to send email via various methods.

Flask-User ships with the following EmailAdapters:

- ``SMTPEmailAdapter()`` for sending email via SMTP.
- ``SendmailEmailAdapter()`` for sending email via ``sendmail``.
- ``SendgridEmailAdapter()`` for sending email via SendGrid.

Flask-User allows developers to implement a custom EmailAdapter that
conforms to the :ref:`EmailAdapterInterface`::

# Define a custom EmailAdapter
from flask_user.email_adapters import EmailAdapter
class CustomEmailAdapter(EmailAdapter):
pass
--------

# Customize Flask-User
class CustomUserManager(UserManager):
Implementing a CustomDbAdapter
------------------------------

def customize(self, app):
# Use the CustomEmailAdapter
self.email_adapter = CustomEmailAdapter(app)
--------

# Setup Flask-User
user_manager = CustomUserManager(app, db, User)
See :ref:`CustomDbAdapters`

Here's the `SMTPEmailAdapter() implementation on github <https://github.com/lingthio/Flask-User/blob/master/flask_user/email_adapters/smtp_email_adapter.py>`_.
Implementing a CustomEmailAdapter
---------------------------------

See :ref:`CustomEmailAdapters`

--------

Expand Down
24 changes: 24 additions & 0 deletions docs/source/customizing_emails.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ Customizing Emails

--------

.. _CustomizingEmailAdapters:

Customizing EmailAdapters
-------------------------
Flask-User ships with the following EmailAdapters:
- SendgridEmailAdapter to send email messages via Sendgrid
- SendmailEmailAdapter to send email messages via Sendmail
- SMTPEmailAdapter to send email messages via SMTP

Flask-User works with the SMTPEmailAdapter by default, but another EmailAdapter can be configured like so::

# Setup Flask-User
user_manager = UserManager(app, db, User)

# Customize Flask-User
from flask_user.email_adapters import SendgridEmailAdapter
user_manager.email_adapter = SendgridEmailAdapter(app)


--------

Customizing Email messages
--------------------------

Flask-User currently offers the following types of email messages::

confirm_email # Sent after a user submitted a registration form
Expand Down
8 changes: 4 additions & 4 deletions docs/source/customizing_forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ Flask user ships with default username and password form field validators that c
# Setup Flask-User
user_manager = CustomUserManager(app, db, User)

The code for the default ``password_validator()`` can be found `on github near this line <https://github.com/lingthio/Flask-User/blob/master/flask_user/user_manager.py#L215>`_.

The code for the default ``username_validator()`` can be found `on github near this line <https://github.com/lingthio/Flask-User/blob/master/flask_user/user_manager.py#L239>`_.
| Examples:
| `The default password_validator() <https://github.com/lingthio/Flask-User/blob/master/flask_user/user_manager.py#L219>`_.
| `The default username_validator() <https://github.com/lingthio/Flask-User/blob/master/flask_user/user_manager.py#L243>`_.
--------

Expand All @@ -202,7 +202,7 @@ Optionally, if you want to change the default behaviour, you can customize the v

# Override or extend the default login view method
def login_view(self):
pass
...

# Setup Flask-User
user_manager = CustomUserManager(app, db, User)
Expand Down
6 changes: 3 additions & 3 deletions docs/source/porting_customizations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ instantiation. For example::

In v0.9, Flask-User is customized by:
- Extending the ``CustomUserManager`` class
- Setting a property in its ``customize()`` method
- Overriding or extending a method
- Setting properties in its ``customize()`` method
- Overriding or extending methods

::

# Customize Flask-User
class CustomUserManager(UserManager):

def customize(app):
def customize(self, app):
# Override properties
register_form = CustomRegisterForm()
token_manager = CustomTokenManager(app)
Expand Down

0 comments on commit 38d2110

Please sign in to comment.