Skip to content

Commit

Permalink
Merge branch 'main' into deployment-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
k3nd0x authored Jun 20, 2024
2 parents b5bbeba + 1b7fc4f commit a0bc813
Show file tree
Hide file tree
Showing 63 changed files with 1,382 additions and 46,968 deletions.
36 changes: 23 additions & 13 deletions .github/workflows/docker-build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@ on:
- 'dockerfile'

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file dockerfile --tag k3nd0x/piglet:latest
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_KEY }}
- name: Push the image
run: |
export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0
docker push k3nd0x/piglet:latest
- uses: actions/checkout@v3
- name: Get latest release tag
id: get_tag
run: |
echo "::set-output name=tag::$(git describe --tags --abbrev=0)"
- name: Build the Docker image with latest release tag
run: docker build . --file dockerfile --tag k3nd0x/piglet:${{ steps.get_tag.outputs.tag }}
- name: Tag the image as latest
run: docker tag k3nd0x/piglet:${{ steps.get_tag.outputs.tag }} k3nd0x/piglet:latest
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_KEY }}
- name: Push the image with latest release tag
run: |
export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0
docker push k3nd0x/piglet:${{ steps.get_tag.outputs.tag }}
- name: Push the image with latest tag
run: |
export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0
docker push k3nd0x/piglet:latest
run-compose:
needs: build
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ webapp/celerybeat-schedule.dir
webapp/celerybeat-schedule.pag
webapp/config/redis/dump.rdb
docker-compose-dev.yml
dockerfile-dev
webapp/app/views/pictures
!webapp/app/views/pictures/default.png
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ Password: `admin`
- password change over webui
- SQLite as database #10

# Known issues
- Site is flashing white at reload when darkmode is active https://github.com/k3nd0x/piglet/issues/1
- Nav Menue is popping out at reload when its in mini mode https://github.com/k3nd0x/piglet/issues/2

# Disclaimer

I started to build this project at the beginning of my programming career so please be gentle if something is not working as expected.
Expand Down
7 changes: 5 additions & 2 deletions webapp/api/routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import time
import logging

from .functs import hex_color, random_name
from .functs import hex_color, random_name,random_image


@admin.on_event("startup")
Expand All @@ -47,13 +47,16 @@ async def startup_event():
time.sleep(15)

name, surname = random_name()
image,image_name = random_image()
if image:
image.save(f'app/views/pictures/{image_name}')

inserts = [ """INSERT IGNORE INTO months VALUES (2,"February"),(3,"March"),(4,"April"),(5,"May"),(6,"June"),(7,"July"),(8,"August"),(9,"September"),(10,"October"),(11,"November"),(12,"December"),(1,"January")""",
"""INSERT IGNORE INTO pig_budgets VALUES (100,0,"Default",0,"3ec5d92868964bfbbf223ca88f379ee9","USD")""",
f"""INSERT IGNORE INTO pig_category VALUES (1,"Groceries",1,1,100,"{hex_color()}")""",
"""INSERT IGNORE INTO pig_notitype VALUES (1,"order","Money"),(2,"category","Category"),(3,"budget","Budget")""",
"""INSERT IGNORE INTO pig_notiobj VALUES (1,'added','added'),(2,'removed','removed'),(3,'joined','joined'),(4,'shared','shared')""",
f'''INSERT IGNORE INTO registered_user VALUES (1,"admin@{domain}",1,"864fd3978f508ef03a3e9c24aef43b639d7725c15e08eeaf961a9b81c3adc097:0b108f78bca548fa8fa2721e46d83150","{name}","{surname}","default.png",NULL,"{hex_color()}","7eb304283ead5f6",100,10000,1)''',
f'''INSERT IGNORE INTO registered_user VALUES (1,"admin@{domain}",1,"864fd3978f508ef03a3e9c24aef43b639d7725c15e08eeaf961a9b81c3adc097:0b108f78bca548fa8fa2721e46d83150","{name}","{surname}","{image_name}",NULL,"{hex_color()}","7eb304283ead5f6",100,10000,1)''',
"""INSERT IGNORE into pig_userbudgets values (1,100,1)""",
]

Expand Down
62 changes: 6 additions & 56 deletions webapp/api/routes/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
budget = APIRouter()

@budget.get("/")
async def _get(current_user = Depends(get_current_user)):
async def _get(current_user = Depends(get_current_user),all: Optional[bool] = False):
mysql = sql()
query = f'''select pig_budgets.*, pig_userbudgets.joined from pig_budgets JOIN pig_userbudgets on pig_budgets.id = pig_userbudgets.budget_id where pig_userbudgets.user_id = {current_user["id"]} order by joined'''
if not all:
query = f'''select pig_budgets.*, pig_userbudgets.joined from pig_budgets JOIN pig_userbudgets on pig_budgets.id = pig_userbudgets.budget_id where pig_userbudgets.user_id = {current_user["id"]} and pig_userbudgets.joined = 1 order by joined'''
else:
query = f'''select pig_budgets.*, pig_userbudgets.joined from pig_budgets JOIN pig_userbudgets on pig_budgets.id = pig_userbudgets.budget_id where pig_userbudgets.user_id = {current_user["id"]} order by joined'''
response = mysql.get(query)

mysql.close()

return response

@budget.post("/add")
Expand Down Expand Up @@ -82,56 +85,3 @@ async def _leave(budgetid: str, force: bool, current_user = Depends(get_current_
return True, "Budget left"
else:
return False, "You cannot leave your last budget"



#bid_mapping = current_user["bid_mapping"]

#query = '''select b0,b1,b2,b3 from pig_bidmapping where id=(select bid_mapping from registered_user where id={})'''.format(userid)

#empty = 0

#for _k,_v in mysql.get(query)[0].items():

# if _v != None:
# empty += 1

#if empty <= 1:
# return False, "You cannot leave your last budget"
#else:
# query = '''update pig_bidmapping set b0=NULL where b0={budgetid} and id={bid}'''.format(budgetid=budgetid,bid=bid_mapping)
# query1 = '''update pig_bidmapping set b1=NULL where b1={budgetid} and id={bid}'''.format(budgetid=budgetid,bid=bid_mapping)
# query2 = '''update pig_bidmapping set b2=NULL where b2={budgetid} and id={bid}'''.format(budgetid=budgetid,bid=bid_mapping)
# query3 = '''update pig_bidmapping set b3=NULL where b3={budgetid} and id={bid}'''.format(budgetid=budgetid,bid=bid_mapping)
#
# response = []
# for i in query,query1,query2,query3:
# response.append(mysql.post(i))

# query = '''select mode from pig_budgets where id={budgetid}'''.format(budgetid=budgetid)

# response = mysql.get(query)

# mode = int(response[0]["mode"])

# if mode == 0:
# if force:
# query = '''delete from pig_budgets where id={}'''.format(budgetid)
# response = mysql.post(query)
# return True, "Budget deleted"
# else:
# query = '''select budget_id from pig_orders where budget_id={}'''.format(budgetid)
# if mysql.get(query) == []:
# query = '''select budget_id from pig_category where budget_id={}'''.format(budgetid)
# if mysql.get(query) == []:
# query = '''delete from pig_budgets where id={}'''.format(budgetid)
# response = mysql.post(query)
# return True, "Budget deleted"
# else:
# return False, "Categories still in budget"
# else:
# return False, "Orders still in budget"
# else:
# return True, "Budget in use"


37 changes: 36 additions & 1 deletion webapp/api/routes/functs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import random as random
from datetime import datetime, timedelta
from dateutil import parser
import random
from PIL import Image
import hashlib
import time

def get_budgetid(user_id):
mysql = sql()
query = '''select budget_id from registered_user where id="{}"'''.format(user_id)
Expand Down Expand Up @@ -90,3 +93,35 @@ def random_name():
random_name = random.choice(names)
random_surname = random.choice(surnames)
return random_name, random_surname


def random_image(size=8, scale=32):
try:
image = Image.new('RGB', (size, size), 'white')
pixels = image.load()

# Generate random colors
colors = [(
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255)
) for _ in range(size * size // 2)]


for x in range(size // 2):
for y in range(size):
color = random.choice(colors)
pixels[x, y] = color
pixels[size - 1 - x, y] = color # Mirror the left half to the right half

image = image.resize((size * scale, size * scale), Image.NEAREST)

current_time = str(time.time())
hash_object = hashlib.sha256(current_time.encode())
name = hash_object.hexdigest()

name = f'gen_{name}.png'

return image,name
except:
return None,"default.png"
15 changes: 10 additions & 5 deletions webapp/api/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .mysql import sql
from .sendmail import mail
from .functs import hex_color, get_timestamp, random_name
from .functs import hex_color, get_timestamp, random_name,random_image
from .admin import oauth2_scheme,get_current_user

user = APIRouter()
Expand Down Expand Up @@ -48,9 +48,10 @@ async def register_user(registerUser: registerUser):
color = hex_color()

name, surname = random_name()

query = '''insert into registered_user( id, email,name, surname, password,color, shamail,budget_id) select max( id ) + 1, "{}", "{}", "{}", "{}", "{}", "{}","{}" from registered_user'''.format(email, name,surname, password,color,shamail,budget_id)
print(query,flush=True)
image,image_name = random_image()
if image:
image.save(f'app/views/pictures/{image_name}')
query = '''insert into registered_user( id, email,name, surname, password,color, shamail,budget_id,image) select max( id ) + 1, "{}", "{}", "{}", "{}", "{}", "{}","{}","{}" from registered_user'''.format(email, name,surname, password,color,shamail,budget_id,image_name)

return_value = mysql.post(query)
user_id = mysql.lastrowid()
Expand Down Expand Up @@ -93,19 +94,23 @@ async def login_user(current_user = Depends(get_current_user)):

userid = current_user["id"]

query1 = f'''select id,email,verified,name,surname,color,image,budget_id from registered_user where id={userid}'''
query = '''select r.id,r.email,r.verified,r.name,r.surname,r.color,r.image,r.budget_id,r.bid_mapping,pig_bidmapping.b0,pig_bidmapping.b1,pig_bidmapping.b2,pig_bidmapping.b3 from registered_user as r join pig_bidmapping on pig_bidmapping.id = r.bid_mapping where r.email="{}"'''.format(email)
query1 = f'''select id,email,verified,name,surname,color,image from registered_user where id={userid}'''

query2 = f'''select budget_id from pig_userbudgets where user_id={userid} and joined=1'''

user_data = mysql.get(query1)[0]
budget_ids = mysql.get(query2)


budgets = []
for i in budget_ids:
budgets.append(i["budget_id"])

budget_id = min(budgets)

user_data["budgetids"] = budgets
user_data["budget_id"] = budget_id

response = user_data

Expand Down
7 changes: 4 additions & 3 deletions webapp/app/views/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ def budget():
user_id = session["userid"]
noticount, notilist, notifications = get_notis(pigapi)

s, my_budgets = pigapi.get(url="budget/")
s, my_budgets = pigapi.get(url="budget/?all=true")
s, users = pigapi.get(url=f'share/availusers/{budget_id}')

session["budgets"] = my_budgets
if request.method == "GET":
return render_template("budget_settings.html", my_budgets=my_budgets,availusers=users,notifications=notifications, notilist=notilist, noticount=noticount)

Expand Down Expand Up @@ -146,14 +145,16 @@ def joinBudget():

s, response = pigapi.post(url=f'share/updatejoin?budget_id={bid}&join={join}')

pigapi.close()

if s:
string = "You joined a budget"
s, my_budgets = pigapi.get(url="budget/")
session["budgets"] = my_budgets
flash_message = {string: "success"}
else:
string = "Budget joining failed"
flash_message = {string: "danger"}
pigapi.close()

flash(flash_message)
return redirect(url_for('budget'))
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion webapp/app/views/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def login():
session["surname"] = response["surname"]
else:
session["surname"] = email
s, my_budgets = pigapi.get(url="budget/",data=response["id"])
s, my_budgets = pigapi.get(url="budget/")
if s:
session["month"] = "None"
session["year"] = "None"
Expand Down
Loading

0 comments on commit a0bc813

Please sign in to comment.