def route(self): match = re.search(ROUTE_REGEX, self.form['recipient']) if not match: raise ConferenceError('Invalid recipient: '.format( self.form['recipient'])) data = match.groupdict() if bool(settings.DEV_MODE) != bool(data['test']): raise ConferenceError( 'Mismatch between `DEV_MODE` and recipient {0}'.format( self.form['recipient'])) return data
def route(self): match = re.search(re.compile(BASE_REGEX.format(allowed_types=(self.allowed_types or 'poster|talk')), re.IGNORECASE | re.VERBOSE), self.form['recipient']) if not match: raise ConferenceError('Invalid recipient: '.format(self.form['recipient'])) data = match.groupdict() if bool(settings.DEV_MODE) != bool(data['test']): # NOTE: test.osf.io has DEV_MODE = False if not data['test'] or (data['test'] and data['test'].rstrip('-') != 'test'): raise ConferenceError( 'Mismatch between `DEV_MODE` and recipient {0}'.format( self.form['recipient'] ) ) return data
def get_by_endpoint(cls, endpoint, active=True): query = Q('endpoint', 'iexact', endpoint) if active: query &= Q('active', 'eq', True) try: return Conference.find_one(query) except ModularOdmException: raise ConferenceError('Endpoint {0} not found'.format(endpoint))
def get_by_endpoint(self, endpoint, active=True): try: if active: return self.get_queryset().get(endpoint__iexact=endpoint, active=True) else: return self.get_queryset().get(endpoint__iexact=endpoint) except Conference.DoesNotExist: raise ConferenceError('Endpoint {} not found'.format(endpoint))
def sender_email(self): match = ANGLE_BRACKETS_REGEX.search(self.sender) if match: # sender format: "some name" <*****@*****.**> return match.groups()[0].lower().strip() elif '@' in self.sender: # sender format: [email protected] return self.sender.lower().strip() raise ConferenceError('Could not extract sender email')
def verify_signature(self): """Verify that request comes from Mailgun. Based on sample code from http://documentation.mailgun.com/user_manual.html#webhooks """ signature = hmac.new( key=settings.MAILGUN_API_KEY, msg='{}{}'.format( self.form['timestamp'], self.form['token'], ), digestmod=hashlib.sha256, ).hexdigest() if signature != self.form['signature']: raise ConferenceError('Invalid headers on incoming mail')
def sender_email(self): match = ANGLE_BRACKETS_REGEX.search(self.sender) if match: return match.groups()[0] raise ConferenceError('Could not extract sender email')