def deleteUser(cookie, uid): session = Session() u = usermanagment.getUser(cookie) if not u.admin: raise Exception("Invalid access %s %s" % (uid, u.id)) q = session.query(User).filter_by(id=uid) if q.count() == 0: raise Exception("User not found") cu = q.one() session.delete(cu) session.commit()
def updateUser(cookie, uid, handle, name, pwd, admin, email): session = Session() u = usermanagment.getUser(cookie) if not u.admin and uid != u.id: raise Exception("Invalid access %s %s" % (uid, u.id)) if uid == -1: cu = User(handle) session.add(cu) else: q = session.query(User).filter_by(id=uid) if q.count() == 0: raise Exception("User not found") cu = q.one() cu.name = name cu.email = email if pwd: cu.password = pwd if u.admin: cu.admin = admin session.commit() return cu.id
def validateCookie(cookie): try: u = usermanagment.getUser(cookie) return [cookie, u.id, u.admin] except: return "invalid_cookie"