示例#1
0
    def post(self):
        if not self.current_user:
            self.redirect("/login")
            return

        email = self.get_argument("email")

        user_exist = conn.get("SELECT * FROM index_login WHERE login = %s",
                              email)
        invited = conn.get("SELECT * FROM invite WHERE email = %s", email)
        if user_exist or invited:
            self.redirect("/invite?status=exists")
            return

        #send email
        invite_code = ''.join(
            random.choice(string.digits + string.letters) for x in range(14))
        conn.execute("INSERT INTO invite (email, code) VALUES(%s, %s)", email,
                     invite_code)

        self.email = urllib.quote(email)
        self.invite_code = invite_code
        msg = EmailMessage()
        msg.subject = "Invite from Pythonic Info"
        msg.bodyHtml = self.render_string("../template/email_invite.html")
        self.send(settings["email_sender"], str(email), msg)
        print "url:", msg.bodyText

        self.redirect("/invite?status=success")
示例#2
0
    def post(self):
        if not self.current_user:
            self.redirect("/login")
            return

        email = self.get_argument("email")

        user_exist = conn.get("SELECT * FROM index_login WHERE login = %s", email)
        invited = conn.get("SELECT * FROM invite WHERE email = %s", email)
        if user_exist or invited:
            self.redirect("/invite?status=exists")
            return

        #send email
        invite_code = ''.join(random.choice(string.digits+string.letters) for x in range(14))
        conn.execute("INSERT INTO invite (email, code) VALUES(%s, %s)", email, invite_code)

        self.email = urllib.quote(email)
        self.invite_code = invite_code
        msg = EmailMessage()
        msg.subject = "Invite from Pythonic Info"
        msg.bodyHtml = self.render_string("../template/email_invite.html")
        self.send(settings["email_sender"], str(email), msg)
        print "url:", msg.bodyText

        self.redirect("/invite?status=success")
示例#3
0
文件: main.py 项目: kenans/front
    def get(self):
        collection_id = self.get_argument("id")
        collection = conn.get("SELECT * FROM collection WHERE id=%s", collection_id)
        if not collection:
            self.finish('')
            return

        liked = conn.get("SELECT * FROM likes WHERE collection_id = %s", collection_id)
        collection["liked"] = liked is not None

        self.finish(collection)
示例#4
0
def create_user(user):
    email = user["email"]
    assert not conn.get("SELECT * FROM index_login WHERE login = %s", email)

    user["type"] = "user"
    user["name"] = user.get("name", "")
    user["salt"] = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(10))
    if "password" in user:
        user["password"] = hashlib.sha1(user["password"] + user["salt"]).hexdigest()
    user["title"] = ""
    user["department"] = ""
    user["locatiion"] = ""
    user["mobile"] = ""
    user["tel"] = ""
    user["about"] = ""
    user["profile_img"] = ""
    user["datetime"] = datetime.datetime.now().isoformat()

    new_id = nomagic._new_key()
    assert nomagic._node(new_id).execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, nomagic._pack(user))

    #update indexes: email
    assert "@" in email
    assert conn.execute_rowcount("INSERT INTO index_login (login, entity_id) VALUES(%s, %s)", email, new_id)

    return (new_id, user)
示例#5
0
文件: auth.py 项目: kenans/front
    def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Google auth failed")
        self.user = user

        current_user = conn.get("SELECT * FROM users WHERE email = %s and type = 'g'",\
                                 user["email"])

        if current_user is None:
            self.user["id"] = conn.execute("INSERT INTO users (type, email, name) VALUES ('g', %s, %s)",\
                                       user["email"], user["name"])
            self.user["city"] = ""
        else:
            self.user["id"] = current_user["id"]
            self.user["city"] = current_user["city"]

        ip = self.request.headers.get("X-Forwarded-For", None) or self.request.remote_ip
        conn.execute("UPDATE users SET last_login_ip = %s WHERE id = %s",\
                      ip, self.user["id"])

        self.set_secure_cookie("user", tornado.escape.json_encode(self.user))

        if self.redirect_url == "/":
            self.redirect_url == "/"+self.user["city"]
        self.redirect(self.redirect_url)
示例#6
0
def get_public_feed(item_offset=15, item_start_id=None):
    if item_start_id:
        last_post = conn.get("SELECT * FROM index_posts WHERE entity_id = %s",
                             item_start_id)
        posts = conn.query(
            "SELECT * FROM index_posts WHERE rank < %s ORDER BY rank DESC LIMIT 0, %s",
            last_post["rank"], item_offset)
    else:
        posts = conn.query(
            "SELECT * FROM index_posts ORDER BY rank DESC LIMIT 0, %s",
            item_offset)
    item_ids = [i["entity_id"] for i in posts]

    if posts:
        items = [
            dict(item, id=item_id)
            for item_id, item in nomagic._get_entities_by_ids(item_ids)
        ]
        return [
            dict(
                item,
                like_count=len(item.get("likes", [])),
                comment_count=len(item.get("comment_ids", [])),
                url=item.get("url"),
            ) for item in items
        ]
    return []
示例#7
0
文件: auth.py 项目: kenans/front
    def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Google auth failed")
        self.user = user

        current_user = conn.get("SELECT * FROM users WHERE email = %s and type = 'g'",\
                                 user["email"])

        if current_user is None:
            self.user["id"] = conn.execute("INSERT INTO users (type, email, name) VALUES ('g', %s, %s)",\
                                       user["email"], user["name"])
            self.user["city"] = ""
        else:
            self.user["id"] = current_user["id"]
            self.user["city"] = current_user["city"]

        ip = self.request.headers.get("X-Forwarded-For",
                                      None) or self.request.remote_ip
        conn.execute("UPDATE users SET last_login_ip = %s WHERE id = %s",\
                      ip, self.user["id"])

        self.set_secure_cookie("user", tornado.escape.json_encode(self.user))

        if self.redirect_url == "/":
            self.redirect_url == "/" + self.user["city"]
        self.redirect(self.redirect_url)
示例#8
0
def create_user(user):
    email = user["email"]
    login = conn.get("SELECT * FROM index_login WHERE login = %s", email)
    assert not login

    user["type"] = "user"
    user["name"] = user.get("name", "")
    user["salt"] = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(10))
    user["password"] = hashlib.sha1(user["password"] + user["salt"]).hexdigest()
    user["title"] = ""
    user["department"] = ""
    user["locatiion"] = ""
    user["mobile"] = ""
    user["tel"] = ""
    user["about"] = ""
    user["profile_img"] = ""
    user["datetime"] = datetime.datetime.now().isoformat()

    new_id = nomagic._new_key()
    rowcount = nomagic._node(new_id).execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)", new_id, nomagic._pack(user))
    assert rowcount

    #update indexes: email
    assert "@" in email
    rowcount = conn.execute_rowcount("INSERT INTO index_login (login, entity_id) VALUES(%s, %s)", email, new_id)
    assert rowcount

    return (new_id, user)
示例#9
0
文件: feeds.py 项目: WifiPi/router
def get_fileinfo_by_rev(rev):
    fileinfo = conn.get("SELECT * FROM index_dropbox WHERE rev=%s", rev)
    if not fileinfo:
        return

    entity = nomagic._get_entity_by_id(fileinfo["entity_id"])
    return dict(entity, md5=fileinfo["entity_id"]) if entity else None
示例#10
0
 def get(self):
     login = self.get_argument("login")
     login_index = conn.get("SELECT * FROM index_login WHERE login = %s", login)
     if login_index:
         self.finish({})
         return
     self.finish({"error":"not exists"})
示例#11
0
    def get(self):
        wp_perfix = settings.get("wordpress_prefix", "wp_")

        term = self.get_argument("t", None)
        if term:
            term_record = conn.get("SELECT * FROM "+wp_perfix+"terms WHERE slug = %s", term)
            term_taxonomy = conn.get("SELECT * FROM "+wp_perfix+"term_taxonomy WHERE term_id = %s", term_record["term_id"])
            object_records = conn.query("SELECT * FROM "+wp_perfix+"term_relationships WHERE term_taxonomy_id = %s ORDER BY object_id DESC LIMIT 5", term_taxonomy["term_taxonomy_id"])
            self.post_list = conn.query("SELECT * FROM "+wp_perfix+"posts WHERE post_status = 'publish' AND post_type = 'post' AND ID IN %s ORDER BY ID DESC", tuple([i["object_id"] for i in object_records]))
            self.term = "&t=%s" % term
        else:
            self.post_list = conn.query("SELECT * FROM "+wp_perfix+"posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY ID DESC LIMIT 5")
            self.term = ""

        post_thumbnail_ids = {}
        meta_thumbnails = {}
        post_thumbnails = {}

        postmeta_list = conn.query("SELECT * FROM "+wp_perfix+"postmeta WHERE meta_key = '_thumbnail_id' AND post_id IN %s", tuple([int(i.ID) for i in self.post_list]))
        for postmeta in postmeta_list:
            post_thumbnail_ids[postmeta.post_id] = postmeta.meta_value

        postmeta_list = conn.query("SELECT * FROM "+wp_perfix+"postmeta WHERE meta_key = '_wp_attached_file' AND post_id IN %s" , tuple([int(i) for i in post_thumbnail_ids.values()]))
        for postmeta in postmeta_list:
            meta_thumbnails[postmeta.post_id] = postmeta.meta_value

        for k, v in post_thumbnail_ids.iteritems():
            post_thumbnails[k] = meta_thumbnails[long(v)]

        self.post_id_from = self.post_list[-1].ID
        self.carousel_list = []
        carousel_count = 0
        color_count = 0
        for post in self.post_list:
            post.thumbnail = "/wp-content/uploads/%s" % post_thumbnails[post.ID] if post_thumbnails.get(post.ID) else None
            if post.thumbnail and carousel_count < 3:
                self.carousel_list.append(post)
                carousel_count += 1

            soup = BeautifulSoup(post.post_content.split("<!--more-->")[0])
            post.post_excerpt = soup.get_text()

            post.color = POST_COLORS[color_count % len(POST_COLORS)]
            color_count += 1

        self.render('../template/main.html')
示例#12
0
    def get(self, post_name):
        wp_perfix = settings.get("wordpress_prefix", "wp_")

        self.post = conn.get("SELECT * FROM "+wp_perfix+"posts WHERE post_status = 'publish' AND post_type = 'post' AND post_name = %s", tornado.escape.url_escape(post_name))
        if not self.post:
            raise tornado.web.HTTPError(404)

        self.render('../template/post.html')
示例#13
0
def check_user(login, password):
    login_info = conn.get("SELECT entity_id FROM index_login WHERE login = %s", login)
    if login_info:
        user_id = login_info["entity_id"]
        user = nomagic._get_entity_by_id(user_id)
        if user["password"] == hashlib.sha1(password + user.get("salt", "")).hexdigest():
            return (user_id, user)
    return (None, None)
示例#14
0
def check_user(login, password):
    login_info = conn.get("SELECT entity_id FROM index_login WHERE login = %s", login)
    if login_info:
        user_id = login_info["entity_id"]
        user = nomagic._get_entity_by_id(user_id)
        if user["password"] == hashlib.sha1(password + user.get("salt", "")).hexdigest():
            return (user_id, user)
    return (None, None)
示例#15
0
    def get(self):
        wp_perfix = settings.get("wordpress_prefix", "wp_")

        from_id = int(self.get_argument("from", ""))
        term = self.get_argument("t", None)
        if term:
            term_record = conn.get("SELECT * FROM "+wp_perfix+"terms WHERE slug = %s", term)
            term_taxonomy = conn.get("SELECT * FROM "+wp_perfix+"term_taxonomy WHERE term_id = %s", term_record["term_id"])
            object_records = conn.query("SELECT * FROM "+wp_perfix+"term_relationships WHERE term_taxonomy_id = %s AND object_id < %s ORDER BY object_id DESC LIMIT 5", term_taxonomy["term_taxonomy_id"], from_id)
            post_list = conn.query("SELECT * FROM "+wp_perfix+"posts WHERE post_status = 'publish' AND post_type = 'post' AND ID IN %s ORDER BY ID DESC", tuple([i["object_id"] for i in object_records]))
            self.term = "&t=%s" % term
        else:
            post_list = conn.query("SELECT * FROM "+wp_perfix+"posts WHERE post_status = 'publish' AND post_type = 'post' AND ID < %s ORDER BY ID DESC LIMIT 5", from_id)

        post_thumbnail_ids = {}
        meta_thumbnails = {}
        post_thumbnails = {}

        postmeta_list = conn.query("SELECT * FROM "+wp_perfix+"postmeta WHERE meta_key = '_thumbnail_id' AND post_id IN %s", tuple([int(i.ID) for i in post_list]))
        for postmeta in postmeta_list:
            post_thumbnail_ids[postmeta.post_id] = postmeta.meta_value

        postmeta_list = conn.query("SELECT * FROM "+wp_perfix+"postmeta WHERE meta_key = '_wp_attached_file' AND post_id IN %s" , tuple([int(i) for i in post_thumbnail_ids.values()]))
        for postmeta in postmeta_list:
            meta_thumbnails[postmeta.post_id] = postmeta.meta_value

        for k, v in post_thumbnail_ids.iteritems():
            post_thumbnails[k] = meta_thumbnails[long(v)]

        post_list_json = []
        color_count = 0
        for post in post_list:
            soup = BeautifulSoup(post.post_content.split("<!--more-->")[0])
            post_json = {}
            post_json["post_excerpt"] = soup.get_text()
            post_json["post_title"] = post.post_title
            post_json["post_name"] = post.post_name
            post_json["thumbnail"] = "/wp-content/uploads/%s" % post_thumbnails[post.ID] if post_thumbnails.get(post.ID) else None
            post_json["color"] = POST_COLORS[color_count % len(POST_COLORS)]
            color_count += 1

            post_list_json.append(post_json)

        self.finish({"list":post_list_json, "post_id_from":post_list[-1].ID if post_list else 0})
示例#16
0
    def get(self, post_name):
        wp_perfix = settings.get("wordpress_prefix", "wp_")

        self.post = conn.get(
            "SELECT * FROM %sposts WHERE post_status = 'publish' AND post_type = 'post' AND post_name = %s"
            % (wp_perfix, "%s"), tornado.escape.url_escape(post_name))
        if not self.post:
            raise tornado.web.HTTPError(404)

        self.render('../template/post.html')
示例#17
0
    def post(self):
        login = self.get_argument("login", None)
        password = self.get_argument("password", None)

        invite_code = self.get_argument("invite_code", None)
        email = self.get_argument("email", None)
        name = self.get_argument("name", None)
        password1 = self.get_argument("password1", None)
        password2 = self.get_argument("password2", None)

        if login and password:
            user_id, user = nomagic.auth.check_user(login, password)
            if user_id:
                self.set_secure_cookie(
                    "user", tornado.escape.json_encode({"user_id": user_id}))
                self.redirect("/?status=login")
                return

        elif email and name and password1 and password2 and password1 == password2 and invite_code:
            invited = conn.get("SELECT * FROM invite WHERE code = %s",
                               invite_code)
            if not invited:
                self.redirect("/login?status=need_invite_code")
                return

            data = {"email": email, "name": name, "password": password1}
            try:
                user_id, user = nomagic.auth.create_user(data)

                self.set_secure_cookie(
                    "user", tornado.escape.json_encode({"user_id": user_id}))

                email_verify_code = ''.join(
                    random.choice(string.digits + string.letters)
                    for x in range(14))
                result = nomagic.auth.update_user(
                    user_id, {
                        "email_verified": False,
                        "email_verify_code": email_verify_code
                    })

                #send verify email here
                msg = EmailMessage()
                msg.subject = "Confirm Email from Pythonic Info"
                msg.bodyText = "http://pythonic.info/verify_email?user_id=%s&verify_code=%s" % (
                    user_id, email_verify_code)
                self.send("*****@*****.**", str(email), msg)
                print "url:", msg.bodyText

                self.redirect("/?status=created")
                return
            except:
                pass

        self.redirect("/login?status=error")
示例#18
0
文件: main.py 项目: kenans/front
 def get(self):
     if self.current_user:
         board_id = self.get_argument("id", None)
         if board_id:
             board = conn.get("SELECT * FROM boards WHERE user_id = %s and id = %s", self.current_user["id"], board_id)
             self.finish({"board": board,"error":None})
             return
         boards = conn.query("SELECT * FROM boards WHERE user_id = %s", self.current_user["id"])
         self.finish({"boards":boards, "error":None})
     else:
         self.finish({"error":"login required"})
示例#19
0
文件: main.py 项目: kenans/front
    def put(self):
        if self.current_user:
            name = self.get_argument("name")
            category_id = self.get_argument("category_id")

            board = conn.get("SELECT * FROM boards WHERE user_id = %s and name = %s", self.current_user["id"], name)

            if board:
                self.finish({"error":"duplicated name"})
            else:
                conn.execute("INSERT INTO boards (user_id, name) VALUES (%s,%s)", self.current_user["id"], name)
                self.finish({"error":None})
示例#20
0
文件: main.py 项目: kenans/front
    def delete(self):
        if self.current_user:
            board_id = self.get_argument("board_id")
            name = self.get_argument("name")
            category_id = self.get_argument("category_id")

            board = conn.get("SELECT * FROM boards WHERE user_id = %s and name = %s and id= %s and category_id = %s", self.current_user["id"], name, board_id, category_id)

            if board:
                conn.execute("DELETE FROM boards WHERE id = %s and user_id = %s", board_id, self.current_user["id"])
                self.finish({"error":None})
            else:
                self.finish({"error":"something else changed"})
示例#21
0
def disconnect_index_and_entity(table_index, index_name, index_connection_name, entity_id, entity_connection_name):
    index = conn.get("SELECT * FROM %s WHERE name = %s" % (table_index, "%s"), index_name)
    index_data = nomagic._unpack(index["data"] or "{}")
    index_connection = set(index_data.get(index_connection_name, []))
    if entity_id in index_connection:
        index_connection.remove(entity_id)
        index_data[index_connection_name] = list(index_connection)
        index_data_updated = nomagic._pack(index_data)
        conn.execute("UPDATE %s SET data = %s WHERE name = %s" % (table_index, "%s", "%s"), index_data_updated, index_name)

    entity = nomagic._get_entity_by_id(entity_id)
    entity_connection = set(entity.get(entity_connection_name, []))
    if index_name in entity_connection:
        entity_connection.remove(index_name)
        entity[entity_connection_name] = list(entity_connection)
        nomagic._update_entity_by_id(entity_id, entity)
示例#22
0
def get_public_feed(item_offset=15, item_start_id=None):
    if item_start_id:
        last_post = conn.get("SELECT * FROM index_posts WHERE entity_id = %s", item_start_id)
        posts = conn.query("SELECT * FROM index_posts WHERE rank < %s ORDER BY rank DESC LIMIT 0, %s", last_post["rank"], item_offset)
    else:
        posts = conn.query("SELECT * FROM index_posts ORDER BY rank DESC LIMIT 0, %s", item_offset)
    item_ids = [i["entity_id"] for i in posts]

    if posts:
        items = [dict(item, id=item_id)
                        for item_id, item in nomagic._get_entities_by_ids(item_ids)]
        return [dict(item,
                     like_count = len(item.get("likes", [])),
                     comment_count = len(item.get("comment_ids", [])),
                     url = item.get("url"),
                     ) for item in items]
    return []
示例#23
0
    def post(self):
        login = self.get_argument("login", None)
        password = self.get_argument("password", None)

        invite_code = self.get_argument("invite_code", None)
        email = self.get_argument("email", None)
        name = self.get_argument("name", None)
        password1 = self.get_argument("password1", None)
        password2 = self.get_argument("password2", None)

        if login and password:
            user_id, user = nomagic.auth.check_user(login, password)
            if user_id:
                self.set_secure_cookie("user", tornado.escape.json_encode({"user_id": user_id}))
                self.redirect("/?status=login")
                return

        elif email and name and password1 and password2 and password1 == password2 and invite_code:
            invited = conn.get("SELECT * FROM invite WHERE code = %s", invite_code)
            if not invited:
                self.redirect("/login?status=need_invite_code")
                return

            data = {"email": email, "name": name, "password": password1}
            try:
                user_id, user = nomagic.auth.create_user(data)

                self.set_secure_cookie("user", tornado.escape.json_encode({"user_id": user_id}))

                email_verify_code = ''.join(random.choice(string.digits+string.letters) for x in range(14))
                result = nomagic.auth.update_user(user_id, {"email_verified": False, "email_verify_code": email_verify_code})

                #send verify email here
                msg = EmailMessage()
                msg.subject = "Confirm Email from Pythonic Info"
                msg.bodyText = "http://pythonic.info/verify_email?user_id=%s&verify_code=%s" % (user_id, email_verify_code)
                self.send("*****@*****.**", str(email), msg)
                print "url:", msg.bodyText

                self.redirect("/?status=created")
                return
            except:
                pass

        self.redirect("/login?status=error")
示例#24
0
    def _on_auth(self, google_user):
        if not google_user:
            raise tornado.web.HTTPError(500, "Google auth failed")

        current_user = conn.get("SELECT * FROM index_login WHERE login = %s", google_user["email"])

        if current_user is None:
            user_id, user = nomagic.create_user({"email":google_user["email"], "name":google_user["name"], "google": google_user})

        else:
            user_id = current_user["entity_id"]
            user = nomagic._get_entity_by_id(user_id)
            if "google" not in user:
                raise tornado.web.HTTPError(500, "Can not login with Google")

        self.set_secure_cookie("user", tornado.escape.json_encode({"user_id": user_id}))

        self.redirect(self.redirect_url)
示例#25
0
文件: feeds.py 项目: WifiPi/router
def update_fileinfo(filehash, user_id, id3info = None, title = None, rev = None):
    if rev:
        if not conn.get("SELECT * FROM index_dropbox WHERE rev=%s", rev):
            assert conn.execute_rowcount("INSERT INTO index_dropbox (rev, entity_id) VALUES (%s, %s)", rev, filehash)

    fileinfo = nomagic._get_entity_by_id(filehash)
    if fileinfo:
        changed = False

        owners = fileinfo.get("owners", [])
        if user_id not in owners:
            owners.append(user_id)
            fileinfo["owners"] = owners
            changed = True

        if id3info and id3info != fileinfo.get("id3info"):
            fileinfo["id3info"] = id3info
            changed = True

        if title and title != fileinfo.get("title"):
            fileinfo["title"] = title
            changed = True

        if changed:
            nomagic._update_entity_by_id(filehash, fileinfo)

    else:
        fileinfo = {"owners":[user_id]}
        if id3info:
            fileinfo["id3info"] = id3info
        if title:
            fileinfo["title"] = title
        assert nomagic._node(filehash).execute_rowcount("INSERT INTO entities (id, body) VALUES(%s, %s)",\
                                                                filehash, nomagic._pack(fileinfo))

    user = nomagic._get_entity_by_id(user_id)
    if user:
        files = user.get("files", [])
        if filehash not in files:
            files.append(filehash)
            user["files"] = files
            nomagic._update_entity_by_id(user_id, user)

    return fileinfo, user
示例#26
0
def disconnect_index_and_entity(table_index, index_name, index_connection_name,
                                entity_id, entity_connection_name):
    index = conn.get("SELECT * FROM %s WHERE name = %s" % (table_index, "%s"),
                     index_name)
    index_data = nomagic._unpack(index["data"] or "{}")
    index_connection = set(index_data.get(index_connection_name, []))
    if entity_id in index_connection:
        index_connection.remove(entity_id)
        index_data[index_connection_name] = list(index_connection)
        index_data_updated = nomagic._pack(index_data)
        conn.execute(
            "UPDATE %s SET data = %s WHERE name = %s" %
            (table_index, "%s", "%s"), index_data_updated, index_name)

    entity = nomagic._get_entity_by_id(entity_id)
    entity_connection = set(entity.get(entity_connection_name, []))
    if index_name in entity_connection:
        entity_connection.remove(index_name)
        entity[entity_connection_name] = list(entity_connection)
        nomagic._update_entity_by_id(entity_id, entity)
示例#27
0
文件: auth.py 项目: kenans/front
    def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Facebook auth failed")
        self.user = user
        #print user

        #login or create account with fb
        current_user = conn.get("SELECT * FROM users WHERE facebook_id = %s and type = 'f'",\
                                 user["id"])

        if current_user is None:
            self.user["id"] = conn.execute("INSERT INTO users (type, facebook_id, name) VALUES ('f', %s, %s)",\
                                       user["id"], user["name"])
            self.user["city"] = ""
        else:
            self.user["id"] = current_user["id"]
            self.user["city"] = current_user["city"]

        #get fb email
        self.facebook_request(path="/me",
                              callback=self._on_userinfo,
                              access_token=user["access_token"])
示例#28
0
文件: auth.py 项目: kenans/front
    def _on_auth(self, user):
        if not user:
            raise tornado.web.HTTPError(500, "Facebook auth failed")
        self.user = user
        #print user

        #login or create account with fb
        current_user = conn.get("SELECT * FROM users WHERE facebook_id = %s and type = 'f'",\
                                 user["id"])

        if current_user is None:
            self.user["id"] = conn.execute("INSERT INTO users (type, facebook_id, name) VALUES ('f', %s, %s)",\
                                       user["id"], user["name"])
            self.user["city"] = ""
        else:
            self.user["id"] = current_user["id"]
            self.user["city"] = current_user["city"]

        #get fb email
        self.facebook_request(
            path="/me",
            callback=self._on_userinfo,
            access_token=user["access_token"])
示例#29
0
def get_user_id_by_login(login):
    index_login = conn.get("SELECT * FROM index_login WHERE login = %s", login)
    return index_login["entity_id"] if index_login else None
示例#30
0
def get_user_by_login(login):
    index_login = conn.get("SELECT * FROM index_login WHERE login = %s", login)
    entity_id = index_login["entity_id"]

    return nomagic._get_entity_by_id(entity_id)
示例#31
0
    def get(self):
        wp_perfix = settings.get("wordpress_prefix", "wp_")

        from_id = int(self.get_argument("from", ""))
        term = self.get_argument("t", None)
        if term:
            term_record = conn.get(
                "SELECT * FROM %sterms WHERE slug = %s" % (wp_perfix, "%s"),
                term)
            term_taxonomy = conn.get(
                "SELECT * FROM %sterm_taxonomy WHERE term_id = %s" %
                (wp_perfix, "%s"), term_record["term_id"])
            object_records = conn.query(
                "SELECT * FROM %sterm_relationships WHERE term_taxonomy_id = %s AND object_id < %s ORDER BY object_id DESC LIMIT 5"
                % (wp_perfix, "%s", "%s"), term_taxonomy["term_taxonomy_id"],
                from_id)
            post_list = conn.query(
                "SELECT * FROM %sposts WHERE post_status = 'publish' AND post_type = 'post' AND ID IN %s ORDER BY ID DESC"
                % (wp_perfix, "%s"),
                tuple([i["object_id"] for i in object_records]))
            self.term = "&t=%s" % term
        else:
            post_list = conn.query(
                "SELECT * FROM %sposts WHERE post_status = 'publish' AND post_type = 'post' AND ID < %s ORDER BY ID DESC LIMIT 5"
                % (wp_perfix, "%s"), from_id)

        post_thumbnail_ids = {}
        meta_thumbnails = {}
        post_thumbnails = {}

        postmeta_list = conn.query(
            "SELECT * FROM %spostmeta WHERE meta_key = '_thumbnail_id' AND post_id IN %s"
            % (wp_perfix, "%s"), tuple([int(i.ID) for i in post_list]))
        for postmeta in postmeta_list:
            post_thumbnail_ids[postmeta.post_id] = postmeta.meta_value

        postmeta_list = conn.query(
            "SELECT * FROM %spostmeta WHERE meta_key = '_wp_attached_file' AND post_id IN %s"
            % (wp_perfix, "%s"),
            tuple([int(i) for i in post_thumbnail_ids.values()]))
        for postmeta in postmeta_list:
            meta_thumbnails[postmeta.post_id] = postmeta.meta_value

        for k, v in post_thumbnail_ids.iteritems():
            post_thumbnails[k] = meta_thumbnails[long(v)]

        post_list_json = []
        color_count = 0
        for post in post_list:
            soup = BeautifulSoup(post.post_content.split("<!--more-->")[0])
            post_json = {}
            post_json["post_excerpt"] = soup.get_text()
            post_json["post_title"] = post.post_title
            post_json["post_name"] = post.post_name
            post_json[
                "thumbnail"] = "/wp-content/uploads/%s" % post_thumbnails[
                    post.ID] if post_thumbnails.get(post.ID) else None
            post_json["color"] = POST_COLORS[color_count % len(POST_COLORS)]
            color_count += 1

            post_list_json.append(post_json)

        self.finish({
            "list": post_list_json,
            "post_id_from": post_list[-1].ID if post_list else 0
        })
示例#32
0
    def get(self):
        wp_perfix = settings.get("wordpress_prefix", "wp_")

        term = self.get_argument("t", None)
        if term:
            term_record = conn.get(
                "SELECT * FROM %sterms WHERE slug = %s" % (wp_perfix, "%s"),
                term)
            term_taxonomy = conn.get(
                "SELECT * FROM %sterm_taxonomy WHERE term_id = %s" %
                (wp_perfix, "%s"), term_record["term_id"])
            object_records = conn.query(
                "SELECT * FROM %sterm_relationships WHERE term_taxonomy_id = %s ORDER BY object_id DESC LIMIT 5"
                % (wp_perfix, "%s"), term_taxonomy["term_taxonomy_id"])
            self.post_list = conn.query(
                "SELECT * FROM %sposts WHERE post_status = 'publish' AND post_type = 'post' AND ID IN %s ORDER BY ID DESC"
                % (wp_perfix, "%s"),
                tuple([i["object_id"] for i in object_records]))
            self.term = "&t=%s" % term
        else:
            self.post_list = conn.query(
                "SELECT * FROM %sposts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY ID DESC LIMIT 5"
                % wp_perfix)
            self.term = ""

        post_thumbnail_ids = {}
        meta_thumbnails = {}
        post_thumbnails = {}

        postmeta_list = conn.query(
            "SELECT * FROM %spostmeta WHERE meta_key = '_thumbnail_id' AND post_id IN %s"
            % (wp_perfix, "%s"), tuple([int(i.ID) for i in self.post_list]))
        for postmeta in postmeta_list:
            post_thumbnail_ids[postmeta.post_id] = postmeta.meta_value

        postmeta_list = conn.query(
            "SELECT * FROM %spostmeta WHERE meta_key = '_wp_attached_file' AND post_id IN %s"
            % (wp_perfix, "%s"),
            tuple([int(i) for i in post_thumbnail_ids.values()]))
        for postmeta in postmeta_list:
            meta_thumbnails[postmeta.post_id] = postmeta.meta_value

        for k, v in post_thumbnail_ids.iteritems():
            post_thumbnails[k] = meta_thumbnails[long(v)]

        self.post_id_from = self.post_list[-1].ID
        self.carousel_list = []
        carousel_count = 0
        color_count = 0
        for post in self.post_list:
            post.thumbnail = "/wp-content/uploads/%s" % post_thumbnails[
                post.ID] if post_thumbnails.get(post.ID) else None
            if post.thumbnail and carousel_count < 3:
                self.carousel_list.append(post)
                carousel_count += 1

            soup = BeautifulSoup(post.post_content.split("<!--more-->")[0])
            post.post_excerpt = soup.get_text()

            post.color = POST_COLORS[color_count % len(POST_COLORS)]
            color_count += 1

        self.render('../template/main.html')
示例#33
0
def get_user_by_login(login):
    index_login = conn.get("SELECT * FROM index_login WHERE login = %s", login)
    entity_id = index_login["entity_id"]

    return nomagic._get_entity_by_id(entity_id)
示例#34
0
def get_user_id_by_login(login):
    index_login = conn.get("SELECT * FROM index_login WHERE login = %s", login)
    return index_login["entity_id"] if index_login else None
示例#35
0
def get_user_by_email(email):
    index_login = conn.get("SELECT * FROM index_login WHERE login = %s", email)
    entity_id = index_login["entity_id"]

    return _get_entity_by_id(entity_id)