def post(self): username = self.get_argument("username") password = self.get_argument("password") session_manager = Session() user = session_manager.login(username, password) if user: self.set_secure_cookie("user", self.get_argument("username")) session_id = self.get_secure_cookie("sessionID") session_manager.merge_session(username, session_id) self.redirect("/") else: self.render("error.html", message="username or password error!")
def save(self, model): with Session() as session: session.add(model) session.commit() session.refresh(model) return model
def delete(self, model): with Session() as session: session.delete(model) session.commit()
def read_by_id(self, id): with Session() as session: result = session.query(self.__model_type).filter_by(id_=id).first() return result
def read_all(self): with Session() as session: result = session.query(self.__model_type).order_by('id').all() return result
def get_current_user(self): username = self.get_secure_cookie("user") session_manager = Session() return session_manager.get_user(username)
def save(self, model) -> None: with Session() as session: session.add(model) session.commit()
def read_by_id(self, identifier: int): with Session() as session: result = session.query(self.__type_model).filter_by(id = identifier).first() return result
def read_all(self) -> list: with Session() as session: result = session.query(self.__type_model).all() return result