def subscribe_url(self, info): """ this function will subscribe the new info into the system :param self: :param info: :return: """ # todo : add confirm url content for user ... # todo : have to load url once and show content to user # todo : to version-ing reasons validate = validator.SchemaValidator(self.config['schema']['url_register_schema']) validate.check(info) info["credit"] = self.user_service.get_user_credit(info["user_id"]) # external info for new url info["url_id"] = uuid.uuid4().hex[0:20] info["is_valid"] = "yes" # the action will describe the correct activity in check point info["action"] = "add" url_count = len(self.get_urls({"user_id": info["user_id"]})) if url_count > info["credit"]["maximum_url"]: raise Exception("maximum url constraint has reached") for location in info["credit"]["url_check_locations"]: check_point = self.check_point_service.get_check_point_info_with_location(location) self.sender.send(destination=check_point["queue"], message=info) self.url_database.insert_url(info) return "url subscribed successfully"
def __init__(self): """ """ loader = config_loader.ConfigLoader() self.config = loader.get_config() self.validator = validator.SchemaValidator( schema_path=self.config["schema"]["handler_schema"]) self.url_service = url_service.UrlService()
def get_urls(self, requested_url_dic): """ :param requested_url_dic: :return: """ validate = validator.SchemaValidator(self.config['schema']['url_fetch_schema']) validate.check(requested_url_dic) return self.url_database.get_url_for(requested_url_dic["user_id"])
def confirm_user(self, confirm_dictionary): """ :param confirm_dictionary: :return: """ validate = validator.SchemaValidator( self.configuration['schema']['user_register_confirm_schema']) validate.check(confirm_dictionary) return self.user_database.confirm_user( confirm_dictionary["user_id"], confirm_dictionary["confirm_code"])
def authorize_user(self, authentication_dictionary): """ :param authentication_dictionary: :return: """ validate = validator.SchemaValidator( self.configuration['schema']['user_authentication_schema']) validate.check(authentication_dictionary) return self.user_database.check_user_password( authentication_dictionary["user_name"], authentication_dictionary["password"])
def add_check_point(self, info): """ :param info: type json :return: """ validate = validator.SchemaValidator( self.config['schema']['checkpoint_register_schema']) validate.check(info) self.database.insert_check_point(info) logger( "INFO", "check_point_service/check_point_service/add_check_point : check point has initialized successfully" ) return { 'status': True, 'result': 'check point registered successfully' }
def delete_url(self, info): """ update url as invalid :param info: :return: """ validate = validator.SchemaValidator(self.config['schema']['url_delete_schema']) validate.check(info) info["action"] = "delete" url = self.url_database.get_url(info['url_id']) # send into check points for location in url["credit"]["url_check_locations"]: check_point = self.check_point_service.get_check_point_info_with_location(location) self.sender.send(destination=check_point["queue"], message=info) self.url_database.delete_url(info['url_id']) return "url deleted successfully"
def register_user(self, new_user_dictionary): """ :param new_user_dictionary: :return: """ validate = validator.SchemaValidator( self.configuration['schema']['user_register_schema']) validate.check(new_user_dictionary) new_user_dictionary["user_id"] = uuid.uuid4().hex[0:20] new_user_dictionary["is_valid"] = "no" new_user_dictionary["confirm_code"] = uuid.uuid4().hex[0:20] # create user with free plan new_user_dictionary["plan"] = "free" new_user_dictionary["credit"] = self.finance_configuration[ new_user_dictionary["plan"]] # Generate a email confirm code and send into the user email address result = self.user_database.check_user(new_user_dictionary) if result["status"] is True: mail_info = { "to": new_user_dictionary["email_address"], "subject": "confirm code", "msg": "your confirm code is -- " + str(new_user_dictionary["confirm_code"]) } result["msg"] = "the confirm code has sent !" # todo : mail agent have some problems in sending email # self.mail_agent.send(title=mail_info['subject'], message=mail_info['msg'], to=mail_info['to']) # create user in database self.user_database.insert_user(new_user_dictionary) else: raise Exception("an error during create the user ") return new_user_dictionary['user_id']