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
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
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)
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)
def by_id(cls, userid): session = DBSession() return session.query(cls).get(userid)