# Path: cms/dateutil.py
# def utcnow(zero_seconds=False):
#     """ Returns a timezone aware version of utcnow.
#     If zero_seconds, the datetime will be rounded down to the minute.
#     """
#     now = datetime.datetime.now(pytz.utc)
#     if zero_seconds: return now.replace(second=0, microsecond=0)
#     return now


from collection import Collection
from object import Object
from cms.dateutil import utcnow
from hashlib import sha1
from pyramid.traversal import find_root
from pyramid_mailer import get_mailer
from pyramid_mailer.message import Message
import colander, deform
import random
import widgets
import permissions
    def _load_nonschema_attributes(self, **kwargs):
        Object._load_nonschema_attributes(self, **kwargs)
        self.encoded_password = kwargs.get('encoded_password', '')
        self.last_logged_in = kwargs.get('last_logged_in', None)

    def set_password(self, password):
        self.encoded_password = self.encode_password(password)

    def set_last_logged_in(self, timestamp=None):
        if not timestamp: timestamp = utcnow()
        self.last_logged_in = timestamp

    def encode_password(self, password, salt=None):
        if salt is None: salt = "%08x" % random.randint(0, 0xffffffff)
        return salt + sha1(password).hexdigest()

    def check_password(self, password):
        if not self.active: return False
        if not self.encoded_password: return False # Don't allow login if no password set.
        salt = self.encoded_password[:-40]
        return self.encoded_password == self.encode_password(password, salt)

    def mail_password(self, password):
        #print "mail password: username=%s password=%s" % (self.__name__, password)
        root = self.find_root()
        # FIXME: make this stuff configurable...
        subject = "Your login info for %s" % root.title
        data = dict(
            site_title = root.title,
            login_url = self.request.resource_url(root, 'login'),

# Path: cms/dateutil.py
# def utcnow(zero_seconds=False):
#     """ Returns a timezone aware version of utcnow.
#     If zero_seconds, the datetime will be rounded down to the minute.
#     """
#     now = datetime.datetime.now(pytz.utc)
#     if zero_seconds: return now.replace(second=0, microsecond=0)
#     return now


# Path: cms/resources/users.py
from collection import Collection
from object import Object
from cms.dateutil import utcnow
from hashlib import sha1
from pyramid.traversal import find_root
from pyramid_mailer import get_mailer
from pyramid_mailer.message import Message
import colander, deform
import random
import widgets
import permissions

    def _load_nonschema_attributes(self, **kwargs):
        Object._load_nonschema_attributes(self, **kwargs)
        self.encoded_password = kwargs.get('encoded_password', '')
        self.last_logged_in = kwargs.get('last_logged_in', None)

    def set_password(self, password):
        self.encoded_password = self.encode_password(password)

    def set_last_logged_in(self, timestamp=None):
        if not timestamp: timestamp = utcnow()
        self.last_logged_in = timestamp

    def encode_password(self, password, salt=None):
        if salt is None: salt = "%08x" % random.randint(0, 0xffffffff)
        return salt + sha1(password).hexdigest()

    def check_password(self, password):
        if not self.active: return False
        if not self.encoded_password: return False # Don't allow login if no password set.
        salt = self.encoded_password[:-40]
        return self.encoded_password == self.encode_password(password, salt)

    def mail_password(self, password):
        #print "mail password: username=%s password=%s" % (self.__name__, password)
        root = self.find_root()
        # FIXME: make this stuff configurable...
        subject = "Your login info for %s" % root.title
        data = dict(
            site_title = root.title,
            login_url = self.request.resource_url(root, 'login'),

            username = self.__name__,