import time
import urllib
-from PLC.Debug import log
+from PLC.Logger import logger
from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
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
+ # Get account information
persons = Persons(self.api, [person_id_or_email])
if not persons:
- raise PLCInvalidArgument, "No such account"
+ raise PLCInvalidArgument, "No such account %r"%person_id_or_email
person = persons[0]
if person['peer_id'] is not None:
- raise PLCInvalidArgument, "Not a local account"
+ raise PLCInvalidArgument, "Not a local account %r"%person_id_or_email
if person['enabled']:
- raise PLCInvalidArgument, "Account must be new (disabled)"
+ raise PLCInvalidArgument, "Account %r must be new (disabled)"%person_id_or_email
# Get the primary site name
person_sites = Sites(self.api, person['site_ids'])
random_key = base64.b64encode("".join(map(chr, bytes)))
if verification_key is None or \
- (verification_key is not None and person['verification_expires'] and \
- person['verification_expires'] < time.time()):
- # Only allow one verification at a time
+ (verification_key is not None and person['verification_expires'] and \
+ person['verification_expires'] < time.time()):
+ # Only allow one verification at a time
if person['verification_expires'] is not None and \
person['verification_expires'] > time.time():
raise PLCPermissionDenied, "Verification request already pending"
message_id = 'Verify account'
- elif verification_key is not None:
+ elif verification_key is not None:
if person['verification_key'] is None or \
person['verification_expires'] is None:
raise PLCPermissionDenied, "Invalid Verification key"
elif person['verification_key'] != verification_key:
- raise PLCPermissionDenied, "Verification key incorrect"
+ raise PLCPermissionDenied, "Verification key incorrect"
else:
person['verification_key'] = None
person['verification_expires'] = None
for site in person_sites:
person_ids.update(site['person_ids'])
persons = Persons(self.api, person_ids)
- pis = filter(lambda person: 'pi' in person['roles'], persons)
+ pis = filter(lambda person: 'pi' in person['roles'] and person['enabled'], persons)
# Send e-mail to PI(s) and copy the user
To = [("%s %s" % (pi['first_name'], pi['last_name']), pi['email']) for pi in pis]
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
-
- if verification_key is not None and person['verification_expires'] and \
+
+ if verification_key is not None and person['verification_expires'] and \
person['verification_expires'] < time.time():
- raise PLCPermissionDenied, "Verification key has expired. Another email has been sent."
+ raise PLCPermissionDenied, "Verification key has expired. Another email has been sent."
return 1