Skip to content

marchon/Flask-Simple-Registration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Flask-Simple-Registration
=========================

This Flask extension provides a somewhat opinionated method of doing the very
basic components needed for user registration and login/logout. It allows for
lots of flexibility and should be what you need to get a basic system up and
running. It assumes that you're using Flask-WTF and Flask-SQLAlchemy. You can
customize the forms and your user model to be whatever you'd like. This
essentially provides the boilerplate code. Unfortunately, you still have to
write some yourself. This registration also doesn't do things like email
validation before a user is active - it's designed for simple use cases.

Setup
=====

First off, you're going to need to create some forms and models for your
application. They should inheret from 


    from flaskext import simpleregistration

    # set up your app, etc. Then...

    simplereg = simpleregistration.SimpleRegistration(
        app=app,
        user_model=MyUserModel,
        login_url="/login",
        login_form=MyLoginForm,
        login_redirect="dashboard",
        logout_url="/logout",
        logout_redirect="index",
        signup_url="/signup",
        signup_form=MySignupForm,
        signup_redirect="welcome"
    )


And you're good to go, assuming that your forms and models have the required methods.

For the _url methods, simpleregistration routes that for you. For the _redirect
urls, simpleregistration will do the url_for routing for you.

Forms and Models
================

Your login form should at some point during the validation process set the
"user" attribute on itself to be an instance of your user. This user object
*must* provide a *user_id* property. This will get stored in the session and be
used to provide the global user object.

The signup form *must* provide a *save* method. This saves the user based on
the form's data and returns an instance of the user, which is then used to log
the user in immediately.


Login Required
==============

There's a decorator to provide login-required functionality.
@flaskext.login_required will redirect the user to a login form with a "next"
GET arg. Once the user logs in, they will be redirected back to the page they
were on.

About

Basic simple registration package for Flask.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published