def change(cls, sid, value): rec = db_session.query(cls).filter(cls.sid == sid).first() if not rec: rec = cls() rec.sid = sid rec.value = value return rec
def isValidAid(self, aid): aid = int(aid) max_aid_string = str(db_session.query(func.max(Album.aid)).first()) max_aid = int(max_aid_string[1:-2]) if aid < 0 or aid > max_aid: return False return True
def isValidUid(self, uid): uid = int(uid) max_uid_string = str(db_session.query(func.max(User.uid)).first()) max_uid = int(max_uid_string[1:-2]) if uid < 0 or uid > max_uid: return False return True
def open_session(self, app, request): sid = request.cookies.get(app.session_cookie_name) if not sid: sid = self.generate_sid() return self.session_class(sid=sid, new=True) rec = db_session.query(FlaskSession).filter(FlaskSession.sid == sid).first() if rec is not None: data = self.serializer.loads(rec.value) return self.session_class(data, sid=sid) return self.session_class(sid=sid, new=True)
def save_session(self, app, session, response): domain = self.get_cookie_domain(app) if not session: rec = db_session.query(FlaskSession).filter(FlaskSession.sid == session.sid).first() db_session.delete(rec) db_session.commit() if session.modified: response.delete_cookie(app.session_cookie_name, domain=domain) return val = self.serializer.dumps(dict(session)) session_db = FlaskSession.change(session, session.sid, val) db_session.add(session_db) db_session.commit() httponly = self.get_cookie_httponly(app) secure = self.get_cookie_secure(app) expires = self.get_expiration_time(app, session) response.set_cookie(app.session_cookie_name, session.sid, expires=expires, httponly=httponly, domain=domain, secure=secure)