commit 6b300fd30439edf713cf220ca97139199834a1e6 Author: muchwowmining Date: Sat Mar 12 12:23:22 2022 +0100 Commit diff --git a/TODO b/TODO new file mode 100644 index 0000000..6b924b6 --- /dev/null +++ b/TODO @@ -0,0 +1,5 @@ +remove Constraints.client_secret before publishing and make a backup of it!! + +Register new application new login.wownero.com + client_id = yellwowpages + client url = /authenticate diff --git a/classes/__init__.py b/classes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/classes/constraints.py b/classes/constraints.py new file mode 100644 index 0000000..c8c210f --- /dev/null +++ b/classes/constraints.py @@ -0,0 +1,8 @@ +from starlette.templating import Jinja2Templates + + +class Constraints: + templates = Jinja2Templates(directory='frontend/templates') + client_id = '' + client_secret = '' + uri = 'sqlite:///users.db' diff --git a/frontend/static/colors.css b/frontend/static/colors.css new file mode 100644 index 0000000..8d2537f --- /dev/null +++ b/frontend/static/colors.css @@ -0,0 +1,4 @@ +:root{ + --yellow: #ffcc00; + --purple: #ff2ad4; +} \ No newline at end of file diff --git a/frontend/static/icon.css b/frontend/static/icon.css new file mode 100644 index 0000000..0057b91 --- /dev/null +++ b/frontend/static/icon.css @@ -0,0 +1 @@ +.icon{box-sizing:border-box;display:inline-block;font-size:inherit;font-style:normal;height:1em;position:relative;text-indent:-9999px;vertical-align:middle;width:1em}.icon::after,.icon::before{content:"";display:block;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}.icon.icon-2x{font-size:1.6rem}.icon.icon-3x{font-size:2.4rem}.icon.icon-4x{font-size:3.2rem}.accordion .icon,.btn .icon,.menu .icon,.toast .icon{vertical-align:-10%}.btn-lg .icon{vertical-align:-15%}.icon-arrow-down::before,.icon-arrow-left::before,.icon-arrow-right::before,.icon-arrow-up::before,.icon-back::before,.icon-downward::before,.icon-forward::before,.icon-upward::before{border:.1rem solid currentColor;border-bottom:0;border-right:0;height:.65em;width:.65em}.icon-arrow-down::before{transform:translate(-50%,-75%) rotate(225deg)}.icon-arrow-left::before{transform:translate(-25%,-50%) rotate(-45deg)}.icon-arrow-right::before{transform:translate(-75%,-50%) rotate(135deg)}.icon-arrow-up::before{transform:translate(-50%,-25%) rotate(45deg)}.icon-back::after,.icon-forward::after{background:currentColor;height:.1rem;width:.8em}.icon-downward::after,.icon-upward::after{background:currentColor;height:.8em;width:.1rem}.icon-back::after{left:55%}.icon-back::before{transform:translate(-50%,-50%) rotate(-45deg)}.icon-downward::after{top:45%}.icon-downward::before{transform:translate(-50%,-50%) rotate(-135deg)}.icon-forward::after{left:45%}.icon-forward::before{transform:translate(-50%,-50%) rotate(135deg)}.icon-upward::after{top:55%}.icon-upward::before{transform:translate(-50%,-50%) rotate(45deg)}.icon-caret::before{border-left:.3em solid transparent;border-right:.3em solid transparent;border-top:.3em solid currentColor;height:0;transform:translate(-50%,-25%);width:0}.icon-menu::before{background:currentColor;box-shadow:0 -.35em,0 .35em;height:.1rem;width:100%}.icon-apps::before{background:currentColor;box-shadow:-.35em -.35em,-.35em 0,-.35em .35em,0 -.35em,0 .35em,.35em -.35em,.35em 0,.35em .35em;height:3px;width:3px}.icon-resize-horiz::after,.icon-resize-horiz::before,.icon-resize-vert::after,.icon-resize-vert::before{border:.1rem solid currentColor;border-bottom:0;border-right:0;height:.45em;width:.45em}.icon-resize-horiz::before,.icon-resize-vert::before{transform:translate(-50%,-90%) rotate(45deg)}.icon-resize-horiz::after,.icon-resize-vert::after{transform:translate(-50%,-10%) rotate(225deg)}.icon-resize-horiz::before{transform:translate(-90%,-50%) rotate(-45deg)}.icon-resize-horiz::after{transform:translate(-10%,-50%) rotate(135deg)}.icon-more-horiz::before,.icon-more-vert::before{background:currentColor;border-radius:50%;box-shadow:-.4em 0,.4em 0;height:3px;width:3px}.icon-more-vert::before{box-shadow:0 -.4em,0 .4em}.icon-cross::before,.icon-minus::before,.icon-plus::before{background:currentColor;height:.1rem;width:100%}.icon-cross::after,.icon-plus::after{background:currentColor;height:100%;width:.1rem}.icon-cross::before{width:100%}.icon-cross::after{height:100%}.icon-cross::after,.icon-cross::before{transform:translate(-50%,-50%) rotate(45deg)}.icon-check::before{border:.1rem solid currentColor;border-right:0;border-top:0;height:.5em;transform:translate(-50%,-75%) rotate(-45deg);width:.9em}.icon-stop{border:.1rem solid currentColor;border-radius:50%}.icon-stop::before{background:currentColor;height:.1rem;transform:translate(-50%,-50%) rotate(45deg);width:1em}.icon-shutdown{border:.1rem solid currentColor;border-radius:50%;border-top-color:transparent}.icon-shutdown::before{background:currentColor;content:"";height:.5em;top:.1em;width:.1rem}.icon-refresh::before{border:.1rem solid currentColor;border-radius:50%;border-right-color:transparent;height:1em;width:1em}.icon-refresh::after{border:.2em solid currentColor;border-left-color:transparent;border-top-color:transparent;height:0;left:80%;top:20%;width:0}.icon-search::before{border:.1rem solid currentColor;border-radius:50%;height:.75em;left:5%;top:5%;transform:translate(0,0) rotate(45deg);width:.75em}.icon-search::after{background:currentColor;height:.1rem;left:80%;top:80%;transform:translate(-50%,-50%) rotate(45deg);width:.4em}.icon-edit::before{border:.1rem solid currentColor;height:.4em;transform:translate(-40%,-60%) rotate(-45deg);width:.85em}.icon-edit::after{border:.15em solid currentColor;border-right-color:transparent;border-top-color:transparent;height:0;left:5%;top:95%;transform:translate(0,-100%);width:0}.icon-delete::before{border:.1rem solid currentColor;border-bottom-left-radius:.1rem;border-bottom-right-radius:.1rem;border-top:0;height:.75em;top:60%;width:.75em}.icon-delete::after{background:currentColor;box-shadow:-.25em .2em,.25em .2em;height:.1rem;top:.05rem;width:.5em}.icon-share{border:.1rem solid currentColor;border-radius:.1rem;border-right:0;border-top:0}.icon-share::before{border:.1rem solid currentColor;border-left:0;border-top:0;height:.4em;left:100%;top:.25em;transform:translate(-125%,-50%) rotate(-45deg);width:.4em}.icon-share::after{border:.1rem solid currentColor;border-bottom:0;border-radius:75% 0;border-right:0;height:.5em;width:.6em}.icon-flag::before{background:currentColor;height:1em;left:15%;width:.1rem}.icon-flag::after{border:.1rem solid currentColor;border-bottom-right-radius:.1rem;border-left:0;border-top-right-radius:.1rem;height:.65em;left:60%;top:35%;width:.8em}.icon-bookmark::before{border:.1rem solid currentColor;border-bottom:0;border-top-left-radius:.1rem;border-top-right-radius:.1rem;height:.9em;width:.8em}.icon-bookmark::after{border:.1rem solid currentColor;border-bottom:0;border-left:0;border-radius:.1rem;height:.5em;transform:translate(-50%,35%) rotate(-45deg) skew(15deg,15deg);width:.5em}.icon-download,.icon-upload{border-bottom:.1rem solid currentColor}.icon-download::before,.icon-upload::before{border:.1rem solid currentColor;border-bottom:0;border-right:0;height:.5em;transform:translate(-50%,-60%) rotate(-135deg);width:.5em}.icon-download::after,.icon-upload::after{background:currentColor;height:.6em;top:40%;width:.1rem}.icon-upload::before{transform:translate(-50%,-60%) rotate(45deg)}.icon-upload::after{top:50%}.icon-copy::before{border:.1rem solid currentColor;border-bottom:0;border-radius:.1rem;border-right:0;height:.8em;left:40%;top:35%;width:.8em}.icon-copy::after{border:.1rem solid currentColor;border-radius:.1rem;height:.8em;left:60%;top:60%;width:.8em}.icon-time{border:.1rem solid currentColor;border-radius:50%}.icon-time::before{background:currentColor;height:.4em;transform:translate(-50%,-75%);width:.1rem}.icon-time::after{background:currentColor;height:.3em;transform:translate(-50%,-75%) rotate(90deg);transform-origin:50% 90%;width:.1rem}.icon-mail::before{border:.1rem solid currentColor;border-radius:.1rem;height:.8em;width:1em}.icon-mail::after{border:.1rem solid currentColor;border-right:0;border-top:0;height:.5em;transform:translate(-50%,-90%) rotate(-45deg) skew(10deg,10deg);width:.5em}.icon-people::before{border:.1rem solid currentColor;border-radius:50%;height:.45em;top:25%;width:.45em}.icon-people::after{border:.1rem solid currentColor;border-radius:50% 50% 0 0;height:.4em;top:75%;width:.9em}.icon-message{border:.1rem solid currentColor;border-bottom:0;border-radius:.1rem;border-right:0}.icon-message::before{border:.1rem solid currentColor;border-bottom-right-radius:.1rem;border-left:0;border-top:0;height:.8em;left:65%;top:40%;width:.7em}.icon-message::after{background:currentColor;border-radius:.1rem;height:.3em;left:10%;top:100%;transform:translate(0,-90%) rotate(45deg);width:.1rem}.icon-photo{border:.1rem solid currentColor;border-radius:.1rem}.icon-photo::before{border:.1rem solid currentColor;border-radius:50%;height:.25em;left:35%;top:35%;width:.25em}.icon-photo::after{border:.1rem solid currentColor;border-bottom:0;border-left:0;height:.5em;left:60%;transform:translate(-50%,25%) rotate(-45deg);width:.5em}.icon-link::after,.icon-link::before{border:.1rem solid currentColor;border-radius:5em 0 0 5em;border-right:0;height:.5em;width:.75em}.icon-link::before{transform:translate(-70%,-45%) rotate(-45deg)}.icon-link::after{transform:translate(-30%,-55%) rotate(135deg)}.icon-location::before{border:.1rem solid currentColor;border-radius:50% 50% 50% 0;height:.8em;transform:translate(-50%,-60%) rotate(-45deg);width:.8em}.icon-location::after{border:.1rem solid currentColor;border-radius:50%;height:.2em;transform:translate(-50%,-80%);width:.2em}.icon-emoji{border:.1rem solid currentColor;border-radius:50%}.icon-emoji::before{border-radius:50%;box-shadow:-.17em -.1em,.17em -.1em;height:.15em;width:.15em}.icon-emoji::after{border:.1rem solid currentColor;border-bottom-color:transparent;border-radius:50%;border-right-color:transparent;height:.5em;transform:translate(-50%,-40%) rotate(-135deg);width:.5em} \ No newline at end of file diff --git a/frontend/static/wownero.png b/frontend/static/wownero.png new file mode 100644 index 0000000..02a262b Binary files /dev/null and b/frontend/static/wownero.png differ diff --git a/frontend/templates/about/api/index.html b/frontend/templates/about/api/index.html new file mode 100644 index 0000000..eb911ca --- /dev/null +++ b/frontend/templates/about/api/index.html @@ -0,0 +1,108 @@ + + + + + + + YellWOWPages - Sex and Drugs in the metaverse + + + + + + +
+ +
+
+
+

About - Api

+

+ Search user: /api/user/{username} +

+ Get all users: /api/all +

+
+
+ + + \ No newline at end of file diff --git a/frontend/templates/about/index.html b/frontend/templates/about/index.html new file mode 100644 index 0000000..d1a4cf1 --- /dev/null +++ b/frontend/templates/about/index.html @@ -0,0 +1,125 @@ + + + + + + + YellWOWPages - Sex and Drugs in the metaverse + + + + + + +
+ +
+
+
+

About

+

+ Search for any Wownero sub-address you want by username and pay + the world! +
+ This application uses Wownero's Centralized Authentication Service. +

+

+ Other Wownero related stuff: +
+ WebSite +
+ SuchWow +
+ Official Git +
+ Discord server +

+

+ Idea of: dsc_ +
+ Made by NotMtth +

+
+
+ + + \ No newline at end of file diff --git a/frontend/templates/dashboard/index.html b/frontend/templates/dashboard/index.html new file mode 100644 index 0000000..bfada88 --- /dev/null +++ b/frontend/templates/dashboard/index.html @@ -0,0 +1,100 @@ + + + + + + + Such dashboard + + + + + + +
+ +
+
+
+
+ {% for username, address in user_data.items() %} +
Welcome back {{username}}!
+ Current sub-address: +
+ Change sub-address: +
+ + +
+
+ {% endfor %} +
+
+
+ + + \ No newline at end of file diff --git a/frontend/templates/errors/index.html b/frontend/templates/errors/index.html new file mode 100644 index 0000000..f5b817d --- /dev/null +++ b/frontend/templates/errors/index.html @@ -0,0 +1,30 @@ + + + + + + + + Such error :( + + + + + + +
+
+

Error: {{error}}

+
+
+ + \ No newline at end of file diff --git a/frontend/templates/root/index.html b/frontend/templates/root/index.html new file mode 100644 index 0000000..52bfe40 --- /dev/null +++ b/frontend/templates/root/index.html @@ -0,0 +1,110 @@ + + + + + + + YellWOWPages - Sex and Drugs in the metaverse + + + + + + +
+ +
+
+
+
+ YellWOWPages +
+
+ The first addresses library - + from the community to the community +
+
+
+ + + \ No newline at end of file diff --git a/frontend/templates/yellwow/index.html b/frontend/templates/yellwow/index.html new file mode 100644 index 0000000..a937f51 --- /dev/null +++ b/frontend/templates/yellwow/index.html @@ -0,0 +1,126 @@ + + + + + + + YellWOWPages - Sex and Drugs in the metaverse + + + + + + +
+ +
+
+
+
+ + +
+
+ {% for username, address in user_data.items() %} +
+
+ {{username}} +
+ {{address}} +
+ {% endfor %} +
+
+
+ + + \ No newline at end of file diff --git a/frontend/templates/yellwow/single_user/index.html b/frontend/templates/yellwow/single_user/index.html new file mode 100644 index 0000000..9c32b8a --- /dev/null +++ b/frontend/templates/yellwow/single_user/index.html @@ -0,0 +1,132 @@ + + + + + + + YellWOWPages - Sex and Drugs in the metaverse + + + + + + +
+ +
+
+
+
+ + +
+
+ Result: {{user_data|length}} + {% if not user_data|length %} + Nothing found... + {% else %} +
+ {% for username, address in user_data.items() %} +
+
+ {{username}} +
+ {{address}} +
+ {% endfor %} +
+ {% endif %} +
+
+ + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..4344355 --- /dev/null +++ b/main.py @@ -0,0 +1,45 @@ +from fastapi import FastAPI, Request +from fastapi.responses import HTMLResponse +from fastapi.staticfiles import StaticFiles +import uvicorn + +from classes.constraints import Constraints + +from starlette.exceptions import HTTPException as StarletteHTTPException + +app = FastAPI(docs_url=None, redoc_url=None) + +app.mount('/static', StaticFiles(directory='frontend/static'), name='static') + +from routers import auth, static, dashboard, db, api + +app.include_router(auth.router) +app.include_router(dashboard.router) +app.include_router(static.router) +app.include_router(api.router) + + +@app.get("/") +@app.get('/root', response_class=HTMLResponse) +async def root(request: Request): + return Constraints.templates.TemplateResponse('/root/index.html', {'request': request}) + + +# shitty error handling +@app.exception_handler(StarletteHTTPException) +async def http_exception_handler(request, exc): + if exc.status_code == 404: + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': 'not found...', + 'url': '/root'}) + elif exc.status_code == 500: + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': 'internal server error', + 'url': '/root'}) + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': exc.detail, + 'url': '/root'}) + + +if __name__ == '__main__': + uvicorn.run(app, host='127.0.0.1', port=8080) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b9939be --- /dev/null +++ b/requirements.txt @@ -0,0 +1,30 @@ +anyio==3.5.0 +asgiref==3.5.0 +asttokens==2.0.5 +certifi==2021.10.8 +charset-normalizer==2.0.12 +click==8.0.4 +colorama==0.4.4 +executing==0.8.3 +fastapi==0.75.0 +Flask==2.0.3 +Flask-SQLAlchemy==2.5.1 +greenlet==1.1.2 +h11==0.13.0 +icecream==2.1.2 +idna==3.3 +itsdangerous==2.1.1 +Jinja2==3.0.3 +MarkupSafe==2.1.0 +pydantic==1.9.0 +Pygments==2.11.2 +python-multipart==0.0.5 +requests==2.27.1 +six==1.16.0 +sniffio==1.2.0 +SQLAlchemy==1.4.32 +starlette==0.17.1 +typing-extensions==4.1.1 +urllib3==1.26.8 +uvicorn==0.17.5 +Werkzeug==2.0.3 diff --git a/routers/__init__.py b/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/routers/api.py b/routers/api.py new file mode 100644 index 0000000..cc8c8bc --- /dev/null +++ b/routers/api.py @@ -0,0 +1,32 @@ +from fastapi import APIRouter, Request, Form +from fastapi.responses import RedirectResponse, HTMLResponse +from icecream import ic + +from classes.constraints import Constraints +from .db import Database + +router = APIRouter() + + +# external api +@router.get('/api/user/{username}') +async def get_api(request: Request, username: str): + if not Database.Users.get_address(username): + return {'error': 'invalid user'} + return Database.Users.get_address(username) + + +@router.get('/api/all') +async def get_api_all(request: Request): + return Database.Users.get_all() + + +# site search redirect +@router.get('/search') +async def search_api(request: Request): + username = request.query_params['username'] + ic(request.query_params.get('switch', None) == 'on') + if request.query_params.get('switch', None) == 'on': + return RedirectResponse(f'/yellwowpage/matches/{username}') + else: + return RedirectResponse(f'/yellwowpage/user/{username}') diff --git a/routers/auth.py b/routers/auth.py new file mode 100644 index 0000000..600165e --- /dev/null +++ b/routers/auth.py @@ -0,0 +1,68 @@ +from fastapi import APIRouter, Request, Cookie +from fastapi.responses import RedirectResponse, HTMLResponse +import requests +from icecream import ic +import secrets + +from classes.constraints import Constraints + +router = APIRouter() + + +@router.get('/login') +async def get_login(request: Request): + state = secrets.token_hex(10) + response = RedirectResponse( + 'https://login.wownero.com/auth/realms/master/protocol/openid-connect/auth?'f'client_id=' + f'{Constraints.client_id}&redirect_uri=https://yellow.wownero.com/authenticate&' + f'response_type=code&state={state}') + response.set_cookie(key='state', value=state) + return response + + +@router.get('/authenticate') +async def get_auth(request: Request, state: str = Cookie(None)): + params = request.query_params + if state is None: + return Constraints.templates.TemplateResponse('/errors/index.html', + {'request': request, + 'error': '`state` security code not found...', + 'url': '/login'}) + if params['state'] != state: + return Constraints.templates.TemplateResponse('/errors/index.html', + {'request': request, + 'error': '`state` security code is wrong', + 'url': '/login'}) + url = "https://login.wownero.com/auth/realms/master/protocol/openid-connect/token" + data = { + "grant_type": "authorization_code", + "code": params["code"], + "redirect_uri": "http://127.0.0.1:8080/authenticate", + "client_id": f'{Constraints.client_id}', + "client_secret": f'{Constraints.client_secret}', + "state": params['state'] + } + r = requests.post(url=url, data=data) + response = r.json() + + if response.get('error', None) is not None: + return Constraints.templates.TemplateResponse('/errors/index.html', + {'request': request, 'error': r.json()['error_description'], + 'url': '/login'}) + auth_code = response.get('access_token', None) + + if auth_code is None: + return Constraints.templates.TemplateResponse('/errors/index.html', + {'request': request, 'error': 'invalid auth code', + 'url': '/login'}) + response = RedirectResponse('/dashboard') + response.set_cookie(key='auth_code', value=auth_code) + response.delete_cookie(key='state') + return response + + +@router.get('/logout') +async def get_logout(): + response = RedirectResponse('/root') + response.delete_cookie('auth_code') + return response diff --git a/routers/dashboard.py b/routers/dashboard.py new file mode 100644 index 0000000..c2e13c5 --- /dev/null +++ b/routers/dashboard.py @@ -0,0 +1,63 @@ +from fastapi import APIRouter, Request, Cookie, Form +from fastapi.responses import RedirectResponse, HTMLResponse +import requests +from icecream import ic + +from classes.constraints import Constraints +from .db import Database + +router = APIRouter() + + +@router.get('/dashboard', response_class=HTMLResponse) +async def get_dashboard(request: Request, auth_code: str = Cookie(None)): + if auth_code is None: + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': 'not logged in', + 'url': '/login'}) + + url = "https://login.wownero.com/auth/realms/master/protocol/openid-connect/userinfo" + response = requests.post(url, headers={"Authorization": f"Bearer {auth_code}"}) + user_profile = response.json() + + if user_profile.get('preferred_username', None) is None: + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': 'account not found...', + 'url': '/login'}) + user_name = user_profile.get('preferred_username', None) + return Constraints.templates.TemplateResponse('/dashboard/index.html', {'request': request, + 'user_data': Database.Users.get_address(user_name)}) + + +@router.post('/submit_address') +async def post_submit_address(request: Request, auth_code: str = Cookie(None), address: str = Form(None)): + if auth_code is None: + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': 'not logged in', + 'url': '/login'}) + if address is None: + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': 'invalid address', + 'url': '/dashboard'}) + + if len(address) != 97: + return Constraints.templates.TemplateResponse('/errors/index.html', {'request': request, + 'error': 'invalid address length', + 'url': '/dashboard'}) + + url = "https://login.wownero.com/auth/realms/master/protocol/openid-connect/userinfo" + response = requests.post(url, headers={"Authorization": f"Bearer {auth_code}"}) + user_name = response.json().get('preferred_username', None) + + if not Database.Users.get_address(user_name): + new_user = Database.Users(username=user_name, address=address) + Database.sqla.session.add(new_user) + Database.sqla.session.commit() + return RedirectResponse('/dashboard', status_code=303) + + update_address = Database.Users.query.filter_by(username=user_name).first() + update_address.address = address + Database.sqla.session.commit() + return RedirectResponse('/dashboard', status_code=303) + + diff --git a/routers/db.py b/routers/db.py new file mode 100644 index 0000000..d938900 --- /dev/null +++ b/routers/db.py @@ -0,0 +1,54 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy + +from icecream import install, ic + +from classes.constraints import Constraints + +app = Flask(__name__) +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +app.config['SQLALCHEMY_DATABASE_URI'] = Constraints.uri +db = SQLAlchemy(app, session_options={'autocommit': False}) + + +class Users(db.Model): + __tablename__ = 'wowusers' + username = db.Column(db.VARCHAR(32), primary_key=True) + address = db.Column(db.CHAR(97), nullable=False) + + @staticmethod + def get_address(username): + user_data = {} + try: + user_data.update({Users.query.filter_by(username=username).first().username: + Users.query.filter_by(username=username).first().address}) + except AttributeError: + return user_data + return user_data + + @staticmethod + def get_all(): + users_data = {} + for user in Users.query.all(): + users_data.update({user.username: user.address}) + return users_data + + @staticmethod + def get_matches(username): + user_data = {} + try: + for i in range(3): + user = Users.query.filter(Database.Users.username.like(f'%{username}%'))[i] + user_data.update({user.username: user.address}) + except IndexError: + return user_data + return user_data + + +class Database: + Users = Users + sqla = db + + +db.create_all() +ic('db done') diff --git a/routers/errors.py b/routers/errors.py new file mode 100644 index 0000000..86c3b6c --- /dev/null +++ b/routers/errors.py @@ -0,0 +1,2 @@ +# stupid fastapi error handling drove me crazy for some hours, updating this asap +# the handler is in the main file diff --git a/routers/static.py b/routers/static.py new file mode 100644 index 0000000..232e23d --- /dev/null +++ b/routers/static.py @@ -0,0 +1,39 @@ +from fastapi import APIRouter, Request +from fastapi.responses import RedirectResponse, HTMLResponse +from icecream import ic + +from classes.constraints import Constraints +from .db import Database + +router = APIRouter() + + +@router.get('/yellwowpage') +async def get_yellwowpage(request: Request): + return Constraints.templates.TemplateResponse('/yellwow/index.html', + {'request': request, 'user_data': Database.Users.get_all()}) + + +@router.get('/yellwowpage/user/{username}') +async def get_yellwowpage(request: Request, username: str): + return Constraints.templates.TemplateResponse('/yellwow/single_user/index.html', + {'request': request, + 'user_data': Database.Users.get_address(username)}) + + +@router.get('/yellwowpage/matches/{username}') +async def get_yellwowpage_matches(request: Request, username: str): + ic(Database.Users.get_matches(username)) + return Constraints.templates.TemplateResponse('/yellwow/single_user/index.html', + {'request': request, + 'user_data': Database.Users.get_matches(username)}) + + +@router.get('/about') +async def get_about(request: Request): + return Constraints.templates.TemplateResponse('/about/index.html', {'request': request}) + + +@router.get('/about/api') +async def get_api_about(request: Request): + return Constraints.templates.TemplateResponse('/about/api/index.html', {'request': request})