# Copyright (c) 2013 - Network Box
#
# This file is part of Uptrack.
#
# Uptrack is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Uptrack is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Uptrack.  If not, see <http://www.gnu.org/licenses/>.


from sqlalchemy import Column, Integer, Unicode
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker

from zope.sqlalchemy import ZopeTransactionExtension


DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()

class BaseModel(object):
    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

    def __json__(self, request):
        return dict([(x, getattr(self, x))
                     for x in self._sa_class_manager.keys()])

class Release(Base, BaseModel):
    __tablename__ = 'release'
    id = Column(Integer, primary_key=True)
    name = Column(Unicode, unique=True, nullable=False)
    koji_tag = Column(Unicode, unique=True, nullable=False)
    git_url = Column(Unicode, unique=True, nullable=False)


@@ -1576,8 +1576,439 @@
 False)%0A%0A
+class User(Base, BaseModel):%0A    __tablename__ = 'users'%0A    id = Column(Integer, primary_key=True)%0A    login = Column(Unicode, unique=True, nullable=False)%0A    email = Column(Unicode, unique=True)%0A    # FIXME: encrypt passwords%0A    password = Column(Unicode, nullable=False)%0A    display_name = Column(Unicode)%0A%0A    def validate_password(self, password):%0A        # FIXME: encrypt passwords%0A        return self.password == password%0A

Add a simple user model