Example #1
0
def validate_recaptcha(challenge, response, remote_ip):
    """Validates the recaptcha.  If the validation fails a `RecaptchaValidationFailed`
    error is raised.
    """
    app = get_application()
    request = urllib2.Request(VERIFY_SERVER, data=url_encode({
        'privatekey':       app.cfg['recaptcha_private_key'],
        'remoteip':         remote_ip,
        'challenge':        challenge,
        'response':         response
    }))
    response = urllib2.urlopen(request)
    rv = response.read().splitlines()
    response.close()
    if rv and rv[0] == 'true':
        return True
    if len(rv) > 1:
        error = rv[1]
        if error == 'invalid-site-public-key':
            raise RuntimeError('invalid public key for recaptcha set')
        if error == 'invalid-site-private-key':
            raise RuntimeError('invalid private key for recaptcha set')
        if error == 'invalid-referrer':
            raise RuntimeError('key not valid for the current domain')
    return False
Example #2
0
 def localized_country(self):
     """country name as in locale, with fallback"""
     from pyClanSphere.api import get_application
     try:
         retval = get_application().locale.territories[self.country]
     except KeyError:
         retval = self.country
     return retval
Example #3
0
    def setUp(self):
        from pyClanSphere.api import get_application
        from pyClanSphere.database import db, init_database
        self.app = get_application()
        self.db = db

        # just in case the table(s) for the test haven't been created
        init_database(self.app.database_engine)
Example #4
0
def get_recaptcha_html(error=None, theme=None):
    """Returns the recaptcha input HTML."""

    app = get_application()
    theme_settings = get_application().theme.settings
    cfg = app.cfg

    if theme == None or theme not in AVAILABLE_THEMES:
        theme = theme_settings['recaptcha.theme']
        if theme == None or theme not in AVAILABLE_THEMES:
            theme = cfg['recaptcha_default_theme']

    server = cfg['recaptcha_use_ssl'] and SSL_API_SERVER or API_SERVER
    options = dict(k=cfg['recaptcha_public_key'])
    if error is not None:
        options['error'] = unicode(error)
    query = url_encode(options)
    return u'''
    <script type="text/javascript">var RecaptchaOptions = %(options)s;</script>
    <script type="text/javascript" src="%(script_url)s"></script>
    <noscript>
      <div><iframe src="%(frame_url)s" height="300" width="500"></iframe></div>
      <div><textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
      <input type="hidden" name="recaptcha_response_field" value="manual_challenge"></div>
    </noscript>
    ''' % dict(
        script_url='%schallenge?%s' % (server, query),
        frame_url='%snoscript?%s' % (server, query),
        options=dumps({
            'theme':    theme,
            'custom_translations': {
                'visual_challenge': _("Get a visual challenge"),
                'audio_challenge': _("Get an audio challenge"),
                'refresh_btn': _("Get a new challenge"),
                'instructions_visual': _("Type the two words:"),
                'instructions_audio': _("Type what you hear:"),
                'help_btn': _("Help"),
                'play_again': _("Play sound again"),
                'cant_hear_this': _("Download sound as MP3"),
                'incorrect_try_again': _("Incorrect. Try again.")
            }
        })
    )
Example #5
0
 def picture_folder(self):
     try:
         return self._picture_folder
     except AttributeError:
         from pyClanSphere.api import get_application
         app = get_application()
         self._picture_folder = pjoin(app.instance_folder, 'userpics')
         if not os.path.exists(self._picture_folder):
             os.makedirs(self._picture_folder)
         return self._picture_folder
Example #6
0
    def url(self):
        """Return a default pic link, the magic gravatar url or
           a link to the uploaded picture, if any
        """

        from pyClanSphere.api import get_application, url_for
        app = get_application()
        size = app.theme.settings['avatar.size']
        pictype = self.user.userpictype
        if not pictype or pictype == u'None':
            return app.cfg['avatar_default'] if app.cfg['avatar_default'] \
                else url_for('core/shared', filename='nopicture.jpg')
        if self.user.userpictype == u'Gravatar':
            gravatar_url = "http://www.gravatar.com/avatar/"
            gravatar_url += md5(self.user.email).hexdigest() + "?"
            gravatar_url += urlencode({'size':str(size)})
            return gravatar_url
        else:
            return url_for('userpics/shared', filename=self.filename)
Example #7
0
 def generate_filename(self):
     from pyClanSphere.api import get_application
     app = get_application()
     self.map_folder = os.path.join(app.instance_folder, 'warmaps')
     self._map_filename = os.path.join(self.map_folder, str(self.id))
Example #8
0
 def _pic_hash(self):
     from pyClanSphere.api import get_application
     app = get_application()
     return md5(app.cfg['iid'] + str(self.user.id)).hexdigest()