out("migrate create an account; link it with TidyHQ") out("authenticate log in to Neat with your club account") out() out("id prints the list of groups you are in") elif command[0] in ["quit", "exit"]: break elif command[0] == "migrate": migrate_first_time = False try: importlib.reload(migrate) except NameError: migrate_first_time = True if migrate_first_time: import migrate elif command[0] == "authenticate": pair = Password.ask(C.DOMAIN) try: user = User.authenticate(*pair) except (AuthenticationError, LDAPPasswordIsMandatoryError): out("authenticate: bad username or password") elif command[0] == "id": if user is not None: entry = user.get() print("user: %d <%s>" % (entry.uidNumber.value, entry.cn.value)) query = "(member=%s)" % entry.entry_dn for group in Directory().reader("group", query=query).search(): print("group: %d <%s>" % (group.gidNumber.value, group.cn.value)) else:
import requests import neat from configuration import C from tidy import Club from user import User from password import Password from directory import Directory, AuthenticationError T = Club(C.TIDY_NAME, C.TIDY_CLIENT, C.TIDY_SECRET) T_pair = None while T._token is None: try: T_pair = Password.ask("TidyHQ", T_pair) T.authenticate(*T_pair) except requests.exceptions.HTTPError: pass print() me = T.me() T_prefix = "TidyHQ contact #%d" % me._data["id"] membership = me.membership() if membership is None: print("%s: you are not an active member" % (T_prefix)) else: print("%s: you are an active member until %s" % (T_prefix, membership["end_date"])) username = me.username() forward_linking_is_required = False if username is None: forward_linking_is_required = True print("%s: not associated with a club account" % (T_prefix))