Пример #1
0
 def set_password(cls, user_name, passwd):
     pass_hash = sha256_crypt.encrypt(passwd)
     try:
         User.objects(username=user_name).update_one(set__password=pass_hash)
         Console.info("User password updated.")
     except:
         Console.error("Oops! Something went wrong while trying to set user password")
Пример #2
0
 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)
Пример #3
0
 def set_user_status(cls, user_name, status):
     if user_name:
         try:
             User.objects(username=user_name).update_one(set__status=status)
         except:
             Console.error("Oops! Something went wrong while trying to amend user status")
     else:
         Console.error("Please specify the user to be amended")
Пример #4
0
 def set_role(cls, user_name, role):
     try:
         if role in ROLE:
             User.objects(username=user_name).update_one(push__roles=role)
             Console.info("Role {0} added to user {1}".format(role, user_name))
         else:
             Console.error("Please specify a valid role. Role {0} is invalid.".format(role))
     except:
         Console.error("Oops! Something went wrong while trying to set user role.")
Пример #5
0
    def get_unique_username(cls, proposal):
        """
        Gets a unique username from a proposal. This is achieved while appending a number at the end.

        :param proposal: the proposed username
        :type proposal: String
        """
        new_proposal = proposal.lower()
        num = 1
        username = User.objects(username=new_proposal)
        while username.count() > 0:
            new_proposal = proposal + str(num)
            username = User.objects(username=new_proposal)
            num += 1
        return new_proposal
Пример #6
0
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
Пример #7
0
 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)
Пример #8
0
    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
Пример #9
0
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
Пример #10
0
    def find(cls, email=None):
        """
        Returns the users based on the given query.
        If no email is specified all users are returned.
        If the email is specified we search for the user with the given e-mail.

        :param email: email
        :type email: email address
        """
        if email is None:
            return User.objects()
        else:
            found = User.objects(email=email)
            if found.count() > 0:
                return User.objects()[0]
            else:
                return None
Пример #11
0
    def find_user(cls, username):
        """
        Returns a user based on the username

        :param username:
        :type username:
        """
        return User.object(username=username)
Пример #12
0
    def __init__(self):
        # config = ConfigDict(filename=config_file("/cloudmesh_server.yaml"))
        # port = config['cloudmesh']['server']['mongo']['port']

        # db = connect('manage', port=port)
        self.users = User.objects()

        db_name = get_mongo_dbname_from_collection("manage")
        if db_name:
            meta = {'db_alias': db_name}
Пример #13
0
    def validate_email(cls, email):

        """
        Verifies if the email of the user is not already in the users.
        :param email: email id of the user
        :return: true or false
        """
        user = User.objects(email=email)
        valid = user.count() == 0
        return valid
Пример #14
0
 def list_users(cls, display_fmt=None, username=None, status=None):
     # req_fields = ["username", "title", "firstname", "lastname",
     # "email", "phone", "url", "citizenship",
     #               "institution", "institutionrole", "department",
     #               "advisor", "address", "status", "projects"]
     req_fields = ["username", "firstname", "lastname",
                   "email", "phone", "institution", "institutionrole",
                   "advisor", "address", "status", "projects", "roles"]
     try:
         if username is None:
             if status:
                 if status not in STATUS:
                     Console.info("Invalid status requested.. Displaying all users..")
                     user_json = User.objects.only(*req_fields).to_json()
                 else:
                     user_json = User.objects(status=status).only(*req_fields).to_json()
             else:
                 user_json = User.objects.only(*req_fields).to_json()
             user_dict = json.loads(user_json)
             if user_dict:
                 if display_fmt != 'json':
                     cls.display(user_dict, username)
                 else:
                     cls.display_json(user_dict, username)
             else:
                 Console.info("No users in the database.")
         else:
             user_json = User.objects(username=username).to_json()
             users_list = json.loads(user_json)
             for item in users_list:
                 users_dict = item
                 if users_dict:
                     if display_fmt != 'json':
                         cls.display_two_columns(users_dict)
                     else:
                         cls.display_json(users_dict, username)
                 else:
                     Console.error("User not in the database.")
     except:
         Console.error("Oops.. Something went wrong in the list users method " + sys.exc_info()[0])
Пример #15
0
 def get_user_status(cls, user_name):
     if user_name:
         try:
             user = User.objects(username=user_name).only('status')
             if user:
                 for entry in user:
                     return entry.status
             else:
                 return
         except:
             Console.error("Oops! Something went wrong while trying to get user status")
     else:
         Console.error("Please specify the user get status")
Пример #16
0
 def list_users_json(cls):
     # req_fields = ["username", "title", "firstname", "lastname",
     # "email", "phone", "url", "citizenship",
     #               "institution", "institutionrole", "department",
     #               "advisor", "address", "status", "projects"]
     req_fields = ["username", "firstname", "lastname",
                   "email", "phone", "institution", "institutionrole",
                   "advisor", "address", "status", "projects"]
     try:
             user_json = User.objects().to_json()
             return user_json
     except:
         Console.error("Oops.. Something went wrong in the list users method " + sys.exc_info()[0])
Пример #17
0
 def remove_project_reviewer(cls, project_id, username):
     if project_id:
         try:
             found = User.objects(username=username)
             if found.count() > 0:
                 Project.objects(project_id=project_id).update_one(pull__reviewers=username)
                 Console.info("User `{0}` removed as Reviewer.".format(username))
             else:
                 Console.error("Please specify a valid user")
         except:
             Console.error("Oops! Something went wrong while trying to remove project reviewer")
     else:
         Console.error("Please specify the project to be amended")
Пример #18
0
 def delete_user(cls, user_name=None):
     if user_name:
         try:
             user = User.objects(username=user_name)
             if user:
                 user.delete()
                 if user_name != "super":
                     Console.info("User " + user_name + " removed from the database.")
             else:
                 Console.error("User with the name '{0}' does not exist.".format(user_name))
         except:
             Console.error("Oops! Something went wrong while trying to remove a user")
     else:
         Console.error("Please specify the user to be removed")
Пример #19
0
    def add_user(cls, user_name, project_id, role):
        """
        Adds a member to the project.

        :param role: the role of the user
        :type role: String
        :param user_name: the username
        :type user_name: String
        :param project_id: the project id
        """

        if role not in ROLES_LIST:
            Console.error("Invalid role `{0}`".format(role))
            return

        """adds members to a particular project"""
        user = User.objects(username=user_name).first()
        project = Project.objects(project_id=project_id).first()
        if project:
            if user and role != 'alumni':
                if role == "member":
                    Project.objects(project_id=project_id).update_one(push__members=user)
                    User.objects(username=user_name).update_one(push__projects=project)
                    Console.info("User `{0}` added as Project member.".format(user_name))
                elif role == "lead":
                    Project.objects(project_id=project_id).update_one(push__lead=user)
                    Console.info("User `{0}` set as Lead.".format(user_name))
                else:
                    Console.error("Role `{0}` cannot be amended".format(role))
            elif role == "alumni":
                Project.objects(project_id=project_id).update_one(push__alumnis=user_name)
                Console.info("User `{0}` added as Alumni.".format(user_name))
            else:
                Console.error("The user `{0}` has not registered with Future Systems".format(user_name))
        else:
            Console.error("The project `{0}` is not registered with Future Systems".format(project_id))
Пример #20
0
 def remove_user(cls, user_name, project_id, role):
     if role not in ROLES_LIST:
         Console.error("Invalid role `{0}`".format(role))
         return
     user = User.objects(username=user_name).first()
     if user and role != "alumni":
         if role == "member":
             Project.objects(project_id=project_id).update_one(pull__members=user)
             Console.info("User `{0}` removed as Project member.".format(user_name))
         elif role == "lead":
             Project.objects(project_id=project_id).update_one(pull__lead=user)
             Console.info("User `{0}` removed as Project lead.".format(user_name))
     elif role == "alumni":
         Project.objects(project_id=project_id).update_one(pull__alumnis=user)
         Console.info("User `{0}` removed as alumni.".format(user_name))
     else:
         Console.error("The user `{0}` has not registered with Future Systems".format(user_name))
Пример #21
0
def get_current_user_role():
    filename = path_expand("~/.cloudmesh/{0}/{1}".format("accounts", ".config"))
    with open(filename, 'r') as yamlfile:
        cfg = yaml.load(yamlfile)
        username = cfg['user']
    db_name = get_mongo_dbname_from_collection("manage")
    if db_name:
        meta = {'db_alias': db_name}
    ##
    ##
    obj = Mongo()
    obj.check_mongo()
    ##
    ##
    get_mongo_db("manage", DBConnFactory.TYPE_MONGOENGINE)
    found = User.objects(username=username).only('roles').first()
    return found.roles
    pass
Пример #22
0
 def __init__(self):
     obj = Mongo()
     obj.check_mongo()
     get_mongo_db("manage", DBConnFactory.TYPE_MONGOENGINE)
     self.projects = Project.objects()
     self.users = User.objects()
Пример #23
0
 def check_exists(cls, user_name):
     return len(User.objects(username=user_name)) > 0