Skip to content

Commit

Permalink
Worked on docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingthio committed Aug 28, 2017
1 parent e3327ed commit b48f59c
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 114 deletions.
1 change: 0 additions & 1 deletion .pypirc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
index-servers=pypi

[pypi]
repository = https://upload.pypi.org/legacy/
username = lingthio
29 changes: 15 additions & 14 deletions docs/source/data_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ In its simplest form, Flask-User makes use of a single User data-model class::
password = db.Column(db.String(255), nullable=False)

# User fields
active = db.Column(db.Boolean(),
active = db.Column(db.Boolean()),
first_name = db.Column(db.String(50), nullable=False)
last_name = db.Column(db.String(50), nullable=False)

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

Optional UserAuth data-model
----------------------------
If desired, the authentication fields can be stored in a separate UserAuth data-model class::
Expand All @@ -34,10 +35,11 @@ If desired, the authentication fields can be stored in a separate UserAuth data-
id = db.Column(db.Integer, primary_key=True)

# User fields
active = db.Column(db.Boolean(),
active = db.Column(db.Boolean()),
first_name = db.Column(db.String(50), nullable=False)
last_name = db.Column(db.String(50), nullable=False)


# Define UserAuth data-model
class UserAuth(db.Model):
id = db.Column(db.Integer, primary_key=True)
Expand All @@ -51,6 +53,7 @@ If desired, the authentication fields can be stored in a separate UserAuth data-
username = db.Column(db.String(50), nullable=False, unique=True)
password = db.Column(db.String(255), nullable=False)


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

Expand All @@ -75,27 +78,23 @@ The 'is_primary' attribute defines with email receives account notification emai
# Relationship
user_emails = db.relationship('UserEmail')


# Define UserEmail data-model
class UserEmail(db.Model):
id = db.Column(db.Integer, primary_key=True)

user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
user = db.relationship('User', uselist=False)

# User email information
email = db.Column(db.String(255), nullable=False, unique=True)
confirmed_at = db.Column(db.DateTime())
is_primary = db.Column(db.Boolean(), nullable=False, server_default='0')

# Relationship
user = db.relationship('User', uselist=False)

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

Note: The UserEmail data-model can also be specified when the UserAuth data-model is being used::

# Setup Flask-User
user_manager = UserManager(app, User, UserAuthClass=UserAuth, UserEmailClass=UserEmail)


Optional Role and UserRoles data-models
---------------------------------------
Expand Down Expand Up @@ -137,11 +136,6 @@ Fixed attribute names
All the attribute names mentioned above (except `first_name` and `last_name`) are fixed
(they must be named this way).

SQLAlchemy allows the database column name to be different from the data-model attribute name.
To use the data-model attribute `email` with the database column name `email_address`::

email = db.Column('email_address', db.String(255), nullable=False, unique=True)

| If your existing code uses different attribute names you have two options:
| 1) Rename these attributes throughout your code base
| 2) Use Python's property and propery-setters to translate attribute names
Expand All @@ -162,3 +156,10 @@ To use the data-model attribute `email` with the database column name `email_add
self.email_address = value # on user.email='xyz': set user.email_address='xyz'


Flexible database column names
------------------------------
SQLAlchemy allows the database column name to be different from the data-model attribute name.
To use the data-model attribute `email` with the database column name `email_address`::

email = db.Column('email_address', db.String(255), nullable=False, unique=True)

18 changes: 2 additions & 16 deletions docs/source/flask_user_starter_app.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
Flask-User-starter-app
======================

A more typical Flask application has modularized code organized in a directory structure.

An example of such a Flask-User application is the Flask-User-starter-app,
which available on Github:
We provide a Flask-User starter application through github:

https://github.com/lingthio/Flask-User-starter-app

It can serve as a great starter app for building your next Flask-User application.

Files of interest:

* app/startup/init_app.py
* app/models/user.py
* app/templates/flask_user/*.html
* app/templates/users/user_profile_page.html
Up Next
-------
:doc:`authorization`
This may serve as a great starting place to create your next Flask application with Flask-User.

36 changes: 32 additions & 4 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,55 @@ Fully customizable, yet Ready to use

Comes with translations
-----------------------
Chinese, Dutch, English, Farsi, Finnish, French, German, Italian, Spanish, Swedish, and Turkish
Chinese, Dutch, English, Farsi, Finnish, French, German, Italian, Russian, Spanish, Swedish, and Turkish

Requirements
------------
Flask-User requires the following Python packages:

- Python |supported_python_versions_or|
- Flask 0.10+
- Flask-Login 0.3+
- Flask-Mail 0.9+ or Flask-Sendmail
- Flask-WTF 0.9+
- passlib 1.6+
- pycrypto 2.6+

Optionally, for fast bcrypt encryption:

- py-bcript 0.4+

For SQLAlchemy applications:

- Flask-SQLAlchemy 1.0+
- A DBAPI driver (such as mysql-python for MySQL or psycopg2 for PostgreSQL)

Optionally, for Event Notification:

- blinker 1.3+

Optionally, for Internationalization:

- Flask-Babel 0.9+
- speaklater 1.3+

Alternatives
------------
* `Flask-Login <https://flask-login.readthedocs.org/en/latest/>`_
* `Flask-Security <https://pythonhosted.org/Flask-Security/>`_


Table of Contents
-----------------
.. toctree::
:maxdepth: 2

index
installation
quickstart
flask_user_starter_app
limitations
installation
data_models
porting
flask_user_starter_app
authorization
roles_required_app
base_templates
Expand Down
44 changes: 3 additions & 41 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,10 @@
Installation
============

Requirements
------------
Flask-User requires the following Python packages:
We recommend making use of virtualenv, virtualenvwrapper and pip::

- Python |supported_python_versions_or|
- Flask 0.10+
- Flask-Login 0.3+
- Flask-Mail 0.9+ or Flask-Sendmail
- Flask-WTF 0.9+
- passlib 1.6+
- pycrypto 2.6+

Optionally, for fast bcrypt encryption:

- py-bcript 0.4+

For SQLAlchemy applications:

- Flask-SQLAlchemy 1.0+
- A DBAPI driver (such as mysql-python for MySQL or psycopg2 for PostgreSQL)

Optionally, for Event Notification:

- blinker 1.3+

Optionally, for Internationalization:

- Flask-Babel 0.9+
- speaklater 1.3+


Installation Instructions
-------------------------

We recommend making use of virtualenv and virtualenvwrapper::

mkvirtualenv my_env
workon my_env

Install Flask-User using pip::

workon my_env
mkvirtualenv my_app
workon my_app
pip install flask-user


1 change: 1 addition & 0 deletions docs/source/internationalization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Flask-User ships with the following languages:
* fr - French (v0.6.1+)
* it - Italian (v0.6.9+)
* nl - Dutch (v0.1+)
* ru - Russian (v0.6.12+)
* sv - Swedish (v0.6.9+)
* tr - Turkish (v0.6.9+)
* zh - Chinese (Simplified) (v0.6.1+)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/limitations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Supported Databases
Flask-User uses a 'DatabaseAdapter' to shield its functionality from
the underlying database. It ships with a DatabaseAdapter for SQLAlchemy.

SQLAlchemy supports many SQL database, including:
SQLAlchemy supports many SQL databases, including:

* Firebird
* Microsoft SQL Server
Expand Down
60 changes: 56 additions & 4 deletions docs/source/porting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ The `db` parameter can be any Database instance (for example `SQLAlchemy()` or
appropriate DbAdapter will be configured internally.


Data-model changes
------------------
The `confirmed_at` attribute name has been renamed to `email_confirmed_at` to better reflect what this attribute means.

The optional UserAuth class has been obsoleted. See below for a workaround.


PasswordManager() changes
-------------------------
Password related methods have been moved from the UserManager class to a separate PasswordManager class,
Expand Down Expand Up @@ -84,11 +91,56 @@ This limitation has been removed in v1.0, to support Mongo ObjectIDs.

As a result, the generated tokens are different, which will affect two areas:

- v0.6 user-sessions that were stored in a browser cookie, are no longer valid in v1.0 and the user will be
required to login again.
- v0.6 user-sessions that were stored in a browser cookie, are no longer valid in v1.0
and the user will be required to login again.

- v0.6 password tokens that were sent in password reset emails are no longer valid in v1.0
and the user will have to issue a new forgot-password email request.
This effect is mitigated by the fact that these tokens are meant to expire relatively quickly.
and the user will have to issue a new forgot-password email request.
This effect is mitigated by the fact that these tokens are meant to expire relatively quickly.


UserAuth class
--------------

The optional UserAuth class has been obsoleted. If you still require a separate class, use the
workaround recipe below::


# Define the UserAuth data model.
class UserAuth(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'))

# User authentication information
username = db.Column(db.String(50), nullable=False, unique=True)
password = db.Column(db.String(255), nullable=False, server_default='')

# Relationships
user = db.relationship('User', uselist=False)


# Define the User data model. Make sure to add flask_user UserMixin!!
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)

# User email information
email = db.Column(db.String(255), nullable=False, unique=True)
confirmed_at = db.Column(db.DateTime())

# User information
active = db.Column('is_active', db.Boolean(), nullable=False, server_default='0')
first_name = db.Column(db.String(100), nullable=False, server_default='')
last_name = db.Column(db.String(100), nullable=False, server_default='')

# Relationships
user_auth = db.relationship('UserAuth', uselist=False)

# Map UserAuth attributes into User attributes
@property
def username(self):
return user_auth.username

@username.setter
def username(self, value)
user_auth.username = value

32 changes: 12 additions & 20 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
QuickStart
==========

The sample code below illustrates the power of using Flask-User with sensible defaults:
With just a dozen additional code statements,
a basic Flask application can be transformed to offer the following features:
With less than a dozen lines of code, we can add User Authentication and Management
to existing Flask applications with the following additional functionality:

* User registration
* Email confirmation
* Login and Logout
* Authentication
* Authentication (Login and Logout)
* Change username
* Change password
* Forgot password

Install Flask-User
------------------

Setup a development environment
-------------------------------
These tutorials assume that you are working with virtualenv and virtualenvwrapper
and that the code resides in ~/dev/example::
We recommend making use of virtualenv and virtualenvwrapper::

# Create virtualenv 'example'
mkvirtualenv example

# Install required Python packages in the 'example' virtualenv
workon example
mkvirtualenv my_app
workon my_app
pip install flask-user
pip install flask-mail

# Change working directory
mkdir -p ~dev/example # or mkdir C:\dev\example
cd ~/dev/example # or C:\dev\example on Windows
mkdir -p ~dev/my_app # or mkdir C:\dev\my_app
cd ~/dev/my_app # or cd C:\dev\my_app


Create the quickstart_app.py file
---------------------------------

Create ~/dev/example/quickstart_app.py with the content below.
Create ~/dev/my_app/quickstart_app.py with the content below.

Highlighted lines shows the lines added to a basic Flask application.

Expand All @@ -62,7 +54,7 @@ Run the QuickStart App
----------------------
Run the QuickStart App with the following command::

cd ~/dev/example
cd ~/dev/my_app
python quickstart_app.py

And point your browser to ``http://localhost:5000``.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/roles_required_app.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
==================
Roles Required App
==================
The Roles Required App builds on the features of :doc:`basic_app`:
The Roles Required App builds on the features of :doc:`quickstart`:

* Register form
* Login form
Expand Down
Loading

0 comments on commit b48f59c

Please sign in to comment.