def user_register(self, authToken, method, email): if not authToken: return('Could not authenticate') check_user_register = Zatiq_Users.objects(user_email=email) if len(check_user_register) > 0: return(self.user_login(authToken, email, method)) else: user_info = self.get_user_info(authToken, method) user_id = user_info['id'] user_email = user_info['email'] user_name = user_info['name'] api_token = self.generate_zatiq_api_token() if method == 'google': if self.check_user_exists(user_id, user_email, method, authToken) == False: user_register = Zatiq_Users.objects(auth_token=authToken).update_one(upsert=True, set__user_email=user_email, set__user_name=user_name, set__google_id=user_id, set__zatiq_token=api_token, set__preferences__halal=False, set__preferences__spicy=False, set__preferences__kosher=False, set__preferences__healthy=False, set__preferences__vegan=False, set__preferences__vegetarian=False, set__preferences__gluten_free=False, set__preferences__lactose_free=False, set__preferences__milk_allergy=False, set__preferences__has_eggs=False, set__preferences__fish_allergy=False, set__preferences__crustacean_allergy=False, set__preferences__has_wheat=False, set__preferences__has_soybeans=False, set__preferences__pescatarian=False, set__preferences__has_peanuts=False, set__preferences__has_treenuts=False, set__preferences__jain=False, set__preferences__omnivore=False) return(self.user_login(authToken, user_email, method)) else: return(self.user_login(authToken, user_email, method)) if method == 'facebook': if self.check_user_exists(user_id, user_email, method, authToken) == False: user_register = Zatiq_Users.objects(auth_token=authToken).update_one(upsert=True, set__user_email=user_email, set__user_name=user_name, set__facebook_id=user_id, set__zatiq_token=api_token, set__preferences__halal=False, set__preferences__spicy=True, set__preferences__kosher=False, set__preferences__healthy=False, set__preferences__vegan=False, set__preferences__vegetarian=False, set__preferences__gluten_free=False, set__preferences__lactose_free=False, set__preferences__milk_allergy=False, set__preferences__has_eggs=False, set__preferences__fish_allergy=False, set__preferences__crustacean_allergy=False, set__preferences__has_wheat=False, set__preferences__has_soybeans=False, set__preferences__pescatarian=False, set__preferences__has_peanuts=False, set__preferences__has_treenuts=False, set__preferences__jain=False, set__preferences__omnivore=False) return(self.user_login(authToken, user_email, method)) else: return(self.user_login(authToken, user_email, method))
def get_user_profile(self, api_token): if not api_token: return('Could not authenticate') if self.check_valid_api_token(api_token) == True: if self.check_business_or_user(api_token) == 'user': try: get_user_info = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) user_email = get_user_info[0].user_email auth_token = get_user_info[0].auth_token user_name = get_user_info[0].user_name preferences = self.generate_preferences_dict(get_user_info[0].preferences) return([user_email, auth_token, user_name, preferences]) elif self.check_business_or_user(api_token) == 'business': try: get_user_info = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) user_email = get_user_info[0].business_email user_name = get_user_info[0].business_name preferences = self.generate_preferences_dict(get_user_info[0].preferences) return([user_email, user_name, preferences]) else: return('Could not find that user') else: return('Could not authenticate')
def get_user_id_by_api_token(self, api_token): valid_token = Zatiq_Users.objects(zatiq_token=api_token) if (len(valid_token) > 0): user_id = valid_token[0].id return(user_id) else: return(None)
def check_user(self, api_token): try: user_token = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(user_token) > 0: return('user')
def update_user_preferences(self, api_token, preferences): if not api_token: return('Could not authenticate') if self.check_valid_api_token(api_token) == True: if self.check_business_or_user(api_token) == 'user': try: Zatiq_Users.objects(zatiq_token=api_token).update_one(upsert=False, set__preferences__halal=preferences['halal'], set__preferences__spicy=preferences['spicy'], set__preferences__kosher=preferences['kosher'], set__preferences__healthy=preferences['healthy'], set__preferences__vegan=preferences['vegan'], set__preferences__vegetarian=preferences['vegetarian'], set__preferences__gluten_free=preferences['gluten_free'], set__preferences__lactose_free=preferences['lactose_intolerant'], set__preferences__milk_allergy=preferences['milk_allergy'], set__preferences__has_eggs=preferences['eggs_allergy'], set__preferences__fish_allergy=preferences['fish_allergy'], set__preferences__crustacean_allergy=preferences['crustacean_allergy'], set__preferences__has_wheat=preferences['wheat_allergy'], set__preferences__has_soybeans=preferences['soybeans_allergy'], set__preferences__jain=preferences['jain'], set__preferences__omnivore=preferences['omnivore'], set__preferences__pescatarian=preferences['pescatarian'], set__preferences__has_peanuts=preferences['peanuts_allergy'], set__preferences__has_treenuts=preferences['treenuts_allergy']) except Exception as e: return("Error \n %s" % (e)) try: get_user_info = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) user_email = get_user_info[0].user_email auth_token = get_user_info[0].auth_token user_name = get_user_info[0].user_name preferences = self.generate_preferences_dict(get_user_info[0].preferences) return([user_email, auth_token, user_name, preferences]) elif self.check_business_or_user(api_token) == 'business': try: Zatiq_Businesses.objects(zatiq_token=api_token).update_one(upsert=False, set__preferences__halal=preferences['halal'], set__preferences__spicy=preferences['spicy'], set__preferences__kosher=preferences['kosher'], set__preferences__healthy=preferences['healthy'], set__preferences__vegan=preferences['vegan'], set__preferences__vegetarian=preferences['vegetarian'], set__preferences__gluten_free=preferences['gluten_free'], set__preferences__lactose_free=preferences['lactose_intolerant'], set__preferences__milk_allergy=preferences['milk_allergy'], set__preferences__has_eggs=preferences['eggs_allergy'], set__preferences__fish_allergy=preferences['fish_allergy'], set__preferences__crustacean_allergy=preferences['crustacean_allergy'], set__preferences__has_wheat=preferences['wheat_allergy'], set__preferences__has_soybeans=preferences['soybeans_allergy'], set__preferences__jain=preferences['jain'], set__preferences__omnivore=preferences['omnivore'], set__preferences__pescatarian=preferences['pescatarian'], set__preferences__has_peanuts=preferences['peanuts_allergy'], set__preferences__has_treenuts=preferences['treenuts_allergy']) except Exception as e: return("Error \n %s" % (e)) try: get_user_info = Zatiq_Businesses.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) user_email = get_user_info[0].business_email user_name = get_user_info[0].business_name preferences = self.generate_preferences_dict(get_user_info[0].preferences) return([user_email, user_name, preferences]) else: return('Could not find that user') else: return('Could not authenticate')
def get_reviewer_id_by_api_token(self, api_token): try: valid_token = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return ("Error \n %s" % (e)) if len(valid_token) > 0: return (valid_token[0].id) else: return (None)
def check_user_exists(self, id, user_email, method, authToken): if method == "google": check_user_exists = Zatiq_Users.objects(google_id=id, user_email=user_email) if len(check_user_exists) > 0: update_user_auth_token = Zatiq_Users.objects(google_id=id).update_one(upsert=True, set__auth_token=authToken) return(True) else: return(False) if method == 'facebook': check_user_exists = Zatiq_Users.objects(facebook_id=id, user_email=user_email) if len(check_user_exists) > 0: update_user_auth_token = Zatiq_Users.objects(facebook_id=id).update_one(upsert=True, set__auth_token=authToken) return(True) else: return(False) if method != 'google' and method != 'facebook': return(False)
def check_valid_api_token(self, api_token): try: valid_token = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(valid_token) > 0: return(True) else: try: valid_token = Zatiq_Businesses.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(valid_token) > 0: return(True) else: return(False)
def user_login(self, authToken, userEmail, method): if not authToken: return('Could not authenticate') if not userEmail: return('Could not authenticate') check_user_login = Zatiq_Users.objects(user_email=userEmail) if len(check_user_login) > 0: user_info = self.get_user_info(authToken, method) user_name = user_info['name'] user_email = user_info['email'] api_token = check_user_login[0].zatiq_token return([user_name, user_email, api_token]) else: return('Could not authenticate')
def get_user_preferences(self, api_token): preferences_list = [] try: zatiq_user = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(zatiq_user) > 0: for preference in zatiq_user[0].preferences: if zatiq_user[0].preferences[preference] == True: preferences_list.append(str(preference)) print(preferences_list) return(preferences_list) else: return([])
def check_business_or_user(self, api_token): try: zatiq_user = Zatiq_Users.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(zatiq_user) > 0: return('user') else: try: zatiq_user = Zatiq_Businesses.objects(zatiq_token=api_token) except Exception as e: return("Error \n %s" % (e)) if len(zatiq_user) > 0: return('business') else: return('none')
def check_api_token_exists(self, api_token): check_api_token = Zatiq_Users.objects(zatiq_token=api_token) if len(check_api_token) > 0: self.generate_zatiq_api_token() else: return(False)
def check_valid_api_token(self, api_token): valid_token = Zatiq_Users.objects(zatiq_token=api_token) if len(valid_token) > 0: return (True) else: return (False)