def external_validator(self, provider, access_code, request): """ Calls the social backend to validate the access_code and get information """ strategy = load_strategy(request=get_request()) log.debug('Loading provider backend %s.', request.provider) try: backend = load_backend( strategy, provider, reverse( "%s:complete" % NAMESPACE, args=( provider,))) except MissingBackend: raise errors.InvalidRequestError( description='Invalid provider given', request=request) log.debug( 'Dispatching authentication to provider %s.', request.provider) try: user = backend.do_auth(access_token=request.access_token) except requests.HTTPError as e: raise errors.InvalidRequestError( description="Backend responded with HTTP{0}: {1}.".format( e.response.status_code, e.response.text), request=request) if not user: raise errors.InvalidGrantError( 'Invalid access-code', request=request) if not user.is_active: raise errors.InvalidGrantError('User inactive', request=request) request.user = user return True
def logout_action(request): request = get_request() login_type = request.session['login_type'] if login_type == '1': access_token = request.session['admin_access_token'] user = Corporate_Login_Access_Token.objects.get( access_token=access_token) request.session['admin_login_type'] = '' request.session['admin_access_token'] = '' elif login_type == '2': access_token = request.session['approves_1_access_token'] user = Corporate_Approves_1_Login_Access_Token.objects.get( access_token=access_token) request.session['approves_1_login_type'] = '' request.session['approves_1_access_token'] = '' elif login_type == '3': access_token = request.session['approves_2_access_token'] user = Corporate_Approves_2_Login_Access_Token.objects.get( access_token=access_token) request.session['approves_2_login_type'] = '' request.session['approves_2_access_token'] = '' elif login_type == '4': access_token = request.session['spoc_access_token'] user = Corporate_Spoc_Login_Access_Token.objects.get( access_token=access_token) request.session['spoc_login_type'] = '' request.session['spoc_token'] = '' elif login_type == '6': access_token = request.session['employee_access_token'] user = Corporate_Employee_Login_Access_Token.objects.get( access_token=access_token) request.session['employee_login_type'] = '' request.session['employee_access_token'] = '' elif login_type == '10': access_token = request.session['agent_access_token'] user = Corporate_Agent_Login_Access_Token.objects.get( access_token=access_token) request.session['agent_login_type'] = '' request.session['agent_access_token'] = '' else: return None user.expiry_date = datetime.now() # change field user.save() # this will update only #logout(request) # the user is now LogOut return HttpResponseRedirect("/login")
def get(cls, name): all_config = getattr(get_request(), 'all_config', None) if not all_config: all_config = cls.cache_all_config() return all_config.get(name, None)
def cache_all_config(cls): all_config = {} for cfg in cls.objects.all(): all_config[cfg.name] = cfg setattr(get_request(), 'all_config', all_config) return all_config
def test(request1): from django_global_request.middleware import get_request request2 = get_request() assert request1 == request2 return HttpResponse("OK")
def save(self, *args, **kwargs): request = get_request() project_name_obj = Profile.objects.get(user_id=request.user.id) self.project = project_name_obj.id super().save(*args, **kwargs)
def user_directory_path(instance, filename): # file will be uploaded to MEDIA_ROOT/user_project_dir/<filename> request = get_request() project_name_obj = Profile.objects.get(user_id=request.user.id) return '{0}/{1}'.format(project_name_obj.project_name, filename)
def get_user(): """Take an access to the global user instance.""" request = get_request() if not request: return AnonymousUser() return request.user
def my_handler(sender, instance, created, **kwargs): corporate_name = instance.Company_Name corporate_location = instance.Company_Location contact_person_name = instance.Contact_Name contact_person_no = instance.Contact_Number contact_person_email = instance.Contact_Email message = instance.Message if (created): print("create call") #message = "" signup = SignupEmail(corporate_name, corporate_location, contact_person_name, contact_person_no, contact_person_email, message) #resp1 = signup.send_email() thread = Thread(target=signup.send_email, args=()) thread.start() else: print("update call") print(instance.id) ag_id = instance.Assigned_Sales_Person ag_email = Corporate_Agent.objects.get(id=ag_id).email ag_name = Corporate_Agent.objects.get(id=ag_id).user_name ag_no = Corporate_Agent.objects.get(id=ag_id).contact_no message = "" if instance.Status == "Closed-Win": try: corporate_name = instance.Company_Name ref = Corporate.objects.get(corporate_name=corporate_name) print("company with same name allready exist") except ObjectDoesNotExist: corporate_name = instance.Company_Name corporate_city = instance.Company_Location corporate_code = instance.Company_Name contact_person_name = instance.Contact_Name contact_person_no = instance.Contact_Number contact_person_email = instance.Contact_Email contact_address_line1 = instance.Contact_Address contact_address_line2 = instance.Contact_Address_Line2 contact_address_line3 = instance.Contact_Address_Line3 company = Corporate() company.corporate_name = corporate_name company.corporate_city = corporate_city company.corporate_code = corporate_code company.contact_person_name = contact_person_name company.contact_person_no = contact_person_no company.contact_person_email = contact_person_email company.contact_address_line1 = contact_address_line1 company.contact_address_line2 = contact_address_line2 company.contact_address_line3 = contact_address_line3 company.has_auth_level = 0 company.no_of_auth_level = 0 company.has_assessment_codes = 0 company.is_radio = 0 company.is_local = 1 company.is_outstation = 1 company.is_bus = 1 company.is_train = 1 company.is_hotel = 1 company.is_meal = 0 company.is_flight = 1 company.is_water_bottles = 1 company.is_reverse_logistics = 1 company.is_deleted = 0 company.is_send_email = 0 company.is_send_sms = 0 company.save() request = get_request() login_type = request.session['agent_login_type'] access_token = request.session['agent_access_token'] access_token_auth = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(60)) password = "******" payload = { 'corporate_id': company.pk, 'user_id': request.user.id, 'login_type': login_type, 'access_token': access_token, 'name': contact_person_name, 'email': contact_person_email, 'cid': '', 'contact_no': contact_person_no, 'is_radio': 0, 'is_local': 1, 'is_outstation': 1, 'is_bus': 1, 'is_train': 1, 'is_hotel': 1, 'is_meal': 0, 'is_flight': 1, 'is_water_bottles': 1, 'is_reverse_logistics': 1, 'access_token_auth': access_token_auth, 'password': password } url = settings.API_BASE_URL + "add_admin" company111 = getDataFromAPI(login_type, access_token, url, payload) payload1 = { 'corporate_id': company.pk, 'rm_level_1_id': ag_id, 'is_active': 1 } url2 = settings.API_BASE_URL + "add_relationship_managements" company1111 = getDataFromAPI(login_type, access_token, url2, payload1) message = "Congratulation on converting your lead to Closed-Win. Your diligence, self-motivation as well as dedication to always go the extra mile in order to achieve the best possible results is really admirable. Thank you for your hard work and effort." print( "Lead is converted to new company after closed-win status") signup1 = Lead_Status_Change_Email( message, "", ag_email, ag_name, instance.Company_Name, instance.Contact_Name, instance.Contact_Email, instance.Contact_Number, instance.Company_Location) resp1 = signup1.send_email() print("in mail send fun") print(resp1) elif instance.Status == "Closed-Lost": message = "Sorry to loose you, We will miss you, let me know if we could be of any help in future. CoTrav Team" signup1 = Lead_Status_Change_Email(message, "", ag_email, ag_name, instance.Company_Name, instance.Contact_Name, instance.Contact_Email, instance.Contact_Number, instance.Company_Location) resp1 = signup1.send_email_lost() elif instance.Status == "Assigned": message = "New Lead has been assigned to your queue" # message = "Lead with id " + str(instance.id) + " is updated and assigned to agent " + ag_email status = instance.Status signup = Lead_Status_Change_Email(message, status, ag_email, ag_name, instance.Company_Name, instance.Contact_Name, instance.Contact_Email, instance.Contact_Number, instance.Company_Location) resp1 = signup.send_email() message1 = "A Relationship Manager from Cotrav Team has been assigned to you to solve all your queries. Please find the details below." signup1 = Lead_Email_To_Company_assign_agent( message1, ag_email, ag_name, ag_no, instance.Contact_Name, instance.Contact_Email, instance.Contact_Number) resp1 = signup1.send_email() print("in mail send fun") print(resp1) else: message = "Lead Status Changed " status = instance.Status signup = Lead_Status_Change_Email(message, status, ag_email, ag_name, instance.Company_Name, instance.Contact_Name, instance.Contact_Email, instance.Contact_Number, instance.Company_Location) resp1 = signup.send_email() print("in mail send fun") print(resp1)