def __init__(self, remoteAddress, method, baseUri, path, fileext, params, headers, body): self.remoteAddress = remoteAddress self.method = method self.baseUri = baseUri self.path = path self.fileext = fileext self.params = params self.origParams = params.copy() self.headers = headers self.cookies = SimpleCookie(headers.get("Cookie", "")) self.body = body self.user = None if "session" in self.cookies: self.session = Session.findOne( {"id": self.cookies["session"].value}) if self.session: self.user = User.findOne({ "id": self.session.user, "passwordHash": self.session.passwordHash }) if self.user: self.session.lastAddress = self.remoteAddress self.session.lastUse = datetime.utcnow() self.session.save() self.user.isDisabled = False self.user.save() else: self.session.erase()
def createOne(cls, req, res): password = req.body.pop("password", "") user = User.findOne(req.body) if not user or not checkPassword(password, user.passwordHash): res.status = 400 render(req, res, "session/new.html.bepy") return user.isDisabled = False user.save() session = Session.create({ "user": user.id, "passwordHash": user.passwordHash, "lastAddress": req.remoteAddress, "lastUse": datetime.utcnow() }) res.cookies["session"] = session.id res.cookies["session"]["httponly"] = True res.cookies["session"]["max-age"] = 365 * 24 * 60 * 60 # 1 year should be permanent enough res.status = 201 res.headers["Location"] = "/session/{0}".format(session.id) render(req, res, "redirect-home.html.bepy") return session
def __init__(self, remoteAddress, method, baseUri, path, fileext, params, headers, body): self.remoteAddress = remoteAddress self.method = method self.baseUri = baseUri self.path = path self.fileext = fileext self.params = params self.origParams = params.copy() self.headers = headers self.cookies = SimpleCookie(headers.get("Cookie", "")) self.body = body self.user = None if "session" in self.cookies: self.session = Session.findOne({"id": self.cookies["session"].value}) if self.session: self.user = User.findOne({ "id": self.session.user, "passwordHash": self.session.passwordHash }) if self.user: self.session.lastAddress = self.remoteAddress self.session.lastUse = datetime.utcnow() self.session.save() self.user.isDisabled = False self.user.save() else: self.session.erase()
def createOne(cls, req, res): password = req.body.pop("password", "") user = User.findOne(req.body) if not user or not checkPassword(password, user.passwordHash): res.status = 400 render(req, res, "session/new.html.bepy") return user.isDisabled = False user.save() session = Session.create({ "user": user.id, "passwordHash": user.passwordHash, "lastAddress": req.remoteAddress, "lastUse": datetime.utcnow() }) res.cookies["session"] = session.id res.cookies["session"]["httponly"] = True res.cookies["session"][ "max-age"] = 365 * 24 * 60 * 60 # 1 year should be permanent enough res.status = 201 res.headers["Location"] = "/session/{0}".format(session.id) render(req, res, "redirect-home.html.bepy") return session
def find(cls, req, res): if not req.user: res.status = 403 return return Session.paginate({"user": req.user.id}, page=req.params.pop("page", 1))
def find(cls, req, res): if not req.user: res.status = 403 return return Session.paginate({"user": req.user.id}, page = req.params.pop("page", 1))