# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: Persons.py,v 1.22 2006/11/28 14:55:00 thierry Exp $
+# $Id: Persons.py,v 1.26 2007/01/05 15:56:16 tmack Exp $
#
from types import StringTypes
from PLC.Filter import Filter
from PLC.Table import Row, Table
from PLC.Keys import Key, Keys
+from PLC.Messages import Message, Messages
import PLC.Sites
class Person(Row):
'bio': Parameter(str, "Biography", max = 254, nullok = True),
'enabled': Parameter(bool, "Has been enabled"),
'password': Parameter(str, "Account password in crypt() form", max = 254),
- 'last_updated': Parameter(int, "Date and time of last update", ro = True),
+ 'verification_key': Parameter(str, "Reset password key", max = 254),
+ 'verification_expires': Parameter(str, "Date/Time when verification_key expires", max = 254),
+ 'last_updated': Parameter(int, "Date and time of last update", ro = True),
'date_created': Parameter(int, "Date and time when account was created", ro = True),
'role_ids': Parameter([int], "List of role identifiers"),
'roles': Parameter([str], "List of roles"),
# for Cache
class_key = 'email'
foreign_fields = ['first_name', 'last_name', 'title', 'email', 'phone', 'url',
- 'bio', 'enabled', 'password', 'last_updated', 'date_created']
+ 'bio', 'enabled', 'password', ]
+ # forget about these ones, they are read-only anyway
+ # handling them causes Cache to re-sync all over again
+ # 'last_updated', 'date_created'
foreign_xrefs = [
{'field' : 'key_ids', 'class': 'Key', 'table' : 'person_key' } ,
{'field' : 'site_ids', 'class': 'Site', 'table' : 'person_site'},
self['site_ids'].remove(site_id)
self['site_ids'].insert(0, site_id)
+ def send_initiate_password_reset_email(self):
+ # email user next step instructions
+ to_addr = {}
+ to_addr[self['email']] = "%s %s" % \
+ (self['first_name'], self['last_name'])
+ from_addr = {}
+ from_addr[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = \
+ "%s %s" % ('Planetlab', 'Support')
+ messages = Messages(self.api, ['PASSWORD_RESET_INITIATE'])
+ if not messages:
+ raise PLCAPIError, "Email template not found"
+ message = messages[0]
+ subject = message['subject']
+ template = message['template'] % \
+ (self.api.config.PLC_WWW_HOST,
+ self['verification_key'], self['person_id'],
+ self.api.config.PLC_MAIL_SUPPORT_ADDRESS,
+ self.api.config.PLC_WWW_HOST)
+
+ self.api.mailer.mail(to_addr, None, from_addr, subject, template)
+
+
def delete(self, commit = True):
"""
Delete existing account.
elif isinstance(person_filter, dict):
person_filter = Filter(Person.fields, person_filter)
sql += " AND (%s)" % person_filter.sql(api, "AND")
-
self.selectall(sql)