From 6cd369b04318c1497e84d8d250268d6f7f6e06b7 Mon Sep 17 00:00:00 2001 From: BlenderDumbass Date: Wed, 4 Dec 2024 14:25:58 +0200 Subject: [PATCH] Basic petition functionality --- icons/petition.png | Bin 0 -> 4828 bytes modules/Email.py | 108 +++++++++++++++++++++++++++++++++++- modules/Render.py | 134 ++++++++++++++++++++++++++++++++++++++------- modules/Run.py | 8 +-- 4 files changed, 223 insertions(+), 27 deletions(-) create mode 100644 icons/petition.png diff --git a/icons/petition.png b/icons/petition.png new file mode 100644 index 0000000000000000000000000000000000000000..f04a332504848111327bd6e408c26667e0907681 GIT binary patch literal 4828 zcmeHLdsGuw8lMCt7!_Z!h|p~e>H+B_nPkYT36v6qKqH6<=(3i1B@B?vm<%LXUEjJs z&K5cAql)!Wd{nknrS`bmuJKi$>$=Bvl@^s&*B5K?tRA60>fV{~Tzk$Q&)NRRaBl9M z?|$F!e)so%_e(Czb0((`k&cl<5H!S=Va)}79N)sjz~`!;4!9slB%=y#4x4Qv6b@vA zfFKkSb?S+Fjm4r6CY z0{VlXX~0+p`ct6M%Yy4RgE9Yv3xBB|3gakJ?xVR9dAiM>13im}pkIUeuAUdlHA+OS z)EWSyT7#MpjY*Bl!KYSdO4LDOXlacEiUKxIKof20@fW;yKQFHokv_H#=r5vEQ*&&o zsdCoCIOuW;g8a2}S6ecUy&ZGny^ERK^J4xb|Gs*wsVOZjrfk%ToUwnGerj4@^kjg2 zOpPou{mA~7mXr9UBPXU8ND5MhJ%eUdvbo&q5ii!sW*qmk%^&#Mf8}d~woW59jLH;m zaBpnlGS5ZkpLme4Eqv@k!%X8z&Gb=Y~b>t(7*mWx&8L&oRzPIh!wMHqITH7 zOffgo(Y5W%i9agpkKaB%a>8$_J65-@ILXwWRSq(19k=#9JdWUdn~!Av zNH02URW2!-ruMwKC1S|FR>_M+*RRgl{)tT$zd`(DX3TA3aCn>e{*D`S-gs;B)6npw zkb>El-(y6Lo9pz4W;_cY-5jQDIJ9A(r056eSoYHLGYzu3_&;O@o<_}`DjI!ofTC>(YdTf!zh}lhYgelhmA&Dr*&xXL|l*dg2?vJASaGXet!>pjF1JLebo!3>Y6V#w~2i@o4 z> z;Cz^eN^t@n0aqYBg|9JroDit^zP|WMC_V~+Fc{ImYV^MeQ*~}w#n+6k9h+4zabgw} zdKDR97nFhG1!|$HyBKzI2K@acpUznPl1s?t{foR3zx{Oe)AdRWypnQ%cJm!-4Q*Q4O76^3V}TcH=w0SM|Sy~y9j2eKK{y%3~~<(tUA zJ-HGHC7jKkCb=^>R65SE>&-RoKorHL6>_PJi~m&)y>#U+SP&5jLE_;yYf4_>vHR<@ zGe%93eLc^4E#b+|YJ3X3@Econ$g#9&d-z1DOnRhbqz$izYns2^Mn$g)_qiAA_U|f* zSAJW!|H95;*Z@3~8vEU4$L^ErhmLFKyt0GW-M4DBw@><<=f4_k09Uc`YsY2hZmf&4 zovjHQf4^xmTQGj^-;$qKqZ4Rf-lpy4`I6?)-%H*ZuYG^m6ffit`+Vu*H$=}Jj}t~e z$US;>;DV4V;ipv@rD1;-wJ%sxeK0Gqe9v!B$k;`J?+#}b|08m0WrTmQS>lGA3)a0& zOh2Dg%oOfjC;lPh=(BBg%3^VexB-d{ywx&0aQbopFO}3Ud3b5SD$&#Dt(yXHOLg1L zs+RaY5syThb45GY2B=mv>1@kSB@(u2*`FjFRPT6<+^e#!^>2|HhTakFn7{OQpNlUH zX9HWVWtHx( zcsR>;W7PLoYw||~{*qbx=@;{m*g3DOV@4muoN#6l4Peht3;RQFR8w=*SxNyF8S2q zkj)Ds10%H?8!pLCOa0M>53}R49AC_AjoLWy!nq0h_eVasa?3M6f~{ZEkbACh`E>Zrn~x6P(bvW$&HLc7jQ<}KWJ{ZDZFr}6;eP-)@|mRo literal 0 HcmV?d00001 diff --git a/modules/Email.py b/modules/Email.py index f5b3e9a..c31335e 100644 --- a/modules/Email.py +++ b/modules/Email.py @@ -73,7 +73,7 @@ def VerifyPage(server):
-
+

@@ -135,8 +135,113 @@ def VerifyPage(server): with open(folder+"/"+user.get("username", "")+".json", "w") as save: json.dump(user, save, indent=4) + del verifying[code] + Render.Redirect(server, "/settings#email") + +def SignPetition(server): + + config = Set.Load() + # Generating + html = Render.head(title = "Verify Email", + description = "Verify Email", + config = config + ) + + html = html + Render.Button(config.get("title", "My Website"), "/", image=config.get("favicon", "/icon/internet")) + + article = server.parsed.get("article", [""])[0] + print(article) + + Articles = Render.allArticles() + if article not in Articles: + Render.AccessDenied(server) + return + + Article = Articles[article] + + code = server.parsed.get("code", [""])[0] + email = server.parsed.get("email", [""])[0] + + if email in Article.get("petition", {}).get("signatures", []): + Render.AccessDenied(server) + return + + if not code: + + html = html + """ + +
+ +
+ + + +
+
+ You have recieved an email with a code.

+ It could be in spam. +

+ + +
+ + +
+ + + +
+
+ + """ + code = RandString(10) + verifying[code] = email + + text = """ +
+ Your Verification Code +
+
"""+code+""" +
+
+ """ + + text = Format(text) + + Send(email, "Verification Code", text) + + Render.send(server, html, 200) + + else: + + # If we recieved the code. + + if code not in verifying: + print("code not in verifying") + Render.AccessDenied(server) + return + + + Article["petition"]["signed"] += 1 + Article["petition"]["signatures"].append(verifying[code]) + + f = Set.Folder() + with open(f+"/tabs"+article+"/metadata.json", "w") as save: + json.dump(Article, save, indent=4) + + + del verifying[code] + + Render.Redirect(server, article) + + +### + def Format(text): config = Set.Load() @@ -160,4 +265,3 @@ def Format(text): return html - diff --git a/modules/Render.py b/modules/Render.py index 85ae9c2..6362ce5 100644 --- a/modules/Render.py +++ b/modules/Render.py @@ -259,7 +259,7 @@ def allArticles(): data = json.load(o) data["tab"] = tab data["url"] = "/"+tab+"/"+article - articles[article] = data + articles[data["url"]] = data except Exception as e: print(e) pass @@ -566,6 +566,50 @@ def ArticlePage(server, url): html = html + '
' + # Petition + + petition = Articles.get(article, {}).get("petition", "") + if petition: + + html = html + '
' + html = html + '

[icon petition]' + html = html + 'Petition

' + + try: + frac = petition.get("signed", 0) / int(petition.get("goal", 1)) + except: + frac = 0 + + html = html + ProgressBar(frac) + html = html + "
"+str(petition.get("signed", 0))+" / "+Safe(str(petition.get("goal", 1)))+" Signatures" + + html = html + """ + +
+ + [icon petition] + Sign + + +
+ + + + + + + +
+ +
+ """ + + html = html + '
' + + # License License = Articles.get(article, {}).get("license", "") if License: html = html + '
' @@ -1346,45 +1390,53 @@ def EditorPage(server): """ - # Optional release options - + # Optional Petition + if rank(user.get("username","")) == 0: + + + petition = article.get("petition", {}) + petition_goal = petition.get("goal", 0) + + html = html + """
- [icon unlock] - Unlock + [icon petition] + Petition

+ + [icon ok] +
-
- For unlockable files that will be published after a certain statistics is reached. -
-

+ +
+ + [icon analytics] + From API + - [icon file] -
[icon link] - +
[icon checlist] - -
- - [icon ok] - +
[icon scene] - + +
+ + [icon link] +
-
@@ -1456,6 +1508,15 @@ def ArticlePreview(article, Tabs, cookie=""): if article.get("thumbnail"): html = html + '
[thumbnail]
' + petition = article.get("petition", "") + if petition: + try: + frac = petition.get("signed", 0) / int(petition.get("goal", 1)) + except: + frac = 0 + + html = html + ProgressBar(frac) + author = article.get("author", "") if author: html = html + '
'+User( author )+'
' @@ -1811,6 +1872,17 @@ def LoginButton(server): return html +def ProgressBar(frac): + + title = str(round(frac*100,1))+"%" + + frac = min(1, frac) + frac = max(0, frac) + + html = '
' + html = html + '
' + html = html + '
' + return html def NotFound(server): @@ -2329,7 +2401,13 @@ def Publish(server): License = server.parsed.get("license", [""])[0] recording = server.parsed.get("recording", [""])[0] - + + # Petition data + petition_goal = server.parsed.get("petition_goal", [""])[0] + petition_api = server.parsed.get("petition_api", [""])[0] + petition_api_key = server.parsed.get("petition_api_key", [""])[0] + petition_api_title = server.parsed.get("petition_api_title", [""])[0] + petition_api_link = server.parsed.get("petition_api_link", [""])[0] # If this tab doesn't exist, this is an error. if tab not in Tabs: @@ -2384,6 +2462,22 @@ def Publish(server): metadata["recording"] = recording metadata["thumbnail"] = thumbnail + # Petition + + if petition_goal: + + petition = metadata.get("petition", { + "signed":0, + "signatures":[] + }) + + try: + petition["goal"] = int(petition_goal) + except: + petition["goal"] = 1 + + metadata["petition"] = petition + # Save the changes try: diff --git a/modules/Run.py b/modules/Run.py index d3be2ff..21a640c 100644 --- a/modules/Run.py +++ b/modules/Run.py @@ -16,6 +16,7 @@ import os from modules import Set from modules import Render +from modules import Email from modules.Common import * class handler(BaseHTTPRequestHandler): @@ -172,8 +173,6 @@ class handler(BaseHTTPRequestHandler): Render.EditorPage(self) elif self.path[1:].startswith("email_verify"): - - from modules import Email Email.VerifyPage(self) elif self.path[1:].startswith("register"): @@ -203,9 +202,8 @@ class handler(BaseHTTPRequestHandler): elif self.path[1:].startswith("log_out"): Render.LogOut(self) - - - + elif self.path[1:].startswith("sign_petition"): + Email.SignPetition(self) elif self.path[1:].startswith("read_notification"): Render.ReadNotification(self)