-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
62 lines (46 loc) · 2.16 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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.