Added FlaskSecrets
This commit is contained in:
parent
2e029b0d13
commit
4a58e1be4e
48
Visual Studio Code Projects/day-61-flask-secrets-end/main.py
Normal file
48
Visual Studio Code Projects/day-61-flask-secrets-end/main.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
from flask import Flask, render_template
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
|
from wtforms import StringField, PasswordField, SubmitField
|
||||||
|
from wtforms.validators import DataRequired, Email, Length # pip install email-validator
|
||||||
|
from flask_bootstrap import Bootstrap5 # pip install bootstrap-flask
|
||||||
|
|
||||||
|
'''
|
||||||
|
Red underlines? Install the required packages first:
|
||||||
|
Open the Terminal in PyCharm (bottom left).
|
||||||
|
|
||||||
|
On Windows type:
|
||||||
|
python -m pip install -r requirements.txt
|
||||||
|
|
||||||
|
On MacOS type:
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
This will install the packages from requirements.txt for this project.
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
class LoginForm(FlaskForm):
|
||||||
|
email = StringField('Email', validators=[DataRequired()])
|
||||||
|
password = PasswordField('Password', validators=[DataRequired()])
|
||||||
|
submit = SubmitField(label="Log In")
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.secret_key = "any-string-you-want-just-keep-it-secret"
|
||||||
|
bootstrap = Bootstrap5(app)
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def home():
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/login", methods=["GET", "POST"])
|
||||||
|
def login():
|
||||||
|
login_form = LoginForm()
|
||||||
|
if login_form.validate_on_submit():
|
||||||
|
if login_form.email.data == "admin@email.com" and login_form.password.data == "12345678":
|
||||||
|
return render_template("success.html")
|
||||||
|
else:
|
||||||
|
return render_template("denied.html")
|
||||||
|
return render_template("login.html", form=login_form)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True, port=5001)
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
Bootstrap_Flask==2.2.0
|
||||||
|
Flask==2.3.2
|
||||||
|
WTForms==3.0.1
|
||||||
|
Flask_WTF==1.2.1
|
||||||
|
Werkzeug==3.0.0
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
|
||||||
|
{% block styles %}
|
||||||
|
<!-- Bootstrap CSS -->
|
||||||
|
{{ bootstrap.load_css() }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Access Denied{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>Access Denied </h1>
|
||||||
|
<iframe src="https://giphy.com/embed/1xeVd1vr43nHO" width="480" height="271" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
|
||||||
|
<p><a href="https://giphy.com/gifs/cheezburger-funny-dog-fails-1xeVd1vr43nHO">via GIPHY</a></p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Secrets{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<!--Using Boostrap classes for styling here-->
|
||||||
|
<div class="jumbotron">
|
||||||
|
<div class="container">
|
||||||
|
<h1>Welcome</h1>
|
||||||
|
<p>Are you ready to discover my secret?</p>
|
||||||
|
<a class="btn btn-primary btn-lg" href=" {{ url_for('login') }} ">Login</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% from 'bootstrap5/form.html' import render_form %}
|
||||||
|
{% block title %}Login{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>Login</h1>
|
||||||
|
{{ render_form(form) }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Access Granted{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>Top Secret </h1>
|
||||||
|
<iframe src="https://giphy.com/embed/Ju7l5y9osyymQ" width="480" height="360" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
|
||||||
|
<p><a href="https://giphy.com/gifs/rick-astley-Ju7l5y9osyymQ">via GIPHY</a></p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
from flask import Flask, render_template
|
||||||
|
|
||||||
|
'''
|
||||||
|
Red underlines? Install the required packages first:
|
||||||
|
Open the Terminal in PyCharm (bottom left).
|
||||||
|
|
||||||
|
On Windows type:
|
||||||
|
python -m pip install -r requirements.txt
|
||||||
|
|
||||||
|
On MacOS type:
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
This will install the packages from requirements.txt for this project.
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def home():
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
Bootstrap_Flask==2.2.0
|
||||||
|
Flask==2.3.2
|
||||||
|
WTForms==3.0.1
|
||||||
|
Flask_WTF==1.2.1
|
||||||
|
Werkzeug==3.0.0
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Access Denied</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Access Denied </h1>
|
||||||
|
<iframe src="https://giphy.com/embed/1xeVd1vr43nHO" width="480" height="271" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
|
||||||
|
<p><a href="https://giphy.com/gifs/cheezburger-funny-dog-fails-1xeVd1vr43nHO">via GIPHY</a></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Secrets</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="jumbotron">
|
||||||
|
<div class="container">
|
||||||
|
<h1>Welcome</h1>
|
||||||
|
<p>Are you ready to discover my secret?</p>
|
||||||
|
<a class="btn btn-primary btn-lg" href=" {{ url_for('login') }} "
|
||||||
|
>Login</a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Login</h1>
|
||||||
|
<!-- This is where our form will go. -->
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Success</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Top Secret </h1>
|
||||||
|
<iframe src="https://giphy.com/embed/Ju7l5y9osyymQ" width="480" height="360" frameBorder="0" class="giphy-embed" allowFullScreen></iframe>
|
||||||
|
<p><a href="https://giphy.com/gifs/rick-astley-Ju7l5y9osyymQ">via GIPHY</a></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user