Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
email=form.cleaned_data['contact_email'],
encrypted_password=encrypt_password(
form.cleaned_data['password'],
RSA.importKey(CREATE_PUBLIC_KEY),
),
handle_warnings=NewAccountRequest.WARNINGS_WARN,
)
if 'warnings-submit' in request.POST:
req = req._replace(
handle_warnings=NewAccountRequest.WARNINGS_SUBMIT,
)
task = validate_then_create_account.delay(req)
task.wait(timeout=5)
if isinstance(task.result, NewAccountResponse):
if task.result.status == NewAccountResponse.REJECTED:
status = 'has_errors'
form.add_error(None, task.result.errors)
elif task.result.status == NewAccountResponse.FLAGGED:
status = 'has_warnings'
form.add_error(None, task.result.errors)
elif task.result.status == NewAccountResponse.PENDING:
return HttpResponseRedirect(reverse('account_pending'))
else:
raise AssertionError('Unexpected state reached')
else:
# validation was successful, the account is being created now
request.session['approve_task_id'] = task.result
return HttpResponseRedirect(reverse('wait_for_account'))
else:
form = ApproveForm()
encrypted_password=encrypt_password(
form.cleaned_data['password'],
RSA.importKey(CREATE_PUBLIC_KEY),
),
handle_warnings=NewAccountRequest.WARNINGS_WARN,
)
if 'warnings-submit' in request.POST:
req = req._replace(
handle_warnings=NewAccountRequest.WARNINGS_SUBMIT,
)
task = validate_then_create_account.delay(req)
task.wait(timeout=5)
if isinstance(task.result, NewAccountResponse):
if task.result.status == NewAccountResponse.REJECTED:
status = 'has_errors'
form.add_error(None, task.result.errors)
elif task.result.status == NewAccountResponse.FLAGGED:
status = 'has_warnings'
form.add_error(None, task.result.errors)
elif task.result.status == NewAccountResponse.PENDING:
return HttpResponseRedirect(reverse('account_pending'))
else:
raise AssertionError('Unexpected state reached')
else:
# validation was successful, the account is being created now
request.session['approve_task_id'] = task.result
return HttpResponseRedirect(reverse('wait_for_account'))
else:
form = ApproveForm()
with get_session() as session:
session.add(stored_request) # TODO: error handling
session.commit()
except sqlalchemy.exc.IntegrityError:
# If there's an integrity constraint, it's okay -- the
# account was already submitted, so we can still return a
# "pending" response.
pass
else:
dispatch_event(
'ocflib.account_submitted',
request=dict(request.to_dict(), reasons=warnings),
)
return NewAccountResponse(
status=NewAccountResponse.PENDING,
errors=warnings,
)
elif request.handle_warnings == NewAccountRequest.WARNINGS_WARN:
return NewAccountResponse(
status=NewAccountResponse.FLAGGED,
errors=warnings,
)
return create_account.delay(request).id
return NewAccountResponse(
status=NewAccountResponse.REJECTED,
errors=(errors + warnings),
)
# actual account creation
kwargs = {}
known_uid = r.get('known_uid')
if known_uid:
kwargs['known_uid'] = int(known_uid)
new_uid = real_create_account(request, credentials, report_status, **kwargs)
r.set('known_uid', new_uid)
dispatch_event('ocflib.account_created', request=request.to_dict())
return NewAccountResponse(
status=NewAccountResponse.CREATED,
errors=[],
)
finally:
try:
lock.release()
except LockError:
pass
create_account.update_state(meta={'status': status})
def __enter__(self, *args):
self(self.start + ' ' + self.task)
def __exit__(self, *args):
self(self.stop + ' ' + self.task)
with report_status('Validating', 'Validated', 'request'), \
get_session() as session:
errors, warnings = validate_request(request, credentials, session)
if errors:
send_rejected_mail(request, str(errors))
return NewAccountResponse(
status=NewAccountResponse.REJECTED,
errors=(errors + warnings),
)
# actual account creation
kwargs = {}
known_uid = r.get('known_uid')
if known_uid:
kwargs['known_uid'] = int(known_uid)
new_uid = real_create_account(request, credentials, report_status, **kwargs)
r.set('known_uid', new_uid)
dispatch_event('ocflib.account_created', request=request.to_dict())
return NewAccountResponse(
status=NewAccountResponse.CREATED,
errors=[],
)
# If there's an integrity constraint, it's okay -- the
# account was already submitted, so we can still return a
# "pending" response.
pass
else:
dispatch_event(
'ocflib.account_submitted',
request=dict(request.to_dict(), reasons=warnings),
)
return NewAccountResponse(
status=NewAccountResponse.PENDING,
errors=warnings,
)
elif request.handle_warnings == NewAccountRequest.WARNINGS_WARN:
return NewAccountResponse(
status=NewAccountResponse.FLAGGED,
errors=warnings,
)
return create_account.delay(request).id
status.append(line)
create_account.update_state(meta={'status': status})
def __enter__(self, *args):
self(self.start + ' ' + self.task)
def __exit__(self, *args):
self(self.stop + ' ' + self.task)
with report_status('Validating', 'Validated', 'request'), \
get_session() as session:
errors, warnings = validate_request(request, credentials, session)
if errors:
send_rejected_mail(request, str(errors))
return NewAccountResponse(
status=NewAccountResponse.REJECTED,
errors=(errors + warnings),
)
# actual account creation
kwargs = {}
known_uid = r.get('known_uid')
if known_uid:
kwargs['known_uid'] = int(known_uid)
new_uid = real_create_account(request, credentials, report_status, **kwargs)
r.set('known_uid', new_uid)
dispatch_event('ocflib.account_created', request=request.to_dict())
return NewAccountResponse(
status=NewAccountResponse.CREATED,
errors=[],
'You can either create the account anyway, or go back and '
'modify the request.'
))
choice = input('Create the account anyway? [yN] ')
if choice in ('y', 'Y'):
new_request = request._replace(
handle_warnings=NewAccountRequest.WARNINGS_CREATE,
)
task = tasks.validate_then_create_account.delay(new_request)
response = wait_for_task(celery, task)
else:
input('Starting over, press enter to continue...')
continue
if response.status == NewAccountResponse.CREATED:
print(bold(green('Account created!')))
print('Your account was created successfully.')
print('You\'ve been sent an email with more information.')
return
else:
# this shouldn't be possible; we must have entered some weird state
# TODO: report via ocflib
print(bold(red('Error: Entered unexpected state.')))
print(red('The request we submitted was:'))
print(red(request))
print(red('The new request we submitted (if any) was:'))
print(red(new_request))
print(red('The response we received was:'))
print(red(response))
print(bold(red('Not really sure what to do here, sorry.')))
input('Press enter to start over...')
# account was already submitted, so we can still return a
# "pending" response.
pass
else:
dispatch_event(
'ocflib.account_submitted',
request=dict(request.to_dict(), reasons=warnings),
)
return NewAccountResponse(
status=NewAccountResponse.PENDING,
errors=warnings,
)
elif request.handle_warnings == NewAccountRequest.WARNINGS_WARN:
return NewAccountResponse(
status=NewAccountResponse.FLAGGED,
errors=warnings,
)
return create_account.delay(request).id
)
tasks = get_tasks(celery)
task = tasks.validate_then_create_account.delay(request)
response = wait_for_task(celery, task)
new_request = None
if response.status == NewAccountResponse.REJECTED:
print(bold(red(
'Account requested was rejected for the following reasons:'
)))
for error in response.errors:
print(red(' - {}'.format(error)))
input('Press enter to start over (or ^C to cancel)...')
continue
elif response.status == NewAccountResponse.FLAGGED:
print(bold(yellow(
'Account requested was flagged for the following reasons:'
)))
for error in response.errors:
print(yellow(' - {}'.format(error)))
print(bold(
'You can either create the account anyway, or go back and '
'modify the request.'
))
choice = input('Create the account anyway? [yN] ')
if choice in ('y', 'Y'):
new_request = request._replace(
handle_warnings=NewAccountRequest.WARNINGS_CREATE,
)
task = tasks.validate_then_create_account.delay(new_request)