class NewsClipApp(BigBlack): "news clipping system main application class" def __init__(self): "NewsClipApp constructor" BigBlack.__init__(self) self.debugger = Debugger(self) db = FbDb(self.config.get_dir("storage_dir")) self._db = db self.session = Session(self, db, self.config.get_value("session_salt")) # subroutines def _login(self): uname = self.cgi.param("loginname") passwd = self.cgi.param("passwd") if self._db.exists("users"): d = self._db.retrive("users", uname, None) if d and d["passwd"] == passwd: # send cookie self.session.new_session("uname") self.redirect("") else: self.view.render("login.html", dict(title="newsclip login", error="error")) else: self._setup() def _setup(self): self.view.render("setup.html", dict(title="newsclip setup")) # handlers def h_setup(self): if self.cgi.getfirst("setup") != "1": print self.redirect("") return uname = self.cgi.getfirst("loginname") passwd = self.cgi.getfirst("passwd") if uname and passwd: s = hashlib.sha1() s.update(passwd) d = dict(uname=uname, passwd=s.hexdigest()) self._db.create_db("users") self._db.create("users", uname, d) self.redirect("") def root(self): if not self._db.exists("users"): return self._setup() if self.cgi.getfirst("login") == "1": return self._login() self.view.render("login.html", dict(title="newsclip login"))
def __init__(self): "NewsClipApp constructor" BigBlack.__init__(self) self.debugger = Debugger(self) db = FbDb(self.config.get_dir("storage_dir")) self._db = db self.session = Session(self, db, self.config.get_value("session_salt"))