monolith/modules/regproc.py

59 lines
1.8 KiB
Python
Raw Normal View History

import main
from modules import provision
from utils.logging.log import *
from copy import deepcopy
def selectInst(net):
if net in main.irc.keys():
inst = deepcopy(main.irc[net])
for i in main.irc["_"].keys():
if not i in inst:
inst[i] = main.irc["_"][i]
else:
inst = main.irc["_"]
print(inst)
print("hello")
return inst
def registerAccount(net, num):
alias = main.alias[num]
nickname = alias["nick"]
username = nickname+"/"+net
password = main.network[net].aliases[num]["password"]
inst = selectInst(net)
if not inst["register"]:
error("Cannot register for %s: function disabled" % (net))
return False
entity = inst["entity"]
email = inst["email"]
cmd = inst["register"]
email = email.replace("{nickname}", nickname)
cmd = cmd.replace("{password}", password)
cmd = cmd.replace("{email}", email)
name = net+str(num)
main.IRCPool[name].msg(entity, cmd)
def confirmAccount(net, num, token):
inst = selectInst(net)
entity = inst["entity"]
cmd = inst["confirm"]
cmd = cmd.replace("{token}", token)
name = net+str(num)
main.IRCPool[name].msg(entity, cmd)
enableAuthentication(net, num)
def enableAuthentication(net, num):
obj = main.network[net]
nick = main.alias[num]["nick"]
security = obj.security
auth = obj.auth
password = obj.aliases[num]["password"]
uname = main.alias[num]["nick"]+"/"+net
provision.provisionAuthenticationData(num, nick, net, security, auth, password) # Set up for auth
if obj.relays[num]["registered"]:
warn("Authentication already enabled: %s - %i" % (net, num))
obj.relays[num]["registered"] = True
main.saveConf("network")
main.IRCPool[net+str(num)].msg(main.config["Tweaks"]["ZNC"]["Prefix"]+"status", "Jump")