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 from random import Random
13 def create_random_string():
15 create and return a random string.
18 pool = string.letters + string.digits
19 key = [random.choice(pool) for i in range(32)]
25 class InitiateResetPassword(Method):
27 start the reset password procedure. this sends the user an email
28 they can use to go to the web interface to finish the reset of their
31 the password is not modified yet. A random link to a password reset page
32 is created, and set to expire in 24 hours.
34 Returns 1 if successful, faults otherwise.
37 roles = ['admin', 'pi', 'user', 'tech']
41 Mixed(Person.fields['person_id'],
42 Person.fields['email'])
45 returns = Parameter(int, '1 if successful')
47 def call(self, auth, person_id_or_email):
49 # Get account information
50 persons = Persons(self.api, [person_id_or_email])
52 raise PLCInvalidArgument, "No such account"
54 # update the verification key for this person in the db
56 verification_key = create_random_string()
57 person['verification_key'] = verification_key
58 person['verification_expires'] = \
59 time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(time.time()+86400))
62 # send notification email
63 person.send_initiate_password_reset_email()
66 self.object_ids = [person['person_id']]
67 self.message = 'Initiated password reset for person %d.' % \