X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FResetPassword.py;h=61abd45719457642c60518fdfdfa41273b9799ae;hb=aee4a5354abde7ae9363053bce1a7117a8ed7b5e;hp=dd76a03de2c5a3d3f12f6100a50f3602fd4eafed;hpb=4f87899ff7aecb0d213ace1208694b288f9cd33d;p=plcapi.git diff --git a/PLC/Methods/ResetPassword.py b/PLC/Methods/ResetPassword.py index dd76a03..61abd45 100644 --- a/PLC/Methods/ResetPassword.py +++ b/PLC/Methods/ResetPassword.py @@ -1,8 +1,12 @@ +# $Id$ +# $URL$ import random import base64 import time import urllib +from types import StringTypes + from PLC.Debug import log from PLC.Faults import * from PLC.Method import Method @@ -33,15 +37,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 +59,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" @@ -104,14 +117,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 + print >> log, "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