def create(self, args): """ Create a new user. """ if not self.settings.user_registration_enabled: print messages['RegisterDisabled'].format( self.settings.user_registration_url) return self.api.set_token(None) if args.name and args.email and args.password: name = args.name[0] email = args.email[0] password = args.password[0] else: name = raw_input('Username: '******'CommandNotImplemented') print messages['UserCreatedNowCheckEmail']
def create(self, args): """ Create a new user. """ if not self.settings.user_registration_enabled: print messages['RegisterDisabled'].format(self.settings.user_registration_url) return self.api.set_token(None) if args.name and args.email and args.password: name = args.name[0] email = args.email[0] password = args.password[0] else: name = raw_input('Username: '******'CommandNotImplemented') print messages['UserCreatedNowCheckEmail']
def run(args, api): """ run takes care of calling the action with the needed arguments parsed using argparse. We first try to call the action. In case the called action requires a valid token and the api instance does not have one a TokenRequiredError gets raised. In this case we catch the error and ask the user for a email/password combination to create a new token. After that we call the action again. pycclib raises an exception any time the API does answer with a HTTP STATUS CODE other than 200, 201 or 204. We catch these exceptions here and stop cctrlapp using sys.exit and show the error message to the user. """ # check if there is a newer version of cctrl or pycclib try: check_for_updates(api.check_versions()['cctrl']) except KeyError: pass while True: try: try: args.func(args) except TokenRequiredError: # check ENV for credentials first try: email = env.pop('CCTRL_EMAIL') password = env.pop('CCTRL_PASSWORD') except KeyError: email, password = get_credentials() try: api.create_token(email, password) except UnauthorizedError: sys.exit(messages['NotAuthorized']) else: pass except ParseAppDeploymentName: sys.exit(messages['InvalidAppOrDeploymentName']) else: break except UnauthorizedError, e: if delete_tokenfile(): api.set_token(None) else: sys.exit(messages['NotAuthorized']) except ForbiddenError, e: sys.exit(messages['NotAllowed'])
def create(self, args): """ Create a new user. """ self.api.set_token(None) if args.name and args.email and args.password: name = args.name[0] email = args.email[0] password = args.password[0] else: name = raw_input('Username: '******'UserCreatedNowCheckEmail']
def run(args, api): """ run takes care of calling the action with the needed arguments parsed using argparse. We first try to call the action. In case the called action requires a valid token and the api instance does not have one a TokenRequiredError gets raised. In this case we catch the error and ask the user for a email/password combination to create a new token. After that we call the action again. pycclib raises an exception any time the API does answer with a HTTP STATUS CODE other than 200, 201 or 204. We catch these exceptions here and stop cctrlapp using sys.exit and show the error message to the user. """ while True: try: try: args.func(args) except cclib.TokenRequiredError: # check ENV for credentials first try: email = os.environ.pop('CCTRL_EMAIL') password = os.environ.pop('CCTRL_PASSWORD') except KeyError: email, password = get_credentials() try: api.create_token(email, password) except cclib.UnauthorizedError: sys.exit(messages['NotAuthorized']) else: pass except ParseAppDeploymentName: sys.exit(messages['InvalidAppOrDeploymentName']) else: break except cclib.UnauthorizedError, e: if delete_tokenfile(): api.set_token(None) else: sys.exit(messages['NotAuthorized']) except cclib.ForbiddenError, e: sys.exit(messages['NotAllowed'])