diff --git a/icons/user_link.png b/icons/user_link.png new file mode 100644 index 0000000..f62c277 Binary files /dev/null and b/icons/user_link.png differ diff --git a/icons/user_new.png b/icons/user_new.png new file mode 100644 index 0000000..2aec0da Binary files /dev/null and b/icons/user_new.png differ diff --git a/modules/Account.py b/modules/Account.py new file mode 100644 index 0000000..141685d --- /dev/null +++ b/modules/Account.py @@ -0,0 +1,109 @@ +# AGPL 3 or any later version +# (C) J.Y.Amihud ( Blender Dumbass ) + + +import os +import sys +import json +import random +import hashlib +import urllib.parse + +from datetime import datetime +from getpass import getpass + +from modules import Set +from modules import markdown +from modules.Common import * + + +def Load(name): + + folder = Set.Folder()+"/accounts/" + try: + with open(folder+name+".json") as o: + return json.load(o) + except: + return {} + +def Save(account): + + name = account.get("username", "") + folder = Set.Folder()+"/accounts/" + + try: + with open(folder+name+".json", "w") as save: + json.dump(account, save, indent=4) + + except Exception as e: + print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Cannot save account!", e) + +def Account(): + + if len(sys.argv) < 3: + from modules import Help + Help.Accounts() + + if "--list" in sys.argv: + List() + + elif "--add" in sys.argv: + try: + account = sys.argv[ sys.argv.index("--add") + 1] + if "--" in account: 1/0 # Failing this for the error message. + Add(account) + + except Exception as e: + print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Account name wasn't specified!") + print('Use: $ python3 run.py --account --add blenderdumbass') + + elif "--edit" in sys.argv: + try: + account = sys.argv[ sys.argv.index("--edit") + 1] + if "--" in account: 1/0 # Failing this for the error message. + Edit(account) + + except Exception as e: + print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Account name wasn't specified!") + print('Use: $ python3 run.py --account --edit blenderdumbass') + + +def List(): + + folder = Set.Folder()+"/accounts" + for account in os.listdir(folder): + if account.endswith(".json"): + print(account.replace(".json", "")) + +def Add(name): + + # Adds a new account. + + account = Load(name) + if account: + print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Account already exists.") + + account = { + "username":name, + "bio":"", + "invite_codes":{}, + "invited":[], + "invited_by":"", + "password":hashlib.sha512(getpass("Account's Password: ").encode("utf-8")).hexdigest(), + "title":name, + "email":"", + "website":"", + "mastodon":"", + "matrix":"", + "sessions":{} + } + + + Save(account) + + print(clr["bold"]+clr["tbyl"]+name+clr["norm"]+" is added."+clr["norm"]) + +def Edit(name): + + folder = Set.Folder()+"/accounts/" + os.system("nano "+folder+name+".json") diff --git a/modules/Common.py b/modules/Common.py index c53b26c..128821d 100644 --- a/modules/Common.py +++ b/modules/Common.py @@ -52,7 +52,10 @@ def Simplify(text, extrasimple=True): good = "QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuiopasdfghjklzxcvbnm.1234567890-_:* " - if extrasimple: + if extrasimple == "file": + good = "QWERTYUIOPLKJHGFDSAZXCVBNMqwertyuiopasdfghjklzxcvbnm.1234567890-_" + + elif extrasimple: good = "qwertyuiopasdfghjklzxcvbnm.1234567890-_:" text = text.lower() diff --git a/modules/Help.py b/modules/Help.py index 8ebdf7f..49a0dfb 100644 --- a/modules/Help.py +++ b/modules/Help.py @@ -10,9 +10,13 @@ def Help(): print() print(clr["tdyl"]+"--help"+clr["norm"]+" - Prints this Help Page.") print(clr["tdyl"]+"--run"+clr["norm"]+" - Run the server.") + print() print(clr["tdyl"]+"--set"+clr["norm"]+" - Use for changing settings.") + print(clr["tdyl"]+"--account"+clr["norm"]+" - Manage Accounts.") + print() print(clr["tdyl"]+"--config"+clr["norm"]+" - Edit config file directly, bypassing --set.") print(clr["tdyl"]+"--folder"+clr["norm"]+" - Open the folder of the website's data.") + print() print(clr["tdyl"]+"--transfer"+clr["norm"]+"- Transfers legacy website data to the new format.") print() @@ -32,3 +36,15 @@ def Set(): print(clr["tdyl"]+"--add_tab"+clr["norm"]+" - Adds a category of articles.") print(clr["tdyl"]+"--edit_tab"+clr["norm"]+" - Edit the config of a category.") print() + +def Accounts(): + + print() + print(clr["bold"]+" BDServer Account Help "+clr["norm"]) + print() + print(" Account is used to manage website's accounts.") + print() + print(clr["tdyl"]+"--add"+clr["norm"]+" - Add a new account.") + print(clr["tdyl"]+"--list"+clr["norm"]+" - List accounts.") + print() + diff --git a/modules/Legacy.py b/modules/Legacy.py index 8a199bf..ae50801 100644 --- a/modules/Legacy.py +++ b/modules/Legacy.py @@ -139,6 +139,13 @@ def Transfer(location): account = accounts[username] + # We are updating the invites + invite_codes = account.pop("invite_codes") + account["invite_codes"] = {} + + for code in invite_codes: + account["invite_codes"][code] = "Unknown" + # We are adding some new stuff to accounts account["title"] = username # Visible title diff --git a/modules/Render.py b/modules/Render.py index 2f922b8..cf81642 100644 --- a/modules/Render.py +++ b/modules/Render.py @@ -138,6 +138,22 @@ def moderates(moderator, user): if moderator == user: return True + + if rank(moderator, Accounts) < rank(user, Accounts): + return True + +def rank(account, Accounts=None): + + if not Accounts: + Accounts = accounts() + + if account not in Accounts: + return 1000000 + + if not Accounts[account].get("invited_by") or Accounts[account].get("invited_by") == account: + return 0 + + return 1 + rank(Accounts[account].get("invited_by"), Accounts) def articles(tab): @@ -530,8 +546,16 @@ def AccountPage(server, account): html = html + '