1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Persons import Person, Persons
5 from PLC.Messages import Message, Messages
6 from PLC.Auth import AnonymousAuth
10 class VerifyPerson(Method):
12 Check that the verification_key is valid for a specified person
15 Returns 1 if the verification key if valid.
18 roles = ['admin', 'pi', 'user', 'tech']
22 Mixed(Person.fields['person_id'],
23 Person.fields['email']),
24 Person.fields['verification_key']
27 returns = Parameter(int, '1 if verification_key is valid')
29 def call(self, auth, person_id_or_email, verification_key):
31 # Get account information
32 persons = Persons(self.api, [person_id_or_email])
34 raise PLCInvalidArgument, "No such account"
38 # make sure verification key matches
39 if not person['verification_key']:
40 raise PLCInvalidArgument, "Invalid key"
41 if person['verification_key'] != verification_key:
42 raise PLCInvalidArgument, "Invalid key"
44 # make sure key is not expired
45 if not person['verification_expires']:
46 raise PLCInvalidArgument, "Invalid key"
47 expires = str(person['verification_expires'])
48 if time.strptime(expires, "%Y-%m-%d %H:%M:%S") < \
49 time.gmtime(time.time()):
50 raise PLCInvalidArgument, "Invalid key"
53 self.object_ids = [person['person_id']]
54 self.message = 'Verification key check on perons %d.' % \