def do_cli(manager, options, session=None): if options.action == 'passwd': try: change_password(password=options.password, session=session) except WeakPassword as e: console(e.value) return console('Updated password') if options.action == 'gentoken': token = generate_token(session=session) console('Generated new token %s' % token) if options.action == 'showtoken': user = get_user() console('Token: %s' % user.token)
def do_cli(manager, options, session=None): if hasattr(options, 'user'): options.user = options.user.lower() if options.action == 'passwd': user = user_exist(name=options.user, session=session) if not user: console('User %s does not exist' % options.user) return try: change_password(user_name=user.name, password=options.password, session=session) except WeakPassword as e: console(e.value) return console('Updated password for user %s' % options.user) if options.action == 'gentoken': user = user_exist(name=options.user, session=session) if not user: console('User %s does not exist' % options.user) return user = generate_token(user_name=user.name, session=session) console('Generated new token for user %s' % user.name) console('Token %s' % user.token)
def get(self, session=None): """ Change current user token """ token = generate_token(username=current_user.name, session=session) return {'token': token}