diff --git a/icons/petition.png b/icons/petition.png new file mode 100644 index 0000000..f04a332 Binary files /dev/null and b/icons/petition.png differ 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)