in webapp/app/encryptioncontext/views.py [0:0]
def create(request):
if request.method =='GET':
form=CustomerProfileForm()
context={'form': form}
return render(request, 'create.html', context)
if request.method=='POST':
form = CustomerProfileForm(request.POST)
if not form.is_valid():
#form error
context={'form': form}
return render(request, 'create.html', context)
elif CustomerProfile.objects.filter(account_number=form.cleaned_data['account_number']).first():
#account number exists
form.add_error('account_number',"Account Number already exists")
context={'form': form}
return render(request, 'create.html', context)
else:
acct=CustomerProfile(account_number=form.cleaned_data['account_number'],userid=form.cleaned_data['userid'])
encryption_context={'account_number':acct.account_number}
ciphertext, encryptor_header = aws_encryption_sdk.encrypt(
source=acct.userid,
key_provider=master_key_encryption_provider,
encryption_context=encryption_context
)
acct.account_encrypted=ciphertext
acct.userid="" #clear out, production app wouldn't have this field in the database schema
logging.info(json.dumps(encryptor_header.encryption_context))
acct.save()
return HttpResponseRedirect( 'authenticate' )