Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ip_addresses = [ip_address.strip() for ip_address in ip_address_param.split(',')]
with boto_error_handler(self.request, self.location):
for ip_address in ip_addresses:
self.log_request(_(u"Disassociating IP {0}").format(ip_address))
address = self.get_ip_address(ip_address)
if address and address.association_id:
self.conn.disassociate_address(ip_address, association_id=address.association_id)
else:
self.conn.disassociate_address(ip_address)
if len(ip_addresses) == 1:
msg = _(u'Successfully disassociated the IP from the instance.')
else:
prefix = _(u'Successfully sent request to disassociate the follow IP addresses:')
msg = u'{0} {1}'.format(prefix, ', '.join(ip_addresses))
self.request.session.flash(msg, queue=Notification.SUCCESS)
return HTTPFound(location=self.location)
msg = _(u'Failed to disassociate the IP address from the instance.')
self.request.session.flash(msg, queue=Notification.ERROR)
return HTTPFound(location=self.location)
def delete(request):
event_id = request.matchdict.get('event_id')
event = models.Event.objects.with_id(event_id)
event.status = 'delete'
event.topic.status = 'delete'
event.save()
event.topic.save()
return HTTPFound(location=request.route_path('manager.events.index'))
def via_redirect(context, request):
url = request.params.get("url")
if url is None:
raise httpexceptions.HTTPBadRequest('"url" parameter missing')
via_link = "https://via.hypothes.is/{}".format(url)
raise httpexceptions.HTTPFound(location=via_link)
instance_id = self.request.params.get('instance_id')
device = self.request.params.get('device')
validation_conditions = [
self.is_csrf_valid(),
instance_id in dict(self.attach_form.instance_id.choices)
]
if all(validation_conditions):
with boto_error_handler(self.request, self.location):
self.log_request(_(u"Attaching volume {0} to {1} as {2}").format(volume_id, instance_id, device))
self.conn.attach_volume(volume_id, instance_id, device)
msg = _(u'Successfully sent request to attach volume. It may take a moment to attach to instance.')
self.request.session.flash(msg, queue=Notification.SUCCESS)
else:
msg = _(u'Unable to attach volume.') # TODO Pull in form validation error messages here
self.request.session.flash(msg, queue=Notification.ERROR)
return HTTPFound(location=self.location)
def add_page(request):
name = request.matchdict['pagename']
if 'form.submitted' in request.params:
body = request.params['body']
page = Page(name, body)
DBSession.add(page)
return HTTPFound(location = request.route_url('view_page',
pagename=name))
save_url = request.route_url('add_page', pagename=name)
page = Page('', '')
# logged_in is available if you've invoking "headers = remember(request, login)" in login.py
return dict(page=page, save_url=save_url, logged_in=authenticated_userid(request))
oauth = OAuth1(
self.consumer_key,
client_secret=self.consumer_secret,
callback_uri=request.route_url(self.callback_route))
resp = requests.post(REQUEST_URL, auth=oauth)
if resp.status_code != 200:
raise ThirdPartyFailure("Status %s: %s" % (
resp.status_code, resp.content))
request_token = dict(parse_qsl(resp.content))
# store the token for later
request.session['velruse.token'] = request_token
# redirect the user to authorize the app
auth_url = flat_url(AUTH_URL, oauth_token=request_token['oauth_token'])
return HTTPFound(location=auth_url)
s['message'] = 'Old password invalid.'
elif request.session['safe_get']['act'] == 'forgot_pass':
user = users.get_user_by_email(p['email'])
if not user:
s['message'] = "That email isn't registered"
else:
s['message'] = "Check your mail for a confirmation message."
users.send_lost_password_verify_email(request, user)
else:
try:
u = users.get_user_by_name(username)
try:
users.login_user(request, u, p['password'])
s['message'] = "Good, logged in"
success = True
return HTTPFound(request.route_url('post'))
except LoginAdapterExc:
s['message'] = "Incorrect password."
success = False
except sqlalchemy.orm.exc.NoResultFound:
s['message'] = "Sorry, I don't know you."
success = False
return {'success': success,}
try:
appstruct = form.validate(controls)
except deform.ValidationFailure, e:
msg = _("ticket_validation_fail",
default = "Ticket validation failed. Either the "
"ticket doesn't exist, was already used or the url used improperly. "
"If you need help, please contact the moderator that invited you to this meeting.")
self.flash_messages.add(msg, type = 'danger', auto_destruct = False, require_commit = False)
url = self.request.resource_url(self.root)
return HTTPFound(location = url)
#Everything in order, claim ticket
ticket = self.context.invite_tickets[appstruct['email']]
claim_ticket(ticket, self.request, self.request.authenticated_userid)
self.flash_messages.add(_(u"You've been granted access to the meeting. Welcome!"))
url = self.request.resource_url(self.context)
return HTTPFound(location=url)
#No action, render page
claim_action_query = dict(
claim = '1',
email = email,
token = self.request.GET.get('token', ''),
)
#FIXME: Use logout button + redirect link to go back to claim ticket
return {'claim_action_url': self.request.resource_url(self.context, 'ticket_claim',
query = claim_action_query)}
def error_to_login_form(request, message):
log.info('OpenID ERROR: %s' % message)
settings = request.registry.settings
error_url = settings.get('openid.error_destination', request.referrer)
if error_url is None:
error_url = '/'
error_flash_queue = settings.get('openid.error_flash_queue', '')
request.session.flash(message, error_flash_queue)
return HTTPFound(location=error_url)
if not domain_names:
raise ValueError("missing valid domain names")
account_key_pem = formStash.results['account_key_file'].file.read()
private_key_pem = formStash.results['private_key_file'].file.read()
try:
dbLetsencryptCertificate = lib_db.create__CertificateRequest__FULL(
DBSession,
domain_names,
account_key_pem=account_key_pem,
private_key_pem=private_key_pem,
)
except:
if self.request.registry.settings['exception_redirect']:
return HTTPFound('/.well-known/admin/certificate_requests?error=new-full')
raise
return HTTPFound('/.well-known/admin/certificate/%s' % dbLetsencryptCertificate.id)
except formhandling.FormInvalid:
formStash.set_error(field="Error_Main",
message="There was an error with your form.",
raise_FormInvalid=False,
message_prepend=True
)
return formhandling.form_reprint(
self.request,
self._certificate_request_new_full__print,
auto_error_formatter=formhandling.formatter_none,
)