def open(self): """Open a new session and log in with given username and password.""" response = get_service('Login').request( username=self.username, password=self.password) try: self.user_id = response['user_id'] except KeyError: messages = listify(response['messages']) raise LoginFailed(*messages)
def create(username, password, email): """Create a new user. Returns the user id of the new user, if everything goes well. Arguments: username -- The desired username. Must be unique in the system. Length 4-20 characters. password -- User's password. email -- User's email address. Exceptions: ValueError -- Given parameters were invalid. """ register_service = get_service('Register') response = register_service.request( username=username, password=password, email=email) if 'messages' in response: messages = listify(response['messages']) raise ValueError(*messages) return response['user_id']