X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FResetPassword.py;h=8e9da53a2a40cbede83721d8a301f7b114b2e450;hb=19d4a01ccf66af9e00914351b3eacd5fc880f988;hp=24282451d65b72c5449e8ada57847b4bc2a860ea;hpb=6af2c3e935948543c3c5aaa59a91baa2a05caa7c;p=plcapi.git diff --git a/PLC/Methods/ResetPassword.py b/PLC/Methods/ResetPassword.py index 2428245..8e9da53 100644 --- a/PLC/Methods/ResetPassword.py +++ b/PLC/Methods/ResetPassword.py @@ -3,7 +3,9 @@ import base64 import time import urllib -from PLC.Debug import log +from types import StringTypes + +from PLC.Logger import logger from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed @@ -33,15 +35,21 @@ class ResetPassword(Method): Auth(), Mixed(Person.fields['person_id'], Person.fields['email']), - Person.fields['verification_key'], + Person.fields['verification_key'], Person.fields['verification_expires'] ] returns = Parameter(int, '1 if verification_key is valid') def call(self, auth, person_id_or_email, verification_key = None, verification_expires = None): - # Get account information - persons = Persons(self.api, [person_id_or_email]) + # Get account information + # we need to search in local objects only + if isinstance (person_id_or_email,StringTypes): + filter={'email':person_id_or_email} + else: + filter={'person_id':person_id_or_email} + filter['peer_id']=None + persons = Persons(self.api, filter) if not persons: raise PLCInvalidArgument, "No such account" person = persons[0] @@ -49,6 +57,9 @@ class ResetPassword(Method): if person['peer_id'] is not None: raise PLCInvalidArgument, "Not a local account" + if not person['enabled']: + raise PLCInvalidArgument, "Account must be enabled" + # Be paranoid and deny password resets for admins if 'admin' in person['roles']: raise PLCInvalidArgument, "Cannot reset admin passwords" @@ -96,7 +107,7 @@ class ResetPassword(Method): params = {'PLC_NAME': self.api.config.PLC_NAME, 'PLC_MAIL_SUPPORT_ADDRESS': self.api.config.PLC_MAIL_SUPPORT_ADDRESS, 'PLC_WWW_HOST': self.api.config.PLC_WWW_HOST, - 'PLC_WWW_SSL_PORT': self.api.config.PLC_WWW_PORT, + 'PLC_WWW_SSL_PORT': self.api.config.PLC_WWW_SSL_PORT, 'person_id': person['person_id'], # Will be used in a URL, so must quote appropriately 'verification_key': urllib.quote_plus(random_key), @@ -104,14 +115,14 @@ class ResetPassword(Method): 'email': person['email']} sendmail(self.api, - To = "%s %s <%s>" % (person['first_name'], person['last_name'], person['email']), - Subject = message['subject'], + To = ("%s %s" % (person['first_name'], person['last_name']), person['email']), + Subject = message['subject'] % params, Body = message['template'] % params) else: - print >> log, "Warning: No message template '%s'" % message-id + logger.warning("No message template '%s'" % message_id) - # Logging variables - self.object_ids = [person['person_id']] + # Logging variables + self.event_objects = {'Person': [person['person_id']]} self.message = message_id return 1