From 472dace1566581ccc6b2332778daa925e1ba0c01 Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Wed, 8 Mar 2023 11:43:10 +1100 Subject: [PATCH] It works --- .gitignore | 8 ++ __init__.py | 42 ++++++++ __pycache__/__init__.cpython-310.pyc | Bin 0 -> 742 bytes __pycache__/auth.cpython-310.pyc | Bin 0 -> 673 bytes __pycache__/main.cpython-310.pyc | Bin 0 -> 542 bytes __pycache__/models.cpython-310.pyc | Bin 0 -> 500 bytes auth.py | 67 ++++++++++++ chatbot.py | 132 ++++++++++++++++++++++++ config/__init__.py | 0 config/db.py.sample | 1 + main.py | 146 +++------------------------ models.py | 9 ++ requirements.txt | 5 +- templates/base.html | 56 ++++++++++ templates/index.html | 10 ++ templates/login.html | 36 +++++++ templates/profile.html | 8 ++ templates/signup.html | 42 ++++++++ 18 files changed, 427 insertions(+), 135 deletions(-) create mode 100644 __init__.py create mode 100644 __pycache__/__init__.cpython-310.pyc create mode 100644 __pycache__/auth.cpython-310.pyc create mode 100644 __pycache__/main.cpython-310.pyc create mode 100644 __pycache__/models.cpython-310.pyc create mode 100644 auth.py create mode 100644 chatbot.py create mode 100644 config/__init__.py create mode 100644 config/db.py.sample create mode 100644 models.py create mode 100644 templates/base.html create mode 100644 templates/index.html create mode 100644 templates/login.html create mode 100644 templates/profile.html create mode 100644 templates/signup.html diff --git a/.gitignore b/.gitignore index 1da188f..ec9d63a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,16 @@ # Configs config/service-acct.json +config/db.py # Logs *.log # JetBrains stuff .idea/ + +# Python stuff +__pycache__/ +venv/ + +# Secrets +*.secret diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..3c60dd7 --- /dev/null +++ b/__init__.py @@ -0,0 +1,42 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from flask_login import LoginManager +from .config import db as db_config + +db = SQLAlchemy() + +def create_app(): + app = Flask(__name__) + + app.config['SECRET_KEY'] = '//' + app.config["SQLALCHEMY_DATABASE_URI"] = db_config.SQL_URI + + db.init_app(app) + login_manager = LoginManager() + login_manager.login_view = 'auth.login' + login_manager.init_app(app) + + from .models import User + + @login_manager.user_loader + def load_user(user_id): + return User.query.get(int(user_id)) + + from . import models + with app.app_context(): + print("Applying the DB models") + db.create_all() + + # blueprint for auth routes in our app + from .auth import auth as auth_blueprint + app.register_blueprint(auth_blueprint) + + # blueprint for non-auth parts of app + from .main import main as main_blueprint + app.register_blueprint(main_blueprint) + + # blueprint for chatbot + from .chatbot import chatbot as chatbot_blueprint + app.register_blueprint(chatbot_blueprint) + + return app diff --git a/__pycache__/__init__.cpython-310.pyc b/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35d6fc6a31e27d2bcdc865cab0a72bf75c93922b GIT binary patch literal 742 zcmYjP&2G~`5T5m49LKFnIUpfkAPCh0ZYZiqQzH^8^1dkie$#KMWSQ>mW9AY z8=+M{&?!)4MV45rhBJd117K#0tN|$V!m44d>)Xr`cIGS**KpBU!*`$PxVr`dA5fo# z-wM^`?qjGPeLIRHvZn|ieA=RVh-Nu)uukJ0lVoQo*O}cErg?^ z@R+_1C+Byo&mvX)Sr7zlx^umW?&%&6MlZuR6S_Y<9_|gtA$@=J>XKkzI0Gju7#9^H zE1s*F{%3KT_kF47+_;qHamFcaoTSK4($mIZ)5uNpRMEIB8<38s^$=4eDE?JNULtv{ zIE{sn9Ua}4{4}i;mvk!Typ(CKq@HizYD`RQuZT8v`5QvCsb$>ke}de?l&hz~tjKsU z<$17QB=d~tstVr9;*2LPNE5!;E7X&K(pDthDHqLuMP;ewR`=1l#4|iJUwiW4w{LmG zH$7q*avQ^keW$Tc^h0R}5pA`Y;#A}77b8t%$)0wa->SRi?%-MD4sg12!FTnrE8VgW IK5?+-9~$Ygvj6}9 literal 0 HcmV?d00001 diff --git a/__pycache__/auth.cpython-310.pyc b/__pycache__/auth.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9a55c0495f02b64804407ec7b2e02b6382a24385 GIT binary patch literal 673 zcma)3Jx{|h5Vf7}q#p==MV3ZlMhF$=3W+UCNMq9m;v{mMpd<72-I>oTLOJN~l#?+)izb z7^XIJb|iI~`{GgO6;qdb&uE8J-*kNF1T-|Az;q($jOf^OLOQua@pKO?C?+bHS3PS* zSxYq)tfow4lJU06CEJ5c6k|o`QrUSg*IPHKnpIgB`tGq2D6YXjd?=WzX#Wpnf z*;?}I4GTTu8xjE=CVVByy5THYvO2kGik`DtcFC=19$8_MvS6EeBhM4fK5IA1G4HvW zN^|-|L~v}qq$^i--~K90cmUIaq5)_W39a@=&5-F&Qtp7#xftm%h5#(U-t_VxECcW_ zmH{<6u;^?NN6LAq^6p9K3C+$F5)S0b&$2q_EX#!6fN}(gVP*qHpfE2TwtF;>f598t XSL{;%Xm<+X1dVV=d=g^c(mui8c@l?$ literal 0 HcmV?d00001 diff --git a/__pycache__/main.cpython-310.pyc b/__pycache__/main.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b4cce961642c0b89fe9d0de0374d03cbac1d6880 GIT binary patch literal 542 zcmZ`#y-ve05VoD4I%!&XjV_JEj1Vf!6%t#PD2=abAWkADk!aWQATahxcn7acosk$S z2F|7u9pEJ2&!@ZlzH>bqg#_*G(-&VD-%W994i?w=+BrHw1TBfA36(5iln5rA(vfcB zQUX-C;B8srga0xR-YXTp7(A0LO}IrkB7q1k5{ThFnM8ZsNhVAOv$BUq6;-Ft6jTCK z+JS7!tb;u@EmSkH(5}pi>OkY%jGY?8;s)ObN7tdqEyeY0z6lFl_B35}vfNQ+ZrKrK z4z}(P$E#XGynrgct@B<&)wS`RsvjV?Ns+^PR(BV%A)YpC?b&_4p)#DDsR+Y{$Bn9& zMG5~ZQ%0Fl6dgOQCKVw1tLG;hBBlq&Hmh}Hy2j|{lTdrhGHV}|p|=NVqC7Lf)3nMY oq^UCUw5RI611ryt{>j2GWi9#=uFNO5hT)tY5Z>$eBb?5r2T)H6B`vgeZuGArNh@SuU9&Uc8TFH;1Iw*8h-{{-teg z%umqD**oxK;LXl^yN{V=%H7>Iqv(J7VCa0e28KJYqe99#TRUb6~MRXXX+-;2>T_>^FSf0%yZXb4d%( zS<{AT~wHUIE)R#jtQhJ zk{qQpZ7K5-s?641DHm0eH8)C-)%cfXR^^3h-4silqB0@{ + + + + + + + Flask Auth Example + + + + +
+ +
+ +
+ +
+
+ {% block content %} + {% endblock %} +
+
+
+ + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..ce45b56 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,10 @@ +{% extends "base.html" %} + +{% block content %} +

+ Flask Login Example +

+

+ Easy authentication and authorization in Flask. +

+{% endblock %} \ No newline at end of file diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..a341451 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% block content %} +
+

Login

+
+ {% with messages = get_flashed_messages() %} + {% if messages %} +
+ {{ messages[0] }} +
+ {% endif %} + {% endwith %} +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+ +
+
+
+{% endblock %} diff --git a/templates/profile.html b/templates/profile.html new file mode 100644 index 0000000..12a799a --- /dev/null +++ b/templates/profile.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block content %} +

+ Welcome, {{ name }}!

+ Your google ID is {{ google_id }} +

+{% endblock %} diff --git a/templates/signup.html b/templates/signup.html new file mode 100644 index 0000000..bd21f73 --- /dev/null +++ b/templates/signup.html @@ -0,0 +1,42 @@ +{% extends "base.html" %} + +{% block content %} +
+

Sign Up

+
+ {% with messages = get_flashed_messages() %} + {% if messages %} +
+ {{ messages[0] }}. Go to login page . +
+ {% endif %} + {% endwith %} +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ + +
+
+
+{% endblock %}