-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 74eb67f
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, PasswordField, SubmitField, BooleanField, validators | ||
from wtforms.fields.html5 import EmailField | ||
from wtforms.validators import DataRequired, Length, email_validator, EqualTo | ||
|
||
|
||
class RegistrationForm(FlaskForm): | ||
username = StringField('Username', | ||
validators=[DataRequired(), Length(min=2, max=20)]) | ||
email = EmailField('Email', [validators.DataRequired(), validators.Email()]) | ||
password = PasswordField('Password', validators=[DataRequired()]) | ||
confirm_password = PasswordField('Confirm Password', | ||
validators=[DataRequired(), EqualTo('password')]) | ||
submit = SubmitField('Sign Up') | ||
|
||
|
||
class LoginForm(FlaskForm): | ||
email = EmailField('Email', [validators.DataRequired(), validators.Email()]) | ||
password = PasswordField('Password', validators=[DataRequired()]) | ||
remember = BooleanField('Remember Me') | ||
submit = SubmitField('Login') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from flask import Flask, render_template, url_for, flash, redirect | ||
from forms import RegistrationForm, LoginForm | ||
|
||
app = Flask(__name__) | ||
app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' | ||
|
||
posts = [ | ||
{ | ||
'author': 'Corey Schafer', | ||
'title': 'Blog Post 1', | ||
'content': 'First post content', | ||
'date_posted': 'April 20, 2018' | ||
}, | ||
{ | ||
'author': 'Jane Doe', | ||
'title': 'Blog Post 2', | ||
'content': 'Second post content', | ||
'date_posted': 'April 21, 2018' | ||
} | ||
] | ||
|
||
|
||
@app.route("/") | ||
@app.route("/home") | ||
def home(): | ||
return render_template('home.html', posts=posts) | ||
|
||
|
||
@app.route("/about") | ||
def about(): | ||
return render_template('about.html', title='About') | ||
|
||
|
||
@app.route("/register", methods=['GET', 'POST']) | ||
def register(): | ||
form = RegistrationForm() | ||
if form.validate_on_submit(): | ||
flash(f'Account created for {form.username.data}!', 'success') | ||
return redirect(url_for('home')) | ||
return render_template('register.html', title='Register', form=form) | ||
|
||
|
||
@app.route("/login", methods=['GET', 'POST']) | ||
def login(): | ||
form = LoginForm() | ||
if form.validate_on_submit(): | ||
if form.email.data == '[email protected]' and form.password.data == 'password': | ||
flash('You have been logged in!', 'success') | ||
return redirect(url_for('home')) | ||
else: | ||
flash('Login Unsuccessful. Please check username and password', 'danger') | ||
return render_template('login.html', title='Login', form=form) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |