def post(self, *args, **kwargs): """ do login action :param args: :param kwargs: """ login_id = self.get_argument("login_id") login_pwd = self.get_argument("login_pwd") if not login_id or not login_pwd: self.redirect(self.get_login_url()) cnn = SessionFactory.new() if Utils.is_email(Utils.trim(login_id)): rows = cnn.query(Account.id, Archives.name).outerjoin(Archives, Account.archives_id == Archives.id) \ .filter(Archives.email == login_id).filter(Account.login_pwd == Utils.md5(login_pwd)) \ .filter(Account.enabled == 1).limit(1).all() if len(rows) > 0: id_ = rows[0][0] name = rows[0][1] self.set_secure_cookie(IRequest.__key_account_id__, "%i" % id_) self.set_secure_cookie(IRequest.__key_account_name__, name) Login.update_last_login_datetime(id_) else: rows = cnn.query(Account.id, Archives.name).outerjoin(Archives, Account.archives_id == Archives.id) \ .filter(Account.login_name == login_id).filter(Account.login_pwd == Utils.md5(login_pwd)) \ .filter(Account.enabled == 1).limit(1).all() if len(rows) > 0: id_ = rows[0][0] name = rows[0][1] self.set_secure_cookie(IRequest.__key_account_id__, "%i" % id_) self.set_secure_cookie(IRequest.__key_account_name__, name) Login.update_last_login_datetime(id_) self.redirect("/workbench/dashboard")
def exists_other(self, id, name_): cnn = SessionFactory.new() num = cnn.query(func.count(TermTaxonomy.id)).filter(TermTaxonomy.id != id) \ .filter(TermTaxonomy.term.has(name=Utils.trim(name_))) \ .filter(TermTaxonomy.taxonomy == self.taxonomy) \ .limit(1).scalar() if num > 0: return True return False
def create_term(self, name): name_ = Utils.trim(name) cnn = SessionFactory.new() id = cnn.query(Term.id).filter(Term.name == name_).limit(1).scalar() if not id: term = Term() term.name = name_ term.slug = name_ cnn.add(term) cnn.commit() return term.id return id