def create_club(username, name): """ Creates a UNIX user account with options tailored to CSC-hosted clubs. Parameters: username - the desired UNIX username name - the club name Exceptions: InvalidArgument - on bad account attributes provided Returns: the uid number of the new account See: create() """ # check username format if not username or not re.match(cfg['username_regex'], username): raise InvalidArgument("username", username, "expected format %s" % repr(cfg['username_regex'])) try: request = ceo_pb2.AddUser() request.type = ceo_pb2.AddUser.CLUB request.username = username request.realname = name out = remote.run_remote('adduser', request.SerializeToString()) response = ceo_pb2.AddUserResponse() response.ParseFromString(out) if any(message.status != 0 for message in response.messages): raise MemberException('\n'.join(message.message for message in response.messages)) except remote.RemoteException, e: raise MemberException(e)
def create_member(username, password, name, program, email, club_rep=False): """ Creates a UNIX user account with options tailored to CSC members. Parameters: username - the desired UNIX username password - the desired UNIX password name - the member's real name program - the member's program of study club_rep - whether the user is a club rep email - email to place in .forward Exceptions: InvalidArgument - on bad account attributes provided Returns: the uid number of the new account See: create() """ # check username format if not username or not re.match(cfg['username_regex'], username): raise InvalidArgument("username", username, "expected format %s" % repr(cfg['username_regex'])) # check password length if not password or len(password) < cfg['min_password_length']: raise InvalidArgument("password", "<hidden>", "too short (minimum %d characters)" % cfg['min_password_length']) try: request = ceo_pb2.AddUser() request.username = username request.password = password request.realname = name request.program = program request.email = email if club_rep: request.type = ceo_pb2.AddUser.CLUB_REP else: request.type = ceo_pb2.AddUser.MEMBER out = remote.run_remote('adduser', request.SerializeToString()) response = ceo_pb2.AddUserResponse() response.ParseFromString(out) if any(message.status != 0 for message in response.messages): raise MemberException('\n'.join(message.message for message in response.messages)) except remote.RemoteException, e: raise MemberException(e)
def change_email(username, forward): try: request = ceo_pb2.UpdateMail() request.username = username request.forward = forward out = remote.run_remote('mail', request.SerializeToString()) response = ceo_pb2.AddUserResponse() response.ParseFromString(out) if any(message.status != 0 for message in response.messages): return '\n'.join(message.message for message in response.messages) except remote.RemoteException, e: raise MemberException(e)
def create_mysql(username): try: request = ceo_pb2.AddMySQLUser() request.username = username out = remote.run_remote('mysql', request.SerializeToString()) response = ceo_pb2.AddMySQLUserResponse() response.ParseFromString(out) if any(message.status != 0 for message in response.messages): raise MySQLException('\n'.join(message.message for message in response.messages)) return response.password except remote.RemoteException, e: raise MySQLException(e)
def subscribe_to_mailing_list(name): member = get(name) if member is not None: return remote.run_remote('mailman', name) else: return 'Error: member does not exist'