Changeset 7308 for main


Ignore:
Timestamp:
7 Dec 2011, 16:46:01 (13 years ago)
Author:
uli
Message:

Move captcha-related interfaces to proper location.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/browser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/captcha.py

    r7307 r7308  
    2929from zope.publisher.interfaces.http import IHTTPRequest
    3030from waeup.sirp.browser import WAeUPPage as SIRPPage
     31from waeup.sirp.browser.interfaces import (
     32    ICaptchaRequest, ICaptchaResponse, ICaptcha, ICaptchaConfig,
     33    ICaptchaManager)
    3134from waeup.sirp.interfaces import IUniversity
    3235
     
    3437grok.templatedir('templates')
    3538
    36 class ICaptchaRequest(Interface):
    37     """A set of data required to verify captcha solutions.
    38 
    39     To solve a captcha we need at least a solution. Many types of
    40     captchas might also need a challenge to compare whether the
    41     solution is correct.
    42     """
    43     solution = schema.TextLine(
    44         title = u'Solution string a user entered',
    45         default = None,
    46         )
    47     challenge = schema.TextLine(
    48         title = u'The challenge the solution might match',
    49         default = None,
    50         )
    51 
    52 class ICaptchaResponse(Interface):
    53     """A formalized response for captcha solutions.
    54     """
    55     is_valid = schema.Bool(
    56         title = u'Indicates validity of entered captcha data.',
    57         default = False,
    58         )
    59     error_code = schema.TextLine(
    60         title = u'Error when trying to validate entered captcha data.',
    61         description = u'Error codes are not expected to be readable strings.',
    62         default = None,
    63         )
    64 
    65 class ICaptcha(Interface):
    66 
    67     def verify(request):
    68         """Verify data entered in an HTTP request.
    69 
    70         Expects some IHTTPRequest object and returns an
    71         ICaptchaResponse indicating that the solution was correct or
    72         not.
    73 
    74         If the solution could not be verified (this might also happen
    75         because of technical reasons), the response might contain an
    76         error code.
    77         """
    78 
    79     def display(error_code=None):
    80         """Returns a piece of HTML code that displays the captcha.
    81 
    82         The generated HTML code might depend on any previous error
    83         code as returned from :meth:`verify`.
    84 
    85         The code is expected to appear inside a ``<form>``. It
    86         therefore should not contain a ``<form>`` nor any submit
    87         buttons.
    88         """
    89 
    90 class ICaptchaConfig(Interface):
    91     """Any type of captcha might need some configuration data.
    92 
    93     By default we require no configuration data.
    94     """
    95 
    96 class ICaptchaManager(Interface):
    97     """A chooser that collects available captchas.
    98     """
    99     def getAvailCaptchas():
    100         """Return a dict of available captchas with registered names as keys.
    101         """
    102 
    103     def getCaptcha():
    104         """Get captcha chosen for a certain site or default.
    105         """
    10639
    10740#
    108 # Global captcha chooser
     41# Global captcha manager
    10942#
    11043class CaptchaManager(grok.GlobalUtility):
     
    288221    To render the needed HTML code, you can deploy the
    289222    :meth:`display`` method of ``mycaptcha``.
     223
     224    This captcha is available at runtime as a global utility named
     225    ``'ReCaptcha'``.
    290226    """
    291227
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/interfaces.py

    r7195 r7308  
    2323    IWAeUPObject, IUniversity, IUsersContainer, IDataCenter)
    2424from waeup.sirp.university.interfaces import (
    25     IFacultyContainer, IFaculty, IFacultyAdd, IDepartment, IDepartmentAdd, 
    26     ICourseContainer, ICourse, ICourseAdd, ICertificateContainer, 
     25    IFacultyContainer, IFaculty, IFacultyAdd, IDepartment, IDepartmentAdd,
     26    ICourseContainer, ICourse, ICourseAdd, ICertificateContainer,
    2727    ICertificate, ICertificateAdd, ICertificateCourse, ICertificateCourseAdd)
    2828
     
    7777        required = False,
    7878        )
    79        
     79
    8080    def getResources():
    8181        """Get resources of the theme.
     
    9292        by the `update()` method of the general site layout.
    9393        """
     94
     95class ICaptchaRequest(Interface):
     96    """A set of data required to verify captcha solutions.
     97
     98    To solve a captcha we need at least a solution. Many types of
     99    captchas might also need a challenge to compare whether the
     100    solution is correct.
     101    """
     102    solution = schema.TextLine(
     103        title = u'Solution string a user entered',
     104        default = None,
     105        )
     106    challenge = schema.TextLine(
     107        title = u'The challenge the solution might match',
     108        default = None,
     109        )
     110
     111class ICaptchaResponse(Interface):
     112    """A formalized response for captcha solutions.
     113    """
     114    is_valid = schema.Bool(
     115        title = u'Indicates validity of entered captcha data.',
     116        default = False,
     117        )
     118    error_code = schema.TextLine(
     119        title = u'Error when trying to validate entered captcha data.',
     120        description = u'Error codes are not expected to be readable strings.',
     121        default = None,
     122        )
     123
     124class ICaptcha(Interface):
     125
     126    def verify(request):
     127        """Verify data entered in an HTTP request.
     128
     129        Expects some IHTTPRequest object and returns an
     130        ICaptchaResponse indicating that the solution was correct or
     131        not.
     132
     133        If the solution could not be verified (this might also happen
     134        because of technical reasons), the response might contain an
     135        error code.
     136        """
     137
     138    def display(error_code=None):
     139        """Returns a piece of HTML code that displays the captcha.
     140
     141        The generated HTML code might depend on any previous error
     142        code as returned from :meth:`verify`.
     143
     144        The code is expected to appear inside a ``<form>``. It
     145        therefore should not contain a ``<form>`` nor any submit
     146        buttons.
     147        """
     148
     149class ICaptchaConfig(Interface):
     150    """Any type of captcha might need some configuration data.
     151
     152    By default we require no configuration data.
     153    """
     154
     155class ICaptchaManager(Interface):
     156    """A chooser that collects available captchas.
     157    """
     158    def getAvailCaptchas():
     159        """Return a dict of available captchas with registered names as keys.
     160        """
     161
     162    def getCaptcha():
     163        """Get captcha chosen for a certain site or default.
     164        """
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/tests/test_captcha.py

    r7307 r7308  
    2323from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
    2424from waeup.sirp.browser.captcha import (
    25     ICaptchaResponse, ICaptchaRequest, ICaptcha, ICaptchaManager)
    26 from waeup.sirp.browser.captcha import (
    2725    CaptchaResponse, CaptchaRequest, NullCaptcha, StaticCaptcha, ReCaptcha,
    2826    CaptchaManager)
     27from waeup.sirp.browser.interfaces import (
     28    ICaptchaRequest, ICaptchaResponse, ICaptcha, ICaptchaConfig,
     29    ICaptchaManager)
     30
    2931
    3032class CaptchaResponseTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.