Beispiel #1
0
    def contact_us(self):
        '''
        Send a contact request form
        :return:
        '''
        response.headers['Content-Type'] = CONTENT_TYPES['json']
        try:
            topic = request.params.get('topic')
            fullname = request.params.get('fullname')
            email = request.params.get('email')
            msg = request.params.get('faq-msg')
            hdx_email = configuration.config.get('hdx.faqrequest.email',
                                                 '*****@*****.**')

            test = True if config.get(
                'ckan.site_id') == 'test.ckan.net' else False
            if not test:
                captcha_response = request.params.get('g-recaptcha-response')
                if not self.is_valid_captcha(response=captcha_response):
                    raise ValidationError(CaptchaNotValid,
                                          error_summary=CaptchaNotValid)

            simple_validate_email(email)

        except ValidationError, e:
            error_summary = e.error_summary
            if error_summary == CaptchaNotValid:
                return FaqCaptchaErr
            return self.error_message(error_summary)
 def _get_user_obj(self, mail_or_username):
     userobj = None
     try:
         if mailutil.simple_validate_email(mail_or_username):
             users = model.User.by_email(mail_or_username)
             if users:
                 userobj = users[0]
     except tk.Invalid as e:
         userobj = model.User.get(mail_or_username)
         if not userobj:
             raise
     return userobj