def _send_confirmation(email, salt, endpoint, template, template_args=None, url_args=None, data=None): template_args = template_args or {} url_args = url_args or {} token = secure_serializer.dumps(data or email, salt=salt) url = url_for(endpoint, token=token, _external=True, **url_args) template_module = get_template_module(template, email=email, url=url, **template_args) send_email(make_email(email, template=template_module)) flash(_('We have sent you a verification email. Please check your mailbox within the next hour and open ' 'the link in that email.')) return redirect(url_for(endpoint, **url_args))
def url_for_register(next_url=None, email=None): """Returns the URL to register :param next_url: The URL to redirect to afterwards. :param email: A pre-validated email address to use when creating a new local account. Use this argument ONLY when sending the link in an email or if the email address has already been validated using some other way. """ if Config.getInstance().getLocalIdentities(): token = secure_serializer.dumps(email, salt='register-email-prevalidated') if email else None return url_for('auth.register', token=token, next=next_url, _external=True, _secure=True) external_url = Config.getInstance().getExternalRegistrationURL() return external_url or url_for_login()
def url_for_register(next_url=None, email=None): """Returns the URL to register :param next_url: The URL to redirect to afterwards. :param email: A pre-validated email address to use when creating a new local account. Use this argument ONLY when sending the link in an email or if the email address has already been validated using some other way. """ if config.LOCAL_IDENTITIES: token = secure_serializer.dumps(email, salt='register-email-prevalidated') if email else None return url_for('auth.register', token=token, next=next_url, _external=True) external_url = config.EXTERNAL_REGISTRATION_URL return external_url or url_for_login()
def submit_attachment(task, attachment): """Sends an attachment's file to the conversion service""" from indico_conversion.plugin import ConversionPlugin if ConversionPlugin.settings.get('maintenance'): task.retry(countdown=900) url = ConversionPlugin.settings.get('server_url') payload = { 'attachment_id': attachment.id } data = { 'converter': 'pdf', 'urlresponse': url_for_plugin('conversion.callback', _external=True), 'dirresponse': secure_serializer.dumps(payload, salt='pdf-conversion') } file = attachment.file name, ext = os.path.splitext(file.filename) # we know ext is safe since it's based on a whitelist. the name part may be fully # non-ascii so we sanitize that to a generic name if necessary filename = secure_filename(name, 'attachment') + ext with file.open() as fd: try: response = requests.post(url, data=data, files={'uploadedfile': (filename, fd, file.content_type)}) response.raise_for_status() if 'ok' not in response.text: raise requests.RequestException(f'Unexpected response from server: {response.text}') except requests.RequestException as exc: attempt = task.request.retries + 1 try: delay = DELAYS[task.request.retries] if not config.DEBUG else 1 except IndexError: # like this we can safely bump MAX_TRIES manually if necessary delay = DELAYS[-1] try: task.retry(countdown=delay, max_retries=(MAX_TRIES - 1)) except MaxRetriesExceededError: ConversionPlugin.logger.error('Could not submit attachment %d (attempt %d/%d); giving up [%s]', attachment.id, attempt, MAX_TRIES, exc) pdf_state_cache.delete(str(attachment.id)) except Retry: ConversionPlugin.logger.warning('Could not submit attachment %d (attempt %d/%d); retry in %ds [%s]', attachment.id, attempt, MAX_TRIES, delay, exc) raise else: ConversionPlugin.logger.info('Submitted %r', attachment)
def submit_attachment(task, attachment): """Sends an attachment's file to the conversion service""" from indico_conversion.plugin import ConversionPlugin if ConversionPlugin.settings.get('maintenance'): task.retry(countdown=900) url = ConversionPlugin.settings.get('server_url') payload = {'attachment_id': attachment.id} data = { 'converter': 'pdf', 'urlresponse': url_for_plugin('conversion.callback', _external=True), 'dirresponse': secure_serializer.dumps(payload, salt='pdf-conversion') } file = attachment.file with file.open() as fd: try: response = requests.post( url, data=data, files={'uploadedfile': (file.filename, fd, file.content_type)}) response.raise_for_status() if 'ok' not in response.text: raise requests.RequestException( 'Unexpected response from server: {}'.format( response.text)) except requests.RequestException as exc: attempt = task.request.retries + 1 delay = (DELAYS + [0])[task.request.retries] if not config.DEBUG else 1 try: task.retry(countdown=delay, max_retries=(MAX_TRIES - 1)) except MaxRetriesExceededError: ConversionPlugin.logger.error( 'Could not submit attachment %d (attempt %d/%d); giving up [%s]', attachment.id, attempt, MAX_TRIES, exc) cache.delete(unicode(attachment.id)) except Retry: ConversionPlugin.logger.warning( 'Could not submit attachment %d (attempt %d/%d); retry in %ds [%s]', attachment.id, attempt, MAX_TRIES, delay, exc) raise else: ConversionPlugin.logger.info('Submitted %r', attachment)
def signed_download_url(self): return url_for('files.download_file', uuid=self.uuid, token=secure_serializer.dumps(self.uuid.hex, salt='file-download'), _external=True)