def POST(self): """ post the piece """ super(new,self).GET() from model import piece from urlparse import urlparse post = web.input(_method="post",share=[]) if self.cur_user: # get cur_user cur_user = self.cur_user # set user_id user_id = cur_user["id"] # set link if "link" in post: link = post["link"] url_parsed = urlparse(link) if not url_parsed.netloc: #相当于host link = None else: link = None # set private private = "private" in post # set content content = post["content"] if content.strip() == "": error = "内容不能为空" return render.new(error) if "pics" in post: pics = post["pics"] else: pics = None # insert piece_id = piece.add(user_id=user_id,content=content,link=link,private=private,pics=pics) # share if not private: share = post["share"] content = sliceContent(content) share_content = u"「" + content + u"」" + " http://" + web.ctx.host + "/piece/" + str(piece_id) if "weibo" in share: client = oauth.createClientWithName("weibo",cur_user) client.post(share_content) if "douban" in share: client = oauth.createClientWithName("douban",cur_user) client.post(share_content) # redirect web.redirect("/people/"+str(user_id)) else: return render.new()
def POST(self): """ post the piece """ super(new, self).GET() from model import piece from urlparse import urlparse post = web.input(_method="post", share=[]) if self.cur_user: # get cur_user cur_user = self.cur_user # set user_id user_id = cur_user["id"] # set link link = post["link"] url_parsed = urlparse(link) if not url_parsed.netloc: link = None # set private if "private" in post: private = True else: private = False # set content content = post["content"] # insert piece_id = piece.add(user_id=user_id, content=content, link=link, private=private) # share if not private: share = post["share"] share_content = u"「" + content + u"」" + " http://" + web.ctx.host + "/piece/" + str( piece_id) if "weibo" in share: client = oauth.createClientWithName("weibo", cur_user) client.post(share_content) if "douban" in share: client = oauth.createClientWithName("douban", cur_user) client.post(share_content) # redirect web.redirect("/people/" + str(user_id)) else: return render.new()
def GET(self, name): input = web.input() new_user = None cur_user = login.logged() try: client = oauth.createClientWithName(name) access_token = client.get_access_token(input["code"]) user_info = client.get_current_user_info(access_token) user_info["access_token"] = access_token if cur_user: user.update_oauth_userid(name, cur_user["id"], user_info["id"]) user.update_access_token(name, user_info["id"], access_token) if not cur_user: oauth_user = user.exist_oauth_user(name, user_info) if not oauth_user: new_user = user.new_oauth_user(name, user_info) else: user.update_access_token(name, oauth_user[name + "_id"], access_token) user.login_oauth_user(name, user_info) return blankrender.logged(True, new_user) except Exception: return blankrender.logged(True, None)
def POST(self, ctx): name = ctx["post"]["name"] access_token = ctx["post"]["access_token"] ret_user = None client_token = None cur_user = login.logged() client = oauth.createClientWithName(name) user_info = client.get_current_user_info(access_token) user_info["access_token"] = access_token if cur_user: print cur_user user.update_oauth_userid(name, cur_user["id"], user_info["id"]) user.update_access_token(name, user_info["id"], access_token) if not cur_user: print "not cur_user" oauth_user = user.exist_oauth_user(name, user_info) if not oauth_user: ret_user = user.new_oauth_user(name, user_info) else: ret_user = oauth_user user.update_access_token(name, oauth_user[name + "_id"], access_token) client_token = user.login_oauth_user(name, user_info) ret_user["client_hash"] = client_token return ret_user
def GET(self,name): input = web.input() new_user = None cur_user = login.logged() try: client = oauth.createClientWithName(name) access_token = client.get_access_token(input["code"]) user_info = client.get_current_user_info(access_token) user_info["access_token"] = access_token if cur_user: user.update_oauth_userid(name,cur_user["id"],user_info["id"]) user.update_access_token(name,user_info["id"],access_token) if not cur_user: oauth_user = user.exist_oauth_user(name,user_info) if not oauth_user: new_user = user.new_oauth_user(name,user_info) else: user.update_access_token(name,oauth_user[name+"_id"],access_token) user.login_oauth_user(name,user_info) return blankrender.logged(True,new_user) except Exception: return blankrender.logged(True,None)
def GET(self, name): try: client = oauth.createClientWithName(name) url = client.redirect() web.seeother(url) except Exception: return traceback.format_exc()
def POST(self,ctx): """ add one """ content = ctx["post"]["content"] userid = ctx["user"]["id"] if "link" in ctx["post"]: link = ctx["post"]["link"] else: link = None pieces = db.select("piece",where="content=$content",vars={"content":content}) # 检查是否已有相同内容 if not pieces: pieceid = db.insert("piece",content=content,user=userid,addtime=datetime.now(),link=link) else: pieceid = pieces[0]["id"] share = [] if "share" in ctx["post"]: share = ctx["post"]["share"].split(",") for key in share: if not key: continue client = oauth.createClientWithName(key,ctx["user"]) post_content = u"「" + content + u"」" + " http://" + web.ctx.host + "/piece/" + str(pieceid) client.post(post_content) favpiece(pieceid,userid) return {"id":int(pieceid)}
def POST(self,ctx): name = ctx["post"]["name"] access_token = ctx["post"]["access_token"] ret_user = None client_token = None cur_user = login.logged() client = oauth.createClientWithName(name) user_info = client.get_current_user_info(access_token) user_info["access_token"] = access_token if cur_user: ret_user = cur_user user.update_oauth_userid(name,cur_user["id"],user_info["id"]) user.update_access_token(name,user_info["id"],access_token) if not cur_user: oauth_user = user.exist_oauth_user(name,user_info) if not oauth_user: ret_user = user.new_oauth_user(name,user_info) else: ret_user = oauth_user user.update_access_token(name,oauth_user[name+"_id"],access_token) client_token = user.login_oauth_user(name,user_info) ret_user["client_hash"] = client_token return ret_user
def GET(self,name): try: client = oauth.createClientWithName(name) url = client.redirect() web.seeother(url) except Exception: return traceback.format_exc()
def GET(self,name): try: client = oauth.createClientWithName(name) url = client.redirect() web.seeother(url) except Exception,e: print e return e
def GET(self,name): input = web.input() action = "action" in input and input["action"] or "login" try: client = oauth.createClientWithName(name) url = client.redirect() web.seeother(url) except Exception,e: return e
def GET(self, name): input = web.input() action = "action" in input and input["action"] or "login" try: client = oauth.createClientWithName(name) url = client.redirect() web.seeother(url) except Exception, e: return e