예제 #1
0
class UpdateProfile:
    def __init__(self):
        self.log = LoggerUtil(self.__class__.__name__).get()
        self.config = ConfigUtil.get_config_instance()
        self.db_utils = DBUtils()

    def get_client(self):
        address = self.config['mongo']['address']
        port = self.config['mongo']['port']
        auth_db = self.config['mongo']['auth_db']
        is_auth_enabled = self.config['mongo']['is_auth_enabled']
        username = self.config['mongo']['username']
        password = self.config['mongo']['password']

        client = self.db_utils.get_client(address=address,
                                          port=port,
                                          username=username,
                                          password=password,
                                          auth_db=auth_db,
                                          is_auth_enabled=is_auth_enabled)
        return client

    @staticmethod
    def insert_query(source, destination, time, date, num_seats_req, phone_num,
                     email, preferences):
        query = dict()
        query['source'] = source
        query['destination'] = destination
        query['time'] = time
        query['date'] = date
        query['num_seats_req'] = num_seats_req
        query['phone_num'] = phone_num
        query['email'] = email
        query['preferences'] = preferences
        return json.dumps(query)

    def update(self, source, destination, time, date, num_seats_req, phone_num,
               email, preferences):
        client = self.get_client()

        users_database_name = self.config['mongo']['users_database']
        users_hist_collection_name = self.config['mongo'][
            'users_hist_collection_name']
        database = client[users_database_name]
        users_hist_collection = database[users_hist_collection_name]

        query = self.insert_query(source=source,
                                  destination=destination,
                                  time=time,
                                  date=date,
                                  num_seats_req=num_seats_req,
                                  phone_num=phone_num,
                                  email=email,
                                  preferences=preferences)
        try:
            users_hist_collection.insert(query)
            self.log.info(
                "Updated profile for user with email : {}".format(email))
        except Exception as e:
            self.log.error("Error : {}".format(e))
예제 #2
0
class UserRegistration:
    def __init__(self):
        self.log = LoggerUtil(self.__class__.__name__).get()
        self.config = ConfigUtil.get_config_instance()
        self.db_utils = DBUtils()

    def get_client(self):
        address = self.config['mongo']['address']
        port = self.config['mongo']['port']
        auth_db = self.config['mongo']['auth_db']
        is_auth_enabled = self.config['mongo']['is_auth_enabled']
        username = self.config['mongo']['username']
        password = self.config['mongo']['password']

        client = self.db_utils.get_client(address=address,
                                          port=port,
                                          username=username,
                                          password=password,
                                          auth_db=auth_db,
                                          is_auth_enabled=is_auth_enabled)
        return client

    @staticmethod
    def insert_query(name, email, contact, password):
        query = dict()
        query['name'] = name
        query['email'] = email
        query['contact'] = contact
        query['password'] = password
        query['auth'] = True
        return query

    def add_user(self, **kwargs):
        name = kwargs['name']
        email = kwargs['email']
        contact = kwargs['contact']
        password = kwargs['password']

        client = self.get_client()

        users_database_name = self.config['mongo']['users_database']
        add_users_collection_name = self.config['mongo'][
            'add_users_collection']
        database = client[users_database_name]
        add_users_collection = database[add_users_collection_name]

        query = self.insert_query(name, email, contact, password)
        try:
            add_users_collection.insert(query)
            self.log.info("Added user with username : {}".format(email))
        except Exception as e:
            self.log.error("Error : {}".format(e))
예제 #3
0
 def __init__(self):
     self.log = LoggerUtil(self.__class__.__name__).get()
     self.config = ConfigUtil.get_config_instance()
     self.db_utils = DBUtils()
예제 #4
0
class UserAuthentication:
    def __init__(self):
        self.log = LoggerUtil(self.__class__.__name__).get()
        self.db_utils = DBUtils()
        self.config = ConfigUtil.get_config_instance()

    def get_client(self):
        address = self.config['mongo']['address']
        port = self.config['mongo']['port']
        auth_db = self.config['mongo']['auth_db']
        is_auth_enabled = self.config['mongo']['is_auth_enabled']
        username = self.config['mongo']['username']
        password = self.config['mongo']['password']

        client = self.db_utils.get_client(address=address,
                                          port=port,
                                          username=username,
                                          password=password,
                                          auth_db=auth_db,
                                          is_auth_enabled=is_auth_enabled)
        return client

    @staticmethod
    def user_auth_query(username, password):
        query = dict()
        query['username'] = username
        query['password'] = password
        return query

    def check_in_db(self, username, password):
        users_database = self.config['mongo']['users_database']
        login_collection = self.config['mongo']['login_collection']
        client = self.get_client()
        database = client[users_database]
        login_collection = database[login_collection]

        query = self.user_auth_query(username=username, password=password)
        cursor = login_collection.find(query)
        for doc in cursor:
            if 'auth' in doc:
                return True
            else:
                return False
        return False

    @staticmethod
    def username_avail_query(username):
        query = dict()
        query['email'] = username
        return query

    def is_username_available(self, username):
        users_database = self.config['mongo']['users_database']
        client = self.get_client()
        database = client[users_database]
        login_collection = database['login_collection']

        query = self.username_avail_query(username=username)
        cursor = login_collection.find(query)
        for doc in cursor:
            if 'auth' in doc:
                return False
            else:
                return True
        return True