def random_user(): """ Returns a random user in a dict :rtype: dict """ firstname = fake.first_name() prefix = fake.prefix() data = User( status="pending", title=prefix[0], firstname=firstname, lastname=fake.last_name(), email=fake.safe_email(), username=firstname.lower(), active=False, password=sha256_crypt.encrypt("MyPassword"), phone=fake.phone_number(), department="IT", institution=fake.company(), institutionrole="Graduate Student", address=fake.address(), country="USA", citizenship="US", bio=fake.paragraph(), url=fake.url(), advisor=fake.name(), confirm=fake.word(), projects=[], ) return data
def create_user_from_file(cls, file_path): try: filename = path_expand(file_path) file_config = ConfigDict(filename=filename) except: Console.error("Could not load file, please check filename and its path") return try: user_config = file_config.get("cloudmesh", "user") user_name = user_config['username'] user = User() update_document(user, user_config) except: Console.error("Could not get user information from yaml file, " "please check you yaml file, users information must be " "under 'cloudmesh' -> 'users' -> user1...") return try: if cls.check_exists(user_name) is False: cls.add(user) Console.info("User created in the database.") else: Console.error("User with user name " + user_name + " already exists.") return except: Console.error("User creation in database failed, " + str(sys.exc_info())) return
def read_user(filename): """ Reads user data from a yaml file :param filename: The file name :type filename: String of the path """ stream = open(filename, 'r') data = yaml.load(stream) user = User( status=data["status"], username=data["username"], title=data["title"], firstname=data["firstname"], lastname=data["lastname"], email=data["email"], url=data["url"], citizenship=data["citizenship"], bio=data["bio"], password=data["password"], userid=data["userid"], phone=data["phone"], projects=data["projects"], institution=data["institution"], department=data["department"], address=data["address"], country=data["country"], advisor=data["advisor"], message=data["message"], ) return user
def run(self): banner("Install Cloudmesh Management") obj = Mongo() obj.check_mongo() get_mongo_db("manage", DBConnFactory.TYPE_MONGOENGINE) install.run(self) banner("Adding Super User") users = Users() found = User.objects(username='******') if not found: data = User( status="approved", title="None", firstname="Super", lastname="User", email="*****@*****.**", username="******", active=True, password=sha256_crypt.encrypt("MyPassword"), phone="555-555-5555", department="IT", institution="IU", institutionrole="Other", address="IU", country="United States(US)", citizenship="United States(US)", bio="Manage Project Committee", url="http://cloudmesh.github.io/cloudmesh.html", advisor="None", confirm=sha256_crypt.encrypt("MyPassword"), projects=[], ) users.add(data)