Exemple #1
0
 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!")
Exemple #2
0
 def save(self, model):
     with Session() as session:
         session.add(model)
         session.commit()
         session.refresh(model)
     return model
Exemple #3
0
 def delete(self, model):
     with Session() as session:
         session.delete(model)
         session.commit()
Exemple #4
0
 def read_by_id(self, id):
     with Session() as session:
         result = session.query(self.__model_type).filter_by(id_=id).first()
     return result
Exemple #5
0
 def read_all(self):
     with Session() as session:
         result = session.query(self.__model_type).order_by('id').all()
     return result
Exemple #6
0
 def get_current_user(self):
     username = self.get_secure_cookie("user")
     session_manager = Session()
     return session_manager.get_user(username)
Exemple #7
0
 def save(self, model) -> None:
     with Session() as session:
         session.add(model)
         session.commit()
Exemple #8
0
 def read_by_id(self, identifier: int):
     with Session() as session:
         result = session.query(self.__type_model).filter_by(id = identifier).first()
     return result
Exemple #9
0
 def read_all(self) -> list:
     with Session() as session:
         result = session.query(self.__type_model).all()
     return result