示例#1
0
文件: user.py 项目: wwitzel3/stockpot
 def validate(cls, email, password):
     try:
         session = DBSession()
         user = session.query(cls).filter_by(email=email).one()
         if crypt.check(user.password, password):
             return user
     except NoResultFound:
         return None
     else:
         return None
示例#2
0
    def setUp(self):
        connection = self.engine.connect()

        # begin a non-ORM transaction
        self.trans = connection.begin()

        # bind an individual Session to the connection
        DBSession.configure(bind=connection)
        self.session = self.Session(bind=connection)
        Base.session = self.session
示例#3
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        user = User(email='*****@*****.**', password='******', username='******')
        for ace in SITE_ACL:
            DBSession.add(Group(ace[1]))
        DBSession.flush()
        group = DBSession.query(Group).filter_by(name='role:admin').one()
        user.groups.add(group)
        DBSession.add(user)
示例#4
0
def login_view(request):
    if 'form.submitted' in request.POST:
        try:
            cuser = S.User().deserialize(request.POST)
        except Invalid, e:
            return {'login_url':login_url, 'errors':e.asdict()}
        else:
            user = User(**cuser)
            session = DBSession()
            group = session.query(Group).filter_by(name='role:viewer').one()
            user.groups.append(group)

            session.add(user)
            session.flush()

            headers = remember(request, user.id)
            redirect_url = route_url('index', request)
            return HTTPFound(location=redirect_url, headers=headers)
示例#5
0
文件: user.py 项目: wwitzel3/stockpot
 def by_id(cls, userid):
     session = DBSession()
     return session.query(cls).get(userid)