├── .gitignore ├── Contributing.md ├── LICENSE ├── README.md ├── app.py ├── forms.py ├── manage.py ├── migrations ├── README ├── __pycache__ │ └── env.cpython-39.pyc ├── alembic.ini ├── env.py └── script.py.mako ├── models.py ├── requirements.txt ├── routes.py ├── run ├── static ├── login.png └── register.png └── templates ├── auth.html ├── base.html └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | /__pycache__ 2 | *.db 3 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions with the project. 7 | 8 | ## Pull Request Process 9 | 10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a 11 | build. 12 | 2. Update the README.md with details of changes to the interface, this includes new environment 13 | variables, exposed ports, useful file locations and container parameters. 14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this 15 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 16 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you 17 | do not have permission to do that, you may request the second reviewer to merge it for you. 18 | 19 | ## Code of Conduct 20 | 21 | ### Our Pledge 22 | 23 | In the interest of fostering an open and welcoming environment, we as 24 | contributors and maintainers pledge to making participation in our project and 25 | our community a harassment-free experience for everyone, regardless of age, body 26 | size, disability, ethnicity, gender identity and expression, level of experience, 27 | nationality, personal appearance, race, religion, or sexual identity and 28 | orientation. 29 | 30 | ### Our Standards 31 | 32 | Examples of behavior that contributes to creating a positive environment 33 | include: 34 | 35 | * Using welcoming and inclusive language 36 | * Being respectful of differing viewpoints and experiences 37 | * Gracefully accepting constructive criticism 38 | * Focusing on what is best for the community 39 | * Showing empathy towards other community members 40 | 41 | Examples of unacceptable behavior by participants include: 42 | 43 | * The use of sexualized language or imagery and unwelcome sexual attention or 44 | advances 45 | * Trolling, insulting/derogatory comments, and personal or political attacks 46 | * Public or private harassment 47 | * Publishing others' private information, such as a physical or electronic 48 | address, without explicit permission 49 | * Other conduct which could reasonably be considered inappropriate in a 50 | professional setting 51 | 52 | ### Our Responsibilities 53 | 54 | Project maintainers are responsible for clarifying the standards of acceptable 55 | behavior and are expected to take appropriate and fair corrective action in 56 | response to any instances of unacceptable behavior. 57 | 58 | Project maintainers have the right and responsibility to remove, edit, or 59 | reject comments, commits, code, wiki edits, issues, and other contributions 60 | that are not aligned to this Code of Conduct, or to ban temporarily or 61 | permanently any contributor for other behaviors that they deem inappropriate, 62 | threatening, offensive, or harmful. 63 | 64 | ### Scope 65 | 66 | This Code of Conduct applies both within project spaces and in public spaces 67 | when an individual is representing the project or its community. Examples of 68 | representing a project or community include using an official project e-mail 69 | address, posting via an official social media account, or acting as an appointed 70 | representative at an online or offline event. Representation of a project may be 71 | further defined and clarified by project maintainers. 72 | 73 | ### Enforcement 74 | 75 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 76 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 77 | complaints will be reviewed and investigated and will result in a response that 78 | is deemed necessary and appropriate to the circumstances. The project team is 79 | obligated to maintain confidentiality with regard to the reporter of an incident. 80 | Further details of specific enforcement policies may be posted separately. 81 | 82 | Project maintainers who do not follow or enforce the Code of Conduct in good 83 | faith may face temporary or permanent repercussions as determined by other 84 | members of the project's leadership. 85 | 86 | ### Attribution 87 | 88 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 89 | available at [http://contributor-covenant.org/version/1/4][version] 90 | 91 | [homepage]: http://contributor-covenant.org 92 | [version]: http://contributor-covenant.org/version/1/4/ 93 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 ONDIEK ELIJAH OCHIENG 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # User-Authentication-in-Flask 2 | 3 | ## Set up & Installation. 4 | 5 | ### 1 .Clone/Fork the git repo and create an environment 6 | 7 | **Windows** 8 | 9 | ```bash 10 | git clone https://github.com/Dev-Elie/User-Authentication-in-Flask.git 11 | cd User-Authentication-in-Flask 12 | py -3 -m venv venv 13 | 14 | ``` 15 | 16 | **macOS/Linux** 17 | 18 | ```bash 19 | git clone https://github.com/Dev-Elie/User-Authentication-in-Flask.git 20 | cd User-Authentication-in-Flask 21 | python3 -m venv venv 22 | 23 | ``` 24 | 25 | ### 2 .Activate the environment 26 | 27 | **Windows** 28 | 29 | ```venv\Scripts\activate``` 30 | 31 | **macOS/Linux** 32 | 33 | ```. venv/bin/activate``` 34 | or 35 | ```source venv/bin/activate``` 36 | 37 | ### 3 .Install the requirements 38 | 39 | Applies for windows/macOS/Linux 40 | 41 | ``` 42 | pip install -r requirements.txt 43 | ``` 44 | ### 4 .Migrate/Create a database 45 | 46 | ```python manage.py``` 47 | 48 | ### 5. Run the application 49 | 50 | **For linux and macOS** 51 | Make the run file executable by running the code 52 | 53 | ```chmod 777 run``` 54 | 55 | Then start the application by executing the run file 56 | 57 | ```./run``` 58 | 59 | **On windows** 60 | ``` 61 | set FLASK_APP=routes 62 | flask run 63 | ``` 64 | 65 | Login | Register 66 | :-------------------------:|:-------------------------: 67 | ![Sample](https://github.com/Dev-Elie/User-Authentication-in-Flask/blob/main/static/login.png) | ![Sample](https://github.com/Dev-Elie/User-Authentication-in-Flask/blob/main/static/register.png) 68 | 69 |
70 |

Follow me on Twitter

71 |

dev_elie

72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask_sqlalchemy import SQLAlchemy 3 | from flask_bcrypt import Bcrypt 4 | from flask_migrate import Migrate 5 | 6 | from flask_login import ( 7 | UserMixin, 8 | login_user, 9 | LoginManager, 10 | current_user, 11 | logout_user, 12 | login_required, 13 | ) 14 | 15 | login_manager = LoginManager() 16 | login_manager.session_protection = "strong" 17 | login_manager.login_view = "login" 18 | login_manager.login_message_category = "info" 19 | 20 | db = SQLAlchemy() 21 | migrate = Migrate() 22 | bcrypt = Bcrypt() 23 | 24 | 25 | def create_app(): 26 | app = Flask(__name__) 27 | 28 | app.secret_key = 'secret-key' 29 | app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///database.db" 30 | app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True 31 | 32 | login_manager.init_app(app) 33 | db.init_app(app) 34 | migrate.init_app(app, db) 35 | bcrypt.init_app(app) 36 | 37 | return app -------------------------------------------------------------------------------- /forms.py: -------------------------------------------------------------------------------- 1 | from wtforms import ( 2 | StringField, 3 | PasswordField, 4 | BooleanField, 5 | IntegerField, 6 | DateField, 7 | TextAreaField, 8 | ) 9 | 10 | from flask_wtf import FlaskForm 11 | from wtforms.validators import InputRequired, Length, EqualTo, Email, Regexp ,Optional 12 | import email_validator 13 | from flask_login import current_user 14 | from wtforms import ValidationError,validators 15 | from models import User 16 | 17 | 18 | class login_form(FlaskForm): 19 | email = StringField(validators=[InputRequired(), Email(), Length(1, 64)]) 20 | pwd = PasswordField(validators=[InputRequired(), Length(min=8, max=72)]) 21 | # Placeholder labels to enable form rendering 22 | username = StringField( 23 | validators=[Optional()] 24 | ) 25 | 26 | 27 | class register_form(FlaskForm): 28 | username = StringField( 29 | validators=[ 30 | InputRequired(), 31 | Length(3, 20, message="Please provide a valid name"), 32 | Regexp( 33 | "^[A-Za-z][A-Za-z0-9_.]*$", 34 | 0, 35 | "Usernames must have only letters, " "numbers, dots or underscores", 36 | ), 37 | ] 38 | ) 39 | email = StringField(validators=[InputRequired(), Email(), Length(1, 64)]) 40 | pwd = PasswordField(validators=[InputRequired(), Length(8, 72)]) 41 | cpwd = PasswordField( 42 | validators=[ 43 | InputRequired(), 44 | Length(8, 72), 45 | EqualTo("pwd", message="Passwords must match !"), 46 | ] 47 | ) 48 | 49 | 50 | def validate_email(self, email): 51 | if User.query.filter_by(email=email.data).first(): 52 | raise ValidationError("Email already registered!") 53 | 54 | def validate_uname(self, uname): 55 | if User.query.filter_by(username=username.data).first(): 56 | raise ValidationError("Username already taken!") -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | 2 | def deploy(): 3 | """Run deployment tasks.""" 4 | from app import create_app,db 5 | from flask_migrate import upgrade,migrate,init,stamp 6 | from models import User 7 | 8 | app = create_app() 9 | app.app_context().push() 10 | db.create_all() 11 | 12 | # migrate database to latest revision 13 | init() 14 | stamp() 15 | migrate() 16 | upgrade() 17 | 18 | deploy() 19 | -------------------------------------------------------------------------------- /migrations/README: -------------------------------------------------------------------------------- 1 | Single-database configuration for Flask. 2 | -------------------------------------------------------------------------------- /migrations/__pycache__/env.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bestdev322/User-Authentication-in-Flask/8bd24e0e18f03d007bfb4423e4def1e6bc98698f/migrations/__pycache__/env.cpython-39.pyc -------------------------------------------------------------------------------- /migrations/alembic.ini: -------------------------------------------------------------------------------- 1 | # A generic, single database configuration. 2 | 3 | [alembic] 4 | # template used to generate migration files 5 | # file_template = %%(rev)s_%%(slug)s 6 | 7 | # set to 'true' to run the environment during 8 | # the 'revision' command, regardless of autogenerate 9 | # revision_environment = false 10 | 11 | 12 | # Logging configuration 13 | [loggers] 14 | keys = root,sqlalchemy,alembic,flask_migrate 15 | 16 | [handlers] 17 | keys = console 18 | 19 | [formatters] 20 | keys = generic 21 | 22 | [logger_root] 23 | level = WARN 24 | handlers = console 25 | qualname = 26 | 27 | [logger_sqlalchemy] 28 | level = WARN 29 | handlers = 30 | qualname = sqlalchemy.engine 31 | 32 | [logger_alembic] 33 | level = INFO 34 | handlers = 35 | qualname = alembic 36 | 37 | [logger_flask_migrate] 38 | level = INFO 39 | handlers = 40 | qualname = flask_migrate 41 | 42 | [handler_console] 43 | class = StreamHandler 44 | args = (sys.stderr,) 45 | level = NOTSET 46 | formatter = generic 47 | 48 | [formatter_generic] 49 | format = %(levelname)-5.5s [%(name)s] %(message)s 50 | datefmt = %H:%M:%S 51 | -------------------------------------------------------------------------------- /migrations/env.py: -------------------------------------------------------------------------------- 1 | from __future__ import with_statement 2 | 3 | import logging 4 | from logging.config import fileConfig 5 | 6 | from flask import current_app 7 | 8 | from alembic import context 9 | 10 | # this is the Alembic Config object, which provides 11 | # access to the values within the .ini file in use. 12 | config = context.config 13 | 14 | # Interpret the config file for Python logging. 15 | # This line sets up loggers basically. 16 | fileConfig(config.config_file_name) 17 | logger = logging.getLogger('alembic.env') 18 | 19 | # add your model's MetaData object here 20 | # for 'autogenerate' support 21 | # from myapp import mymodel 22 | # target_metadata = mymodel.Base.metadata 23 | config.set_main_option( 24 | 'sqlalchemy.url', 25 | str(current_app.extensions['migrate'].db.get_engine().url).replace( 26 | '%', '%%')) 27 | target_metadata = current_app.extensions['migrate'].db.metadata 28 | 29 | # other values from the config, defined by the needs of env.py, 30 | # can be acquired: 31 | # my_important_option = config.get_main_option("my_important_option") 32 | # ... etc. 33 | 34 | 35 | def run_migrations_offline(): 36 | """Run migrations in 'offline' mode. 37 | 38 | This configures the context with just a URL 39 | and not an Engine, though an Engine is acceptable 40 | here as well. By skipping the Engine creation 41 | we don't even need a DBAPI to be available. 42 | 43 | Calls to context.execute() here emit the given string to the 44 | script output. 45 | 46 | """ 47 | url = config.get_main_option("sqlalchemy.url") 48 | context.configure( 49 | url=url, target_metadata=target_metadata, literal_binds=True 50 | ) 51 | 52 | with context.begin_transaction(): 53 | context.run_migrations() 54 | 55 | 56 | def run_migrations_online(): 57 | """Run migrations in 'online' mode. 58 | 59 | In this scenario we need to create an Engine 60 | and associate a connection with the context. 61 | 62 | """ 63 | 64 | # this callback is used to prevent an auto-migration from being generated 65 | # when there are no changes to the schema 66 | # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html 67 | def process_revision_directives(context, revision, directives): 68 | if getattr(config.cmd_opts, 'autogenerate', False): 69 | script = directives[0] 70 | if script.upgrade_ops.is_empty(): 71 | directives[:] = [] 72 | logger.info('No changes in schema detected.') 73 | 74 | connectable = current_app.extensions['migrate'].db.get_engine() 75 | 76 | with connectable.connect() as connection: 77 | context.configure( 78 | connection=connection, 79 | target_metadata=target_metadata, 80 | process_revision_directives=process_revision_directives, 81 | **current_app.extensions['migrate'].configure_args 82 | ) 83 | 84 | with context.begin_transaction(): 85 | context.run_migrations() 86 | 87 | 88 | if context.is_offline_mode(): 89 | run_migrations_offline() 90 | else: 91 | run_migrations_online() 92 | -------------------------------------------------------------------------------- /migrations/script.py.mako: -------------------------------------------------------------------------------- 1 | """${message} 2 | 3 | Revision ID: ${up_revision} 4 | Revises: ${down_revision | comma,n} 5 | Create Date: ${create_date} 6 | 7 | """ 8 | from alembic import op 9 | import sqlalchemy as sa 10 | ${imports if imports else ""} 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = ${repr(up_revision)} 14 | down_revision = ${repr(down_revision)} 15 | branch_labels = ${repr(branch_labels)} 16 | depends_on = ${repr(depends_on)} 17 | 18 | 19 | def upgrade(): 20 | ${upgrades if upgrades else "pass"} 21 | 22 | 23 | def downgrade(): 24 | ${downgrades if downgrades else "pass"} 25 | -------------------------------------------------------------------------------- /models.py: -------------------------------------------------------------------------------- 1 | from app import db 2 | from flask_login import UserMixin 3 | 4 | class User(UserMixin, db.Model): 5 | __tablename__ = "user" 6 | 7 | id = db.Column(db.Integer, primary_key=True) 8 | username = db.Column(db.String(80), unique=True, nullable=False) 9 | email = db.Column(db.String(120), unique=True, nullable=False) 10 | pwd = db.Column(db.String(300), nullable=False, unique=True) 11 | 12 | def __repr__(self): 13 | return '' % self.username -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | alembic==1.6.5 2 | bcrypt==3.2.0 3 | cffi==1.15.0 4 | click==8.0.1 5 | dnspython==2.1.0 6 | email-validator==1.1.3 7 | Flask==2.0.1 8 | Flask-Bcrypt==0.7.1 9 | Flask-Login==0.5.0 10 | Flask-Migrate==3.1.0 11 | Flask-SQLAlchemy==2.5.1 12 | Flask-WTF==0.15.1 13 | greenlet==1.1.1 14 | idna==3.2 15 | itsdangerous==2.0.1 16 | Jinja2==3.0.1 17 | Mako==1.1.5 18 | MarkupSafe==2.0.1 19 | pycparser==2.20 20 | python-dateutil==2.8.2 21 | python-editor==1.0.4 22 | six==1.16.0 23 | SQLAlchemy==1.4.23 24 | Werkzeug==2.0.1 25 | WTForms==2.3.3 26 | -------------------------------------------------------------------------------- /routes.py: -------------------------------------------------------------------------------- 1 | from flask import ( 2 | Flask, 3 | render_template, 4 | redirect, 5 | flash, 6 | url_for, 7 | session 8 | ) 9 | 10 | from datetime import timedelta 11 | from sqlalchemy.exc import ( 12 | IntegrityError, 13 | DataError, 14 | DatabaseError, 15 | InterfaceError, 16 | InvalidRequestError, 17 | ) 18 | from werkzeug.routing import BuildError 19 | 20 | 21 | from flask_bcrypt import Bcrypt,generate_password_hash, check_password_hash 22 | 23 | from flask_login import ( 24 | UserMixin, 25 | login_user, 26 | LoginManager, 27 | current_user, 28 | logout_user, 29 | login_required, 30 | ) 31 | 32 | from app import create_app,db,login_manager,bcrypt 33 | from models import User 34 | from forms import login_form,register_form 35 | 36 | 37 | @login_manager.user_loader 38 | def load_user(user_id): 39 | return User.query.get(int(user_id)) 40 | 41 | app = create_app() 42 | 43 | @app.before_request 44 | def session_handler(): 45 | session.permanent = True 46 | app.permanent_session_lifetime = timedelta(minutes=1) 47 | 48 | @app.route("/", methods=("GET", "POST"), strict_slashes=False) 49 | def index(): 50 | return render_template("index.html",title="Home") 51 | 52 | 53 | @app.route("/login/", methods=("GET", "POST"), strict_slashes=False) 54 | def login(): 55 | form = login_form() 56 | 57 | if form.validate_on_submit(): 58 | try: 59 | user = User.query.filter_by(email=form.email.data).first() 60 | if check_password_hash(user.pwd, form.pwd.data): 61 | login_user(user) 62 | return redirect(url_for('index')) 63 | else: 64 | flash("Invalid Username or password!", "danger") 65 | except Exception as e: 66 | flash(e, "danger") 67 | 68 | return render_template("auth.html", 69 | form=form, 70 | text="Login", 71 | title="Login", 72 | btn_action="Login" 73 | ) 74 | 75 | 76 | 77 | # Register route 78 | @app.route("/register/", methods=("GET", "POST"), strict_slashes=False) 79 | def register(): 80 | form = register_form() 81 | if form.validate_on_submit(): 82 | try: 83 | email = form.email.data 84 | pwd = form.pwd.data 85 | username = form.username.data 86 | 87 | newuser = User( 88 | username=username, 89 | email=email, 90 | pwd=bcrypt.generate_password_hash(pwd), 91 | ) 92 | 93 | db.session.add(newuser) 94 | db.session.commit() 95 | flash(f"Account Succesfully created", "success") 96 | return redirect(url_for("login")) 97 | 98 | except InvalidRequestError: 99 | db.session.rollback() 100 | flash(f"Something went wrong!", "danger") 101 | except IntegrityError: 102 | db.session.rollback() 103 | flash(f"User already exists!.", "warning") 104 | except DataError: 105 | db.session.rollback() 106 | flash(f"Invalid Entry", "warning") 107 | except InterfaceError: 108 | db.session.rollback() 109 | flash(f"Error connecting to the database", "danger") 110 | except DatabaseError: 111 | db.session.rollback() 112 | flash(f"Error connecting to the database", "danger") 113 | except BuildError: 114 | db.session.rollback() 115 | flash(f"An error occured !", "danger") 116 | return render_template("auth.html", 117 | form=form, 118 | text="Create account", 119 | title="Register", 120 | btn_action="Register account" 121 | ) 122 | 123 | @app.route("/logout") 124 | @login_required 125 | def logout(): 126 | logout_user() 127 | return redirect(url_for('login')) 128 | 129 | 130 | if __name__ == "__main__": 131 | app.run(debug=True) 132 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | FLASK_APP=routes.py FLASK_DEBUG=1 FLASK_ENV=development flask run -------------------------------------------------------------------------------- /static/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bestdev322/User-Authentication-in-Flask/8bd24e0e18f03d007bfb4423e4def1e6bc98698f/static/login.png -------------------------------------------------------------------------------- /static/register.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bestdev322/User-Authentication-in-Flask/8bd24e0e18f03d007bfb4423e4def1e6bc98698f/static/register.png -------------------------------------------------------------------------------- /templates/auth.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block title%} {{ title }} {% endblock %} 3 | {% block content%} 4 |
5 |
6 |
7 |
8 | {{ form.csrf_token }} 9 | 10 | {% with messages = get_flashed_messages(with_categories=true) %} 11 | 12 | {% if messages %} 13 | {% for category, message in messages %} 14 | 18 | {% endfor %} 19 | {% endif %} 20 | {% endwith %} 21 | 22 |
23 |

User Authentication in Flask

24 |
{{ text }}
25 |
26 | 27 | {% if request.path == '/register/' %} 28 |
29 | {{ form.username(class_="form-control",placeholder="Username")}} 30 |
31 | {% for error in form.username.errors %} 32 | 36 | {% endfor%} 37 | {% endif%} 38 |
39 | {{ form.email(class_="form-control",placeholder="Email")}} 40 |
41 | {% for error in form.email.errors %} 42 | 46 | {% endfor%} 47 |
48 | {{ form.pwd(class_="form-control",placeholder="Password")}} 49 |
50 | {% for error in form.pwd.errors %} 51 | {% endfor%} 55 | {% if request.path == '/register/' %} 56 |
57 | {{ form.cpwd(class_="form-control",placeholder="Confirm Password")}} 58 |
59 | {% for error in form.cpwd.errors %} 60 | {% endfor%} 64 | {% endif %} 65 |
66 | 67 |
68 | 69 |
70 | 71 |

72 | {% if request.path != '/register/' %} 73 | New here? 74 | Create account 75 | {% else %} 76 | Already have an account? 77 | Login 78 | {% endif %} 79 |

80 | 81 |
82 |
83 |
84 |
85 |
86 | {% endblock %} -------------------------------------------------------------------------------- /templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | {% block title%} {{ title }} {% endblock %} 13 | 14 | 15 | 16 |
17 | {% block content%} 18 | {% endblock %} 19 |
20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | {% block title%} {{ title }} {% endblock %} 3 | {% block content%} 4 | 5 |
6 | 7 | 8 | {% if current_user.is_authenticated %} 9 | 10 |

Welcome {{ current_user.username }}

11 | Logout 12 | 13 | {% else %} 14 | 15 | Sign in/Sign Up 16 | 17 | {% endif %} 18 |
19 | {% endblock %} --------------------------------------------------------------------------------