def TrustData(request): """ Get data to use for BaseTrust call: requester_email (from user.email), bundle, domain, owner_email :param request: :param user: logged in user :param organization: Organization Name :return: """ user = get_user_model() access_field = settings.USERNAME_FIELD print("User:"******"User(email):",request.user.email) u = user.objects.filter(**{access_field: request.user}) poetconf = getattr(settings, 'POET_CONF', {'MODE':"CHECK"}) poet_mode = poetconf['MODE'] if settings.DEBUG: print("User (u):", u) print("POET MODE:", poet_mode) if poet_mode == "AUTO_TRUST": # Set to trusted and current date/time and return org = Organization.objects.get(owner=request.user) org.trusted = True org.trusted_since = datetime.now() org.save() return HttpResponseRedirect(reverse('appmgmt:organization_view')) # No AUTO_TRUST so we process the form. if settings.DEBUG: print("AUTO TRUSTED Organization:", org.name) if request.method == 'POST': form = TrustForm(request.POST) if form.is_valid(): if settings.DEBUG: print("Valid Trust Form. Calling BaseTrust") # trust_bundle = forms.ChoiceField(choices=TRUST_BUNDLE_CHOICE) # trust_domain = forms.CharField(max_length=100,label="Trusted Application Domain") # owner_email = forms.EmailField(label="Trusted Application Owner Email") whitelist = BaseTrust(request, request.user.email, form.cleaned_data['trust_bundle'], form.cleaned_data['trust_domain'], form.cleaned_data['owner_email'], form.cleaned_data['shared_secret'], internal_call=True) if settings.DEBUG: print("Whitelist result:", whitelist) org = Organization.objects.get(owner=request.user) if whitelist['valid']: trust_info = whitelist['trust_info'] org.trusted = whitelist['valid'] tz = get_current_timezone() since_dt = parse_datetime(trust_info['validation_timestamp']) # since_dt = datetime.strptime(trust_info['validation_timestamp'], # '%Y-%m-%dT%H:%M:%S.%f%z').replace(tzinfo=tz) org.trusted_since = since_dt org.save() if settings.DEBUG: print("Org:", org, ":", org.trusted) return HttpResponseRedirect(reverse('appmgmt:organization_view')) else: # t=u.objects.get(**{access_field: request.user}) t = {'trust_bundle': "", 'trust_domain': "", 'administrator_email': ""} if settings.DEBUG: print("T:", t) form = TrustForm() return render(request, 'appmgmt/trust_form.html', {'form': form}) return HttpResponseRedirect(reverse('accounts:manage_account'))
def TrustData(request): """ Get data to use for BaseTrust call: requester_email (from user.email), bundle, domain, owner_email :param request: :param user: logged in user :param organization: Organization Name :return: """ user = get_user_model() print("User:"******"User(email):",request.user) u = user.objects.filter(email=request.user) if settings.DEBUG: print("User (u):", u) if request.method == 'POST': form = TrustForm(request.POST) if form.is_valid(): # trust_bundle = forms.ChoiceField(choices=TRUST_BUNDLE_CHOICE) # trust_domain = forms.CharField(max_length=100,label="Trusted Application Domain") # owner_email = forms.EmailField(label="Trusted Application Owner Email") whitelist = BaseTrust(request, request.user, form.cleaned_data['trust_bundle'], form.cleaned_data['trust_domain'], form.cleaned_data['owner_email'], form.cleaned_data['shared_secret'], internal_call=True) if settings.DEBUG: print("Whitelist result:", whitelist) org = Organization.objects.get(owner=request.user) if whitelist['valid']: trust_info = whitelist['trust_info'] org.trusted = whitelist['valid'] tz = get_current_timezone() until_dt = datetime.strptime(trust_info['expires'], '%Y%m%d.%H%M').replace(tzinfo=tz) org.trusted_until = until_dt org.save() if settings.DEBUG: print("Org:", org, ":", org.trusted) return HttpResponseRedirect(reverse('appmgmt:organization_view')) else: # t=u.objects.get(email=request.user) t = {'trust_bundle': "", 'trust_domain': "", 'administrator_email': ""} if settings.DEBUG: print("T:", t) form = TrustForm() return render(request, 'appmgmt/trust_form.html', {'form': form}) return HttpResponseRedirect(reverse('accounts:manage_account'))
def TrustData(request): """ Get data to use for BaseTrust call: requester_email (from user.email), bundle, domain, owner_email :param request: :param user: logged in user :param organization: Organization Name :return: """ user = get_user_model() access_field = settings.USERNAME_FIELD print("User:"******"User(email):", request.user.email) u = user.objects.filter(**{access_field: request.user}) if settings.DEBUG: print("User (u):", u) if request.method == 'POST': form = TrustForm(request.POST) if form.is_valid(): # trust_bundle = forms.ChoiceField(choices=TRUST_BUNDLE_CHOICE) # trust_domain = forms.CharField(max_length=100,label="Trusted Application Domain") # owner_email = forms.EmailField(label="Trusted Application Owner Email") whitelist = BaseTrust(request, request.user.email, form.cleaned_data['trust_bundle'], form.cleaned_data['trust_domain'], form.cleaned_data['owner_email'], form.cleaned_data['shared_secret'], internal_call=True) if settings.DEBUG: print("Whitelist result:", whitelist) org = Organization.objects.get(owner=request.user) if whitelist['valid']: trust_info = whitelist['trust_info'] org.trusted = whitelist['valid'] tz = get_current_timezone() until_dt = datetime.strptime(trust_info['expires'], '%Y%m%d.%H%M').replace(tzinfo=tz) org.trusted_until = until_dt org.save() if settings.DEBUG: print("Org:", org, ":", org.trusted) return HttpResponseRedirect(reverse('appmgmt:organization_view')) else: # t=u.objects.get(**{access_field: request.user}) t = {'trust_bundle': "", 'trust_domain': "", 'administrator_email': ""} if settings.DEBUG: print("T:", t) form = TrustForm() return render(request, 'appmgmt/trust_form.html', {'form': form}) return HttpResponseRedirect(reverse('accounts:manage_account'))