-
-
Save awesomekimn/5d7a091e99b4ee32b898be6e6a8e3149 to your computer and use it in GitHub Desktop.
flask-secrets
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
{% extends "bootstrap/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 %} |
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
{% extends "bootstrap/base.html" %} | |
{% block title %}Secrets{% endblock %} | |
{% block content %} | |
<div class="jumbotron"> | |
<div class="container"> | |
<h1>Welcome</h1> | |
<p>Are you ready to discover my secret?</p> | |
<button class="btn btn-primary btn-lg" onclick="window.location.href='/login'">Login</button> | |
</div> | |
</div> | |
{% endblock %} |
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
{% extends "bootstrap/base.html" %} | |
{% import "bootstrap/wtf.html" as wtf %} | |
{% block title %}Login{% endblock %} | |
{% block content %} | |
<div class="container"> | |
<h1>Login</h1> | |
{{ wtf.quick_form(form, novalidate=True) }} | |
</div> | |
{% endblock %} |
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
from flask import Flask, render_template | |
from flask_bootstrap import Bootstrap | |
from flask_wtf import FlaskForm | |
from wtforms import StringField, PasswordField, SubmitField | |
from wtforms.validators import DataRequired, Email, Length | |
class LoginForm(FlaskForm): | |
email = StringField(label='Email', | |
validators=[DataRequired(), | |
Email(message="Invalid email address.")]) | |
password = PasswordField(label='Password', | |
validators=[DataRequired(), | |
Length(min=8, message="Field must be at least 8 characters long.")]) | |
submit = SubmitField(label='Log In') | |
app = Flask(__name__) | |
Bootstrap(app) | |
app.secret_key = "any-string-you-want-just-keep-it-secret" | |
@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) |
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
Flask==2.0.3 | |
Jinja2==3.1.1 |
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
{% extends "bootstrap/base.html" %} | |
{% block title %}Success{% 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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment