Code Monkey home page Code Monkey logo

flask-simple-registration's Introduction

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.

flask-simple-registration's People

Contributors

mtrichardson avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.