# 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

    _object_type = "user"
    _name_title = "Username"

    def get_class_schema(cls, request=None):
        schema = colander.SchemaNode(colander.Mapping())
        schema.add(colander.SchemaNode(colander.String(), name='firstname', title='First name', widget=widgets.get_wide_text_widget()))
        schema.add(colander.SchemaNode(colander.String(), name='lastname', title='Last name', widget=widgets.get_wide_text_widget()))
        schema.add(colander.SchemaNode(colander.String(), name='email', title='E-mail address', validator=colander.Email(), widget=widgets.get_wide_text_widget()))
        schema.add(colander.SchemaNode(deform.Set(allow_empty=True), name='groups', title='Groups', widget=deform.widget.CheckboxChoiceWidget(values=get_groups_vocabulary(request))))
        schema.add(colander.SchemaNode(colander.Boolean(), name='active', title='Active account', description="A user must be active in able to log in.  You can mark an account as inactive as an alternative to deleting the account.", default=True))
        return schema
    get_class_schema = classmethod(get_class_schema)

    def _get_nonschema_mongo_save_document(self):
        doc = Object._get_nonschema_mongo_save_document(self)
        doc['encoded_password'] = self.encoded_password
        doc['last_logged_in'] = self.last_logged_in
        doc['sortable_fullname'] = self.sortable_fullname.lower()  # a convenient single sort field for the user management page
        return doc

    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):

# 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


    _object_type = "user"
    _name_title = "Username"

    def get_class_schema(cls, request=None):
        schema = colander.SchemaNode(colander.Mapping())
        schema.add(colander.SchemaNode(colander.String(), name='firstname', title='First name', widget=widgets.get_wide_text_widget()))
        schema.add(colander.SchemaNode(colander.String(), name='lastname', title='Last name', widget=widgets.get_wide_text_widget()))
        schema.add(colander.SchemaNode(colander.String(), name='email', title='E-mail address', validator=colander.Email(), widget=widgets.get_wide_text_widget()))
        schema.add(colander.SchemaNode(deform.Set(allow_empty=True), name='groups', title='Groups', widget=deform.widget.CheckboxChoiceWidget(values=get_groups_vocabulary(request))))
        schema.add(colander.SchemaNode(colander.Boolean(), name='active', title='Active account', description="A user must be active in able to log in.  You can mark an account as inactive as an alternative to deleting the account.", default=True))
        return schema
    get_class_schema = classmethod(get_class_schema)

    def _get_nonschema_mongo_save_document(self):
        doc = Object._get_nonschema_mongo_save_document(self)
        doc['encoded_password'] = self.encoded_password
        doc['last_logged_in'] = self.last_logged_in
        doc['sortable_fullname'] = self.sortable_fullname.lower()  # a convenient single sort field for the user management page
        return doc

    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()