Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Attributes
CMFPlone.RegistrationTool.RegistrationTool Class Reference
Inheritance diagram for CMFPlone.RegistrationTool.RegistrationTool:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.RegistrationTool.RegistrationTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getPassword
def isValidEmail
def testPropertiesValidity
def isMemberIdAllowed
def generatePassword
def generateResetCode
def mailPassword
def registeredNotify
def isMemberIdAllowed

Static Public Attributes

 meta_type = ToolNames.RegistrationTool
tuple security = ClassSecurityInfo()
string toolicon = 'skins/plone_images/pencil_icon.gif'
int plone_tool = 1
 md5key = None

Private Member Functions

def _md5base

Static Private Attributes

tuple __implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, )
 _v_md5base = None

Detailed Description

Definition at line 47 of file RegistrationTool.py.


Constructor & Destructor Documentation

Definition at line 57 of file RegistrationTool.py.

00057 
00058     def __init__(self):
00059         if hasattr(BaseTool, '__init__'):
00060             BaseTool.__init__(self)
00061         # build and persist an MD5 key
00062         self.md5key = ''
00063         for i in range(0, 20):
00064             self.md5key += chr(ord('a')+random.randint(0,26))


Member Function Documentation

Definition at line 65 of file RegistrationTool.py.

00065 
00066     def _md5base(self):
00067         if self._v_md5base is None:
00068             self._v_md5base = md5.new(self.md5key)
00069         return self._v_md5base

Here is the caller graph for this function:

Generates a password which is guaranteed to comply
with the password policy.

Definition at line 185 of file RegistrationTool.py.

00185 
00186     def generatePassword(self):
00187         """Generates a password which is guaranteed to comply
00188         with the password policy."""
00189         return self.getPassword(6)

Here is the call graph for this function:

def CMFPlone.RegistrationTool.RegistrationTool.generateResetCode (   self,
  salt,
  length = 14 
)
Generates a reset code which is guaranteed to return the
same value for a given length and salt, every time.

Definition at line 191 of file RegistrationTool.py.

00191 
00192     def generateResetCode(self, salt, length=14):
00193         """Generates a reset code which is guaranteed to return the
00194         same value for a given length and salt, every time."""
00195         return self.getPassword(length, salt)

Here is the call graph for this function:

def CMFPlone.RegistrationTool.RegistrationTool.getPassword (   self,
  length = 5,
  s = None 
)

Definition at line 77 of file RegistrationTool.py.

00077 
00078     def getPassword(self, length=5, s=None):
00079         global password_chars, md5base
00080 
00081         if s is None:
00082             password = ''
00083             nchars = len(password_chars)
00084             for i in range(0, length):
00085                 password += password_chars[random.randint(0,nchars-1)]
00086             return password
00087         else:
00088             m = self._md5base().copy()
00089             m.update(s)
00090             d = m.digest() # compute md5(md5key + s)
00091             assert(len(d) >= length)
00092             password = ''
00093             nchars = len(password_chars)
00094             for i in range(0, length):
00095                 password += password_chars[ord(d[i]) % nchars]
00096             return password

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 162 of file RegistrationTool.py.

00162 
00163     def isMemberIdAllowed(self, id):
00164         if len(id) < 1 or id == 'Anonymous User':
00165             return 0
00166         if not self._ALLOWED_MEMBER_ID_PATTERN.match( id ):
00167             return 0
00168 
00169         pas = getToolByName("acl_users")
00170         if IPluggableAuthService.providedBy(pas):
00171             results = pas.searchPrincipals(id=id)
00172             if results:
00173                 return 0
00174         else:
00175             membership = getToolByName(self, 'portal_membership')
00176             if membership.getMemberById(id) is not None:
00177                 return 0
00178             groups = getToolByName(self, 'portal_groups')
00179             if groups.getGroupById(id) is not None:
00180                 return 0
00181 
00182         return 1
00183 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 285 of file RegistrationTool.py.

00285 
00286     def isMemberIdAllowed(self, id):
00287         if len(id) < 1 or id == 'Anonymous User':
00288             return 0
00289         if not self._ALLOWED_MEMBER_ID_PATTERN.match( id ):
00290             return 0
00291 
00292         pas = getToolByName(self, 'acl_users')
00293         if IPluggableAuthService.providedBy(pas):
00294             results = pas.searchPrincipals(id=id, exact_match=True)
00295             if results:
00296                 return 0
00297         else:
00298             membership = getToolByName(self, 'portal_membership')
00299             if membership.getMemberById(id) is not None:
00300                 return 0
00301             groups = getToolByName(self, 'portal_groups')
00302             if groups.getGroupById(id) is not None:
00303                 return 0
00304 
00305         return 1
00306 
00307 RegistrationTool.__doc__ = BaseTool.__doc__
00308 
00309 InitializeClass(RegistrationTool)

Here is the call graph for this function:

Here is the caller graph for this function:

checks for valid email 

Definition at line 98 of file RegistrationTool.py.

00098 
00099     def isValidEmail(self, email):
00100         """ checks for valid email """
00101         if EMAIL_RE.search(email) == None:
00102             return 0
00103         try:
00104             checkEmailAddress(email)
00105         except EmailAddressInvalid:
00106             return 0
00107         else:
00108             return 1

def CMFPlone.RegistrationTool.RegistrationTool.mailPassword (   self,
  forgotten_userid,
  REQUEST 
)
Wrapper around mailPassword 

Definition at line 197 of file RegistrationTool.py.

00197 
00198     def mailPassword(self, forgotten_userid, REQUEST):
00199         """ Wrapper around mailPassword """
00200         membership = getToolByName(self, 'portal_membership')
00201         if not membership.checkPermission('Mail forgotten password', self):
00202             raise Unauthorized, "Mailing forgotten passwords has been disabled"
00203 
00204         utils = getToolByName(self, 'plone_utils')
00205         member = membership.getMemberById(forgotten_userid)
00206 
00207         if member is None:
00208             raise ValueError, 'The username you entered could not be found'
00209 
00210         # assert that we can actually get an email address, otherwise
00211         # the template will be made with a blank To:, this is bad
00212         email = member.getProperty('email')
00213         if not email:
00214             raise ValueError('That user does not have an email address.')
00215         else:
00216             # add the single email address
00217             if not utils.validateSingleEmailAddress(email):
00218                 raise ValueError, 'The email address did not validate'
00219         check, msg = _checkEmail(email)
00220         if not check:
00221             raise ValueError, msg
00222 
00223         # Rather than have the template try to use the mailhost, we will
00224         # render the message ourselves and send it from here (where we
00225         # don't need to worry about 'UseMailHost' permissions).
00226         reset_tool = getToolByName(self, 'portal_password_reset')
00227         reset = reset_tool.requestReset(forgotten_userid)
00228 
00229         
00230         email_charset = getattr(self, 'email_charset', 'UTF-8')
00231         mail_text = self.mail_password_template( self
00232                                                , REQUEST
00233                                                , member=member
00234                                                , reset=reset
00235                                                , password=member.getPassword()
00236                                                , charset=email_charset
00237                                                )
00238         if isinstance(mail_text, unicode):
00239             mail_text = mail_text.encode(email_charset)
00240         host = self.MailHost
00241         try:
00242             host.send( mail_text )
00243 
00244             return self.mail_password_response( self, REQUEST )
00245         except SMTPRecipientsRefused:
00246             # Don't disclose email address on failure
00247             raise SMTPRecipientsRefused('Recipient address rejected by server')

Here is the call graph for this function:

Wrapper around registeredNotify 

Definition at line 249 of file RegistrationTool.py.

00249 
00250     def registeredNotify(self, new_member_id):
00251         """ Wrapper around registeredNotify """
00252         membership = getToolByName( self, 'portal_membership' )
00253         utils = getToolByName(self, 'plone_utils')
00254         member = membership.getMemberById( new_member_id )
00255 
00256         if member and member.getProperty('email'):
00257             # add the single email address
00258             if not utils.validateSingleEmailAddress(member.getProperty('email')):
00259                 raise ValueError, 'The email address did not validate'
00260 
00261         email = member.getProperty( 'email' )
00262         try:
00263             checkEmailAddress(email)
00264         except EmailAddressInvalid:
00265             raise ValueError, 'The email address did not validate'
00266 
00267         pwrt = getToolByName(self, 'portal_password_reset')
00268         reset = pwrt.requestReset(new_member_id)
00269 
00270         # Rather than have the template try to use the mailhost, we will
00271         # render the message ourselves and send it from here (where we
00272         # don't need to worry about 'UseMailHost' permissions).
00273         mail_text = self.registered_notify_template( self
00274                                                    , self.REQUEST
00275                                                    , member=member
00276                                                    , reset=reset
00277                                                    , email=email
00278                                                    )
00279 
00280         host = self.MailHost
00281         encoding = getUtility(ISiteRoot).getProperty('email_charset')
00282         host.send(mail_text.encode(encoding))
00283 
00284         return self.mail_password_response( self, self.REQUEST )

Here is the call graph for this function:

def CMFPlone.RegistrationTool.RegistrationTool.testPropertiesValidity (   self,
  props,
  member = None 
)
Verify that the properties supplied satisfy portal's requirements.

o If the properties are valid, return None.
o If not, return a string explaining why.

This is a customized version of the CMFDefault version: we also
check if the email property is writable before verifying it.

Definition at line 110 of file RegistrationTool.py.

00110 
00111     def testPropertiesValidity(self, props, member=None):
00112 
00113         """ Verify that the properties supplied satisfy portal's requirements.
00114 
00115         o If the properties are valid, return None.
00116         o If not, return a string explaining why.
00117 
00118         This is a customized version of the CMFDefault version: we also
00119         check if the email property is writable before verifying it.
00120         """
00121         if member is None: # New member.
00122 
00123             username = props.get('username', '')
00124             if not username:
00125                 return 'You must enter a valid name.'
00126 
00127             if not self.isMemberIdAllowed(username):
00128                 return ('The login name you selected is already '
00129                         'in use or is not valid. Please choose another.')
00130 
00131             email = props.get('email')
00132             if email is None:
00133                 return 'You must enter an email address.'
00134 
00135             try:
00136                 checkEmailAddress( email )
00137             except EmailAddressInvalid: 
00138                 return 'You must enter a valid email address.'
00139 
00140         else: # Existing member.
00141             if not hasattr(member, 'canWriteProperty') or \
00142                     member.canWriteProperty('email'):
00143 
00144                 email = props.get('email')
00145 
00146                 if email is not None:
00147 
00148                     try:
00149                         checkEmailAddress( email )
00150                     except EmailAddressInvalid:
00151                         return 'You must enter a valid email address.'
00152 
00153                 # Not allowed to clear an existing non-empty email.
00154                 existing = member.getProperty('email')
00155                 
00156                 if existing and email == '':
00157                     return 'You must enter a valid email address.'
00158 
00159         return None
00160 

Here is the call graph for this function:


Member Data Documentation

tuple CMFPlone.RegistrationTool.RegistrationTool.__implements__ = (PloneBaseTool.__implements__, BaseTool.__implements__, ) [static, private]

Definition at line 53 of file RegistrationTool.py.

Definition at line 55 of file RegistrationTool.py.

Definition at line 54 of file RegistrationTool.py.

Definition at line 49 of file RegistrationTool.py.

Definition at line 52 of file RegistrationTool.py.

tuple CMFPlone.RegistrationTool.RegistrationTool.security = ClassSecurityInfo() [static]

Definition at line 50 of file RegistrationTool.py.

string CMFPlone.RegistrationTool.RegistrationTool.toolicon = 'skins/plone_images/pencil_icon.gif' [static]

Definition at line 51 of file RegistrationTool.py.


The documentation for this class was generated from the following file: