import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import json from modules import Set from modules.Common import * from modules import Render verifying = {} def Send(reciever, subject, html): config = Set.Load() Email = config.get("email") if not Email: print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" No email credentials!") try: port = int(Email.get("port", "")) except: port = 587 message = MIMEMultipart() message["From"] = Email["visible"] message["To"] = reciever message["Subject"] = subject message.attach(MIMEText(html, "html")) # Send the email with smtplib.SMTP(Email["server"], port) as server: server.starttls() server.login(Email["sender"], Email["password"]) server.sendmail(Email["sender"], reciever, message.as_string()) print('Email "'+subject+'" was sent to', reciever) def VerifyPage(server): user = Render.validate(server.cookie) # Authorization check if not user: Render.AccessDenied(server) return 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")) code = server.parsed.get("code", [""])[0] if not code: html = html + """

You have recieved an email with a code.

It could be in spam.


""" code = RandString(10) verifying[code] = user.get("email") text = """
Your Verification Code
"""+code+"""
""" text = Format(text) Send(user.get("email", ""), "Verification Code", text) Render.send(server, html, 200) else: # If we recieved the code. if code not in verifying: Render.Error(server, "Wrong Code!") return if verifying[code] != user.get("email"): Render.Error(server, "Wrong Code!") return user["email_verified"] = True f = Set.Folder() folder = f+"/accounts" 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.Error(server, "You already signed!") 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: Render.Error(server, "Wrong Code!") 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() favicon = config.get("favicon", "") if favicon.startswith("/"): favicon = "https://"+config.get("domain", "")+favicon css = open(config.get("css", "default.css"), "r") html = '' html = html + '
' if favicon: html = html + '[favicon]' html = html + " "+config.get("title", "My Website") html = html + "

" html = html + '
' html = html + text html = html + '
' return html