Changeset 7308 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 7 Dec 2011, 16:46:01 (13 years ago)
- 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 29 29 from zope.publisher.interfaces.http import IHTTPRequest 30 30 from waeup.sirp.browser import WAeUPPage as SIRPPage 31 from waeup.sirp.browser.interfaces import ( 32 ICaptchaRequest, ICaptchaResponse, ICaptcha, ICaptchaConfig, 33 ICaptchaManager) 31 34 from waeup.sirp.interfaces import IUniversity 32 35 … … 34 37 grok.templatedir('templates') 35 38 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 of40 captchas might also need a challenge to compare whether the41 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 an71 ICaptchaResponse indicating that the solution was correct or72 not.73 74 If the solution could not be verified (this might also happen75 because of technical reasons), the response might contain an76 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 error83 code as returned from :meth:`verify`.84 85 The code is expected to appear inside a ``<form>``. It86 therefore should not contain a ``<form>`` nor any submit87 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 """106 39 107 40 # 108 # Global captcha chooser41 # Global captcha manager 109 42 # 110 43 class CaptchaManager(grok.GlobalUtility): … … 288 221 To render the needed HTML code, you can deploy the 289 222 :meth:`display`` method of ``mycaptcha``. 223 224 This captcha is available at runtime as a global utility named 225 ``'ReCaptcha'``. 290 226 """ 291 227 -
main/waeup.sirp/trunk/src/waeup/sirp/browser/interfaces.py
r7195 r7308 23 23 IWAeUPObject, IUniversity, IUsersContainer, IDataCenter) 24 24 from 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, 27 27 ICertificate, ICertificateAdd, ICertificateCourse, ICertificateCourseAdd) 28 28 … … 77 77 required = False, 78 78 ) 79 79 80 80 def getResources(): 81 81 """Get resources of the theme. … … 92 92 by the `update()` method of the general site layout. 93 93 """ 94 95 class 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 111 class 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 124 class 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 149 class ICaptchaConfig(Interface): 150 """Any type of captcha might need some configuration data. 151 152 By default we require no configuration data. 153 """ 154 155 class 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 23 23 from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase 24 24 from waeup.sirp.browser.captcha import ( 25 ICaptchaResponse, ICaptchaRequest, ICaptcha, ICaptchaManager)26 from waeup.sirp.browser.captcha import (27 25 CaptchaResponse, CaptchaRequest, NullCaptcha, StaticCaptcha, ReCaptcha, 28 26 CaptchaManager) 27 from waeup.sirp.browser.interfaces import ( 28 ICaptchaRequest, ICaptchaResponse, ICaptcha, ICaptchaConfig, 29 ICaptchaManager) 30 29 31 30 32 class CaptchaResponseTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.