Skip to content

Commit

Permalink
Removed UserAuthClass. Renamed User/UserEmail/UserInvitationModel to …
Browse files Browse the repository at this point in the history
…User/UserEmail/UserInvitationClass.
  • Loading branch information
lingthio committed Aug 28, 2017
1 parent b48f59c commit 84db036
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 431 deletions.
32 changes: 0 additions & 32 deletions docs/source/data_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,6 @@ In its simplest form, Flask-User makes use of a single User data-model class::
# 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::

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

# User fields
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)

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

# Authentication fields
email = db.Column(db.String(255), nullable=False, unique=True)
email_confirmed_at = db.Column(db.DateTime())
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)


Optional UserEmail data-model
-----------------------------
Flask-User can be configured to allow for multiple emails per users, pointing to the same user account
Expand Down
6 changes: 3 additions & 3 deletions docs/source/limitations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Python data-model class names
-----------------------------
No known restrictions.

Flask-User relies on a User class and optionally on a UserAuth, UserEmail, UserInvitation and Role class.
Flask-User relies on a User class and optionally on a UserEmail, UserInvitation and Role class.
The names of these classes can be anything you choose.


Expand Down Expand Up @@ -84,7 +84,7 @@ If a single User data-model class is specified, the following attribute names ar


Note: Depending on Flask-User configuration settings, some attributes may move to other data-model classes,
such as UserAuth and UserEmail. These configurations will be discussed elsewhere.
such as UserEmail. These configurations will be discussed elsewhere.


SQL table names
Expand Down Expand Up @@ -112,7 +112,7 @@ SQLAlchemy allows column names to be different from their corresponding attribut

Primary keys
------------
The primary key of the User, UserAuth, UserEmail, UserInvitation and Role tables:
The primary key of the User, UserEmail, UserInvitation and Role tables:

- must be named 'id'
- must be an Integer
Expand Down
94 changes: 1 addition & 93 deletions docs/source/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,99 +34,7 @@ Feeling generous? `Tip me on Gittip <https://www.gittip.com/lingthio/>`_

Revision History
----------------
* v0.6.10 Added Spanish translation.
* v0.6.9 Added support for Flask-Login v0.4+.
Replaced pycrypto with pycryptodome.
Added Farsi, Italian and Turkish translations.
* v0.6.8 Added support for Flask-Login v0.3+
* v0.6.7 Uses Python package bcrypt instead of py-bcrypt.
* v0.6.6 Forgot password form now honors USER_SHOW_USERNAME_OR_EMAIL_DOES_NOT_EXIST setting.
* v0.6.5 Added USER_SHOW_USERNAME_OR_EMAIL_DOES_NOT_EXIST setting.
* v0.6.4 Moved custom params from __init__() to init_app(). Added send_reset_password_email().
* v0.6.3 Fix for Python 3.4 and signals. Added UserMixin.has_role() and @roles_accepted().
* v0.6.2 Added support for invitation-only registrations.
* v0.6.1 Added Chinese (Simplified) and French translations`.
* v0.6 Changed User/UserProfile data-models into UserAuth/User data-models.

::

v0.6 Is backwards compatible with v0.5 but UserProfileClass will be deprecated
in the future. See the 'Data Models' section in this documentation.

* v0.5.5 Added user_profile view. Cleaned up base template. Support for UserProfile.roles.
* v0.5.4 Decoupled Flask-User from Flask-Babel and speaklater
* v0.5.3

* Added remember-me feature.
* Added support for a primary key name other than 'id'.
* Added USER_AUTO_LOGIN\_... settings.
* Added USER_AFTER\_..._ENDPOINT settings.
* Cleaned up email templates.

::

v0.5.3 API changes
The 'confirm_email' emails are now sent only after a resend confirm email request.
The 'registered' email is now sent after registration, whether
USER_ENABLE_CONFIRM_EMAIL is True or False.

(Previously, the 'confirm_email' email was sent after registration
and after a resend confirm email request, and the 'registered' email was sent only
after registration and when USER_ENABLE_CONFIRM_EMAIL was False)


* v0.5.2 Added USER_AUTO_LOGIN setting.
* v0.5.1 Added Support for multiple emails per user.
* v0.5.0 Added ``resend_confirm_email``.
* v0.4.9 Added ``login_or_register.html``. Cleaned up example_apps.
* v0.4.8 Removed the need for app.mail, app.babel, app.db and app.User properties.
* v0.4.7 Added 'confirm_email', 'password_changed' and 'username_changed' emails.

::

v0.4.7 API changes
The 'registered' email was split into 'confirm_email' and 'registered' emails.
If you've customized 'templates/flask_user/email/registered_*':
rename the 'registered_*' files into 'confirm_email_*'.

* v0.4.6 Added 'next' query parameter to confirm_email link
* v0.4.5 Save custom Register fields to User or UserProfile

::

v0.4.5 API changes
db_adapter.add_object()/update_object()/delete_object() now require a separate
call to db_adapter.commit()

* v0.4.4 Enhancements and Fixes: Github issues #6, #7 & #8
* v0.4.3 base.html, flask_user/public_base.html, flask_user/member_base.html.
Cleanup. Reduced package size from 83KB to 30KB.

::

v0.4.3 API changes
Form templates now inherit from templates/flask_user/public_base.html,
templates/flask_user/member_base.html and templates/base.html.

* v0.4.2 Cleanup of SQLAlchemyAdapter. Added tox for Python 3.4
* v0.4.1 Cleanup of customized email messages and signals.

::

v0.4.1 API changes
- User.email_confirmed_at --> confirmed_at
- templates/flask_user/emails/confirmation_email_* --> registered_*
- signals.confirmation_email_set --> user_registered
- template variable {{ confirmation_link }} --> {{ confirm_email_link }}
- templates/flask_user/emails/reset_password_* --> forgot_password_*
- signals.reset_password_email_sent --> user_forgot_password

* v0.4.0 Beta release. Translations via Babel.
* v0.3.8 Role-based authorization via @roles_required.
* v0.3.5 Support for Python 2.6, 2.7 and 3.3, Event notifications.
* v0.3.1 Alpha release. Email sending, Confirm email, Forgot password, Reset password.
* v0.2 Change username, Change password.
* v0.1 Register, Login, Logout.
* v1.0.0 Initial version

Extension Packages
------------------
Expand Down
30 changes: 24 additions & 6 deletions docs/source/porting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,24 @@ As a result, the generated tokens are different, which will affect two areas:
UserAuth class
--------------

The optional UserAuth class has been obsoleted. If you still require a separate class, use the
workaround recipe below::
The optional v0.6 UserAuth class has been fully obsoleted in v1.0 to simplify the Flask-User source code.

If you are using SQLAlchemy and choose to separate the uer authorization fields
from the user profile fields, you can use the workaround recipe below::


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

# Relationship to user
user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'))
user = db.relationship('User', uselist=False)

# 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):
Expand All @@ -135,7 +137,14 @@ workaround recipe below::
# Relationships
user_auth = db.relationship('UserAuth', uselist=False)

# Map UserAuth attributes into User attributes

# Create UserAuth instance when User instance is created
def __init__(self, *args, **kwargs):
super(User, self).__init__(*args, **kwargs)
self.user_auth = UserAuth(user=self)


# Map the User.username field into the UserAuth.username field
@property
def username(self):
return user_auth.username
Expand All @@ -144,3 +153,12 @@ workaround recipe below::
def username(self, value)
user_auth.username = value


# Map the User.password field into the UserAuth.password field
@property
def password(self):
return user_auth.password

@password.setter
def password(self, value)
user_auth.password = value
159 changes: 0 additions & 159 deletions example_apps/user_auth_app.py

This file was deleted.

Loading

0 comments on commit 84db036

Please sign in to comment.