Tracking PR for registration rewrite #5
6 changed files with 43 additions and 0 deletions
|
@ -19,4 +19,8 @@ def create_app():
|
||||||
|
|
||||||
from .models import User
|
from .models import User
|
||||||
|
|
||||||
|
from . import registration
|
||||||
|
|
||||||
|
app.register_blueprint(registration.bp)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
from flask import flash, redirect, url_for
|
||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
from sqlalchemy import Boolean, Column, DateTime, Integer, String
|
from sqlalchemy import Boolean, Column, DateTime, Integer, String
|
||||||
from . import db
|
from . import db
|
||||||
|
from . import login
|
||||||
|
|
||||||
class User(db.Model, UserMixin):
|
class User(db.Model, UserMixin):
|
||||||
id = Column(Integer, primary_key=True)
|
id = Column(Integer, primary_key=True)
|
||||||
|
@ -11,3 +13,13 @@ class User(db.Model, UserMixin):
|
||||||
last_login = Column(DateTime, nullable=False)
|
last_login = Column(DateTime, nullable=False)
|
||||||
active = Column(Boolean, nullable=False, default=True)
|
active = Column(Boolean, nullable=False, default=True)
|
||||||
is_admin = Column(Boolean, nullable=False, default=False)
|
is_admin = Column(Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
|
|
||||||
|
@login.user_loader
|
||||||
|
def user_loader(user_id):
|
||||||
|
return User.query.filter_by(id=user_id).first()
|
||||||
|
|
||||||
|
@login.unauthorized_handler
|
||||||
![]() The data was required by mlh, still could be nice to have so I'd keep it The data was required by mlh, still could be nice to have so I'd keep it
|
|||||||
|
def unauth():
|
||||||
|
flash("Please login first")
|
||||||
|
return redirect(url_for("registration.register"))
|
||||||
|
|
12
goathacks/registration/__init__.py
Normal file
12
goathacks/registration/__init__.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from flask import Blueprint, flash
|
||||||
|
from flask_login import current_user
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('registration', __name__, url_prefix="/registration")
|
||||||
|
|
||||||
|
@bp.route("/")
|
||||||
|
def register():
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
flash("You are already registered and logged in!")
|
||||||
|
|
||||||
|
|
13
goathacks/registration/forms.py
Normal file
13
goathacks/registration/forms.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
|
from wtforms import PasswordField, StringField
|
||||||
|
from wtforms.validators import DataRequired
|
||||||
|
|
||||||
|
class RegisterForm(FlaskForm):
|
||||||
|
email = StringField("Email", validators=[DataRequired()])
|
||||||
![]() This could probably get turned into an This could probably get turned into an `EmailField` if we cared enough
|
|||||||
|
first_name = StringField("Preferred First Name",
|
||||||
|
validators=[DataRequired()])
|
||||||
|
last_name = StringField("Last Name", validators=[DataRequired()])
|
||||||
|
password = PasswordField("Password", validators=[DataRequired()])
|
||||||
|
password_confirm = PasswordField("Confirm Password",
|
||||||
|
validators=[DataRequired()])
|
||||||
|
|
0
goathacks/templates/.gitkeep
Normal file
0
goathacks/templates/.gitkeep
Normal file
|
@ -4,6 +4,7 @@ Flask==2.2.2
|
||||||
Flask-Login==0.6.2
|
Flask-Login==0.6.2
|
||||||
Flask-Migrate==4.0.0
|
Flask-Migrate==4.0.0
|
||||||
Flask-SQLAlchemy==3.0.2
|
Flask-SQLAlchemy==3.0.2
|
||||||
|
Flask-WTF==1.0.1
|
||||||
greenlet==2.0.1
|
greenlet==2.0.1
|
||||||
itsdangerous==2.1.2
|
itsdangerous==2.1.2
|
||||||
Jinja2==3.1.2
|
Jinja2==3.1.2
|
||||||
|
@ -17,3 +18,4 @@ python-dotenv==0.21.0
|
||||||
SQLAlchemy==1.4.44
|
SQLAlchemy==1.4.44
|
||||||
uWSGI==2.0.21
|
uWSGI==2.0.21
|
||||||
Werkzeug==2.2.2
|
Werkzeug==2.2.2
|
||||||
|
WTForms==3.0.1
|
||||||
|
|
Loading…
Add table
Reference in a new issue
@willhockey20 is this something that actually needs to be stored? I only included it bc it was in the original registration system.