app.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from flask import Flask, render_template
  2. from flask_bootstrap import Bootstrap
  3. from flask_wtf import FlaskForm
  4. from wtforms import SubmitField, PasswordField, EmailField
  5. from wtforms.validators import DataRequired, Email, Length
  6. app = Flask(__name__)
  7. app.secret_key = "any-string-you-want-just-keep-it-secret"
  8. Bootstrap(app)
  9. class Credendials():
  10. EMAIL = 'sasha@admin.com'
  11. PASSWORD = 'password'
  12. def is_match_credentials(email: str, password: str) -> bool:
  13. if email == Credendials.EMAIL and password == Credendials.PASSWORD:
  14. return True
  15. return False
  16. class MyForm(FlaskForm):
  17. email = EmailField('Email', validators=[DataRequired(), Email()])
  18. password = PasswordField('Password', validators=[DataRequired(), Length(8)])
  19. submit = SubmitField(label='Send')
  20. @app.route("/")
  21. def home():
  22. return render_template('index.html')
  23. @app.route("/login", methods=["GET", "POST"])
  24. def login():
  25. login_form = MyForm()
  26. is_valid = login_form.validate_on_submit()
  27. if is_valid:
  28. if is_match_credentials(login_form.email.data, login_form.password.data):
  29. return render_template('success.html')
  30. else:
  31. return render_template('denied.html')
  32. return render_template('login.html', form=login_form)
  33. if __name__ == '__main__':
  34. app.run(debug=True)