Exemplo n.º 1
0
 def GET(self,provider):
   if provider!="sina":
     return "todo"      
   code=web.input().get("code")
   client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
   r = client.request_access_token(code)
   access_token = r.access_token
   expires_in = r.expires_in
   client.set_access_token(access_token, expires_in)
   uid =r.uid
   weibouser=client.get.users__show(uid=uid)
   sinaid=weibouser.get("id")
   authbind=Auth_bind.objects(opid="sina"+str(sinaid)).first()
   if authbind==None:
     avatar_large=weibouser.get("avatar_large")
     avatar=weibouser.get("profile_image_url")
     username=weibouser.get("screen_name")
     username=username+"21223"
     #??????          I
     ID=User.objects.count() + 101
     u=User(username=username,email="!!sina2"+str(sinaid),password="",ID=ID)
     u.avatar=avatar
     u.avatar_big=avatar_large
     u.save()
     a=Auth_bind(ID=ID,opid="sina"+str(sinaid),access_token=access_token,expires_in=str(expires_in))
     a.save()
     Auth.set_login(u.id,username.encode("utf-8"))
     return  web.seeother("/")
   else:
      ID=authbind.ID
      user=User.objects(ID=ID).first()
      Auth.set_login(user.id,user.username.encode("utf-8"))
      return web.seeother("/")
Exemplo n.º 2
0
 def POST(self):
    email=web.input().get("email")
    name=web.input().get("nickname")
    passwd=web.input().get("password")
    if not( email and name and passwd):
          content= u"输入不能为空"
          return render.signup(is_login=False,content=content)  
    if  User.objects(email=email).first() :
          content= u"邮箱已经注册"
          return render.signup(is_login=False,content=content) 
    if   User.objects(username=name).first() :
          content =u"用户名已经被注册"
          return render.signup(is_login=False,content=content) 
    ID=User.objects.count() + 101
    user = User(username=name,email=email,password=passwd,ID=User.objects.count() + 101)
    user.avatar="default.png"
    user.avatar_big="default_big.png"
    #方便管理,只有一级目录
    user.save()
    if user : 
       Auth.set_login(user.id,name.encode("utf-8"))
       return web.seeother("/")
    else:
          content =u"用户名已经被注册"
          return render.signup(is_login=False,content=content)
Exemplo n.º 3
0
 def GET(self,id):
    page=int(web.input().get('page','1'))
    item=Node.objects(ID=int(id)).first()
    #todo 分页 or ajax
    comments=Tweet.objects(Q(SubjectID=int(id))&Q(flag__ne=1)).order_by("-ID") 
    #flag=1 means share 
    next=None
    if Auth.is_login():
         user=User.objects(id=Auth.uid()).first()
         mycollect=user.nodes_follow
         if item.ID in mycollect:
            collected=True
         else:
           collected=False
    else:
         user=None
         collected=False
    if item and  item.creatorID:
        creator=User.objects(ID=item.creatorID).first()
    else:
        creator =None
    datalist=[]
    for comment in comments:
       datalist.append((User.objects(ID=comment.AutherID).first(),comment))
    if user==creator :
            editble=True
    else:
           editble=False
    if  user and ( user.email=="*****@*****.**" or user.email=="*****@*****.**"  ):
            editble=True
    return render.item(editble=editble,user=user,creator=creator,item=item,datalist=datalist,collected=collected)
Exemplo n.º 4
0
 def GET(self):
   if Auth.is_login():
      user=User.objects(id=Auth.uid()).first()
   else:
      user=None
   nodes=Node.objects(score=20).order_by("-ID")
   if nodes.count()>20:
        nodes=nodes[0:20]
   return render.index(user=user,nodes=nodes)           
Exemplo n.º 5
0
 def POST(self):
      email=web.input().get("email")
      passwd=web.input().get("password")
      key=passwd
      #key=hashlib.md5(passwd).hexdigest()
      user = User.objects(email=email).first()
      if not user :
          return render.login(is_login=Auth.is_login(),content=u"没有这个用户")
      if user.password==key:
          Auth.set_login(user.id,user.username)
          return web.seeother("/")
      return render.login(is_login=Auth.is_login(),content=u"密码错误")
Exemplo n.º 6
0
 def GET(self,uid): 
   if Auth.is_login():
       user=User.objects(id=Auth.uid()).first()
   else:
       user=None
   thisguy=User.objects(ID=uid).first()    
   datalist=[]    
   shares=Share_items.objects(creatorID=int(uid))
   counts=(0,0,0)
   for p in shares:
          datalist.append(("share" ,Node.objects(ID=p.itemID).first(),p, friendly_time(p.created).decode("utf-8")))
   return render.share_items(user=user,thisguy=thisguy,datalist=datalist,counts=counts)
Exemplo n.º 7
0
 def GET(self,uid):
     #关注我的人 should keep it in  a list ?
     if Auth.is_login():
             me=User.objects(id=Auth.uid()).first()
     else:
            me=None
     user=User.objects(ID=int(uid)).first()
     followeds=User.objects(followings=user.ID)
     page=int(web.input().get("page","1"))
     count=user.followed_count
     if page*10<count:
        next=page+1
     else:
        next=None      
     return render.followeds(user=me,thisguy=user,count=count,next=next,followeds=followeds)
Exemplo n.º 8
0
 def GET(self,userID):
   thisguy=User.objects(ID=userID).first()
   c= thisguy.nodes_follow
   if not  c:
     collections=[]
   else:
      collections=[]
      #取最新的收藏
      for _id in c:
        collections.append(Node.objects(ID=_id).first())
   if Auth.is_login():
          me=User.objects(id=Auth.uid()).first()
   else:
         me=None
   counts = thisguy.followings_count,thisguy.followed_count,thisguy.tweet_count      
   return render.usercollections(user=me,thisguy=thisguy, collections=collections, counts =counts)
Exemplo n.º 9
0
 def POST(self):
        uid=Auth.uid()
        user=User.objects(id=uid).first()
        _file= web.input(avatar={})
        if _file['avatar'].filename!="" and  _file['avatar'].filename[-3:]=="jpg":
              fileimg=_file['avatar'].value 
              _filename=TEMP+"/"+str(user.ID)+".jpg"
              open(_filename,"wb").write(fileimg)
              im = Image.open(_filename)
              (width,height)=im.size
              if width<=height:
                im_new=im.resize((100,int(height*100.0/width)),Image.ANTIALIAS)
                im_new.transform((100,100),Image.EXTENT ,(0,0,100,100),Image.BILINEAR).save('m'+uid+".jpg",quality = 95)
                im_new.transform((50,50),Image.EXTENT,(0,0,100,100)).save(STATIC_FILE+'/s'+uid+".jpg",quality = 95)
                im_new.save(STATIC_FILE+'/b'+uid+".jpg",quality = 95)   
              else:    
                im_new=im.resize((int(width*100.0/height),100))
                im_new.transform((100,100),Image.EXTENT,(0,0,100,100),Image.BILINEAR).save('m'+uid+".jpg",quality = 95)
                im_new.transform((50,50),Image.EXTENT,(0,0,100,100)).save(STATIC_FILE+'/s'+uid+".jpg",quality = 95)
                im_new.save(STATIC_FILE+'/b'+uid+".jpg",quality = 95)
              user.avatar="s"+uid+".jpg"
              user.avatar_big="b"+uid+".jpg"                          
              user.save()
        else:
            render.profile_avatar(is_login=True,user=user,content=u"请上传JPG文件")      
        return  render.profile_avatar(is_login=True,user=user,content=u"更新头像成功")
Exemplo n.º 10
0
 def GET(self,uid):
     #关注的人
     if Auth.is_login():
            me=User.objects(id=Auth.uid()).first()
     else:
            me=None
     user=User.objects(ID=int(uid)).first()
     followings_ids=user.followings
     followings=[User.objects(ID=idd).first() for idd in followings_ids] 
     page=int(web.input().get("page","1"))
     count=user.followings_count
     if page*10<count:
        next=page+1
     else:
        next=None      
     return  render.followings(user=me,thisguy=user,count=count,next=next,followings=followings)
Exemplo n.º 11
0
  def GET(self,uid):
      myuid=Auth.uid()
      page=int(web.input().get("page","1")) 
      thisguy=User.objects(ID=int(uid)).first()
      if not thisguy:
          return  render.notfound()
      thisguy.tweet_count=Tweet.objects(AutherID=thisguy.ID).count()
      counts = thisguy.followings_count,thisguy.followed_count,thisguy.tweet_count
      
      #update count
      if page*20<counts[2]:
         next=page+1
      elif page*20-counts[2]>20 :
         return  web.notfound()
      else:  
         next=None

      if Auth.is_login():
          me=User.objects(id=Auth.uid()).first()
      else:
          me=None
          
      if not me:
           relation=None
      elif me==thisguy:
          relation="self"
      elif thisguy.ID in me.followings:
           relation="ifollowhim"
      else:
           relation=None
      # do i follow that people?
      datalist=[]
      posts=Tweet.objects(AutherID=thisguy.ID).order_by("-ID")[(page-1)*20:page*20]
  
      for p in posts:
          if p.SubjectID>0:
              if p.flag==1:
                 datalist.append(("share" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))
              elif p.flag==-1:
                  pass   
              else:   
                 datalist.append(("comment" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))
          elif p.flag==-1:
                  pass
          else: 
                datalist.append(("say",p,friendly_time(p.created).decode("utf-8")))  
      return  render.user(user=me,thisguy=thisguy,counts=counts,next=next,datalist=datalist,relation=relation)
Exemplo n.º 12
0
 def POST(self):
        uid=Auth.uid()
        passwd=web.input().get("password")
        passwd1=web.input().get("password1")
        user=User.objects(id=uid).first()
        if passwd and (passwd!=passwd1):
            return render.profile_password(is_login=True,user=user,content=u"两次密码不同,请再次输入")
        return  render.profile_password(is_login=True,user=user,content=u"更新密码成功")
Exemplo n.º 13
0
 def POST(self):
        uid=Auth.uid()
        intro=web.input().get("intro")
        user=User.objects(id=uid).first()
        if intro!=user.intro:
            user.intro=intro                      
        user.save()    
        return  render.profile(is_login=True,user=user,content=u"更新信息成功")
Exemplo n.º 14
0
 def GET(self):
     user=User.objects(id=Auth.uid()).first()  
     if web.input().get("count",None):             
          count=web.input().get("count",None)
          piclist=[]
          for i in range(int(count)):
               piclist.append(web.input().get("u"+str(i)))
          title=web.input().get("title")
          #print title
          url=web.input().get("fromurl")
          store=get_store(url).decode("utf-8")
          des=web.input().get("d",None)
          return render.share_bm(user=user,piclist=piclist,store=store,title=title,url=url,des=des)
     return render.share(is_login=True,user=user)
Exemplo n.º 15
0
 def POST(self):
     user=User.objects(id=Auth.uid()).first()
     if user.role!=2:
         return "blocked"
     content=web.input().get('txt')
     typet=web.input().get('type')
     subtopID=int(web.input().get('stID','0'))
     if not content:
        return "Content_empty"
     if typet=="post":
         tweet=Tweet(ID=Tweet.objects.count()+101,AutherID=user.ID,SubjectID=subtopID,content=content)
         user.tweet_count+=1
         tweet.save()
         user.save()
     return "Success"
Exemplo n.º 16
0
 def POST(self):
   unfoid=web.input().get("unfollow")
   thisguy=User.objects(ID=int(unfoid)).first()
   user=User.objects(id=Auth.uid()).first()
   followings=user.followings
   _id=int(unfoid)
   if _id in followings:
      followings.remove(_id)
      user.followings=followings
      user.followings_count-=1
      thisguy.followed_count-=1
      user.save()
      thisguy.save()
      return "Unfollow_success"
   return "cant unfollow"
Exemplo n.º 17
0
 def  POST(self):
      user=User.objects(id=Auth.uid()).first()
      itemid=web.input().get("itemid")
      # print itemid
      #数据结构为 item,收藏此item的ID
      c=Collect.objects(ID=int(itemid))
      if len(c)!=0:
          c.update_one(push__userlist=user.ID)
          user.update(push__nodes_follow=int(itemid))
          user.save()
          c.first().save()
      else:
         c=Collect(ID=user.ID,userlist=[itemid])
         user.update(push__nodes_follow=int(itemid))
         user.save()
         c.save()
      return None
Exemplo n.º 18
0
 def POST(self):
   myuid=Auth.uid()
   foid=web.input().get("follow")
   if myuid==str(User.objects(ID=foid).first().id):
       return "not_allowed"
   print str(myuid)==str(User.objects(ID=foid).first().id)
   user=User.objects(id=myuid).first()
   thisguy=User.objects(ID=int(foid)).first()
   if thisguy.ID not in user.followings:
       ids=user.followings
       ids.append(thisguy.ID)
       user.ids=ids
       user.followings_count+=1
       thisguy.followed_count+=1
       user.save()
       thisguy.save()
       return "success"
   return "failed"
Exemplo n.º 19
0
 def POST(self):   
     
     name=web.input().get("name")
     _tags=web.input().get("tags")
     source=web.input().get("source")                 
     if _tags:
          tags=[x for x in  _tags.split(",")]
     else:
          tags=[]
     user=User.objects(id=Auth.uid()).first()     
     creatorID=user.ID     
     intro=web.input().get("intro")
     picurl=web.input().get("picurl",None)
     price=web.input().get("price")
     link=web.input().get("source")
     store=get_store("store")
     price=web.input().get("price")
     buyinfo=Buy_info(link=link,store=store,price=price)
     #check if none 
     pic=urllib2.urlopen(picurl).read()
     ID=Node.objects.count()+1
     open(str(ID)+".jpg","wb").write(pic)
     u = UpYun(BUCKETNAME,USER,PASSWORD)
     data = open(str(ID)+".jpg",'rb')
     u.setContentMD5(md5file(data))
     a = u.writeFile('/o'+str(ID)+'.jpg',data)
     if not a:
       return "get picture erro"
     #cut_item_picture(STATIC_FILE,ID,str(ID)+".jpg")  
     node=Node(creatorID=creatorID,ID=ID,name=name,des=intro,picurl=picurl,tags=tags,buy_info=[buyinfo])
     node.picinfo=101    #a out sidelink
     node.save()
     share=Share_items(ID=Share_items.objects.count()+1,creatorID=user.ID,itemID=ID,flag=1,content="")
     share.save()
     #加入到shareitem中
     #todo count更新
     tweet=Tweet(ID=Tweet.objects.count()+1,AutherID=user.ID,SubjectID=ID,flag=1,content=str(ID))
     tweet.save()
     return web.seeother("/item/"+str(ID)+"/")
Exemplo n.º 20
0
 def POST(self):
          picurl=web.input().get("check")
          name=web.input().get("name")
          _tags=web.input().get("tags")
          source=web.input().get("source")                 
          if _tags:
            tags=[x for x in  _tags.split(",")]
          else:
            tags=[]
          user=User.objects(id=Auth.uid()).first()     
          creatorID=user.ID     
          intro=web.input().get("intro")
          price=web.input().get("price")
          link=web.input().get("source")
          store=web.input().get("store")
          #store=get_store(link).decode("utf-8")
          price=web.input().get("price")
          buyinfo=Buy_info(link=link,store=store,price=price)
          pic=urllib2.urlopen(picurl).read()
          ID=Node.objects.count()+1
          open(str(ID)+".jpg","wb").write(pic)
          u = UpYun(BUCKETNAME,USER,PASSWORD)
          data = open(str(ID)+".jpg",'rb')
          u.setContentMD5(md5file(data))
          a = u.writeFile('/o'+str(ID)+'.jpg',data)
          if not a:
              return "get picture erro"
          #cut_item_picture(STATIC_FILE,ID,str(ID)+".jpg")  
          node=Node(creatorID=creatorID,ID=ID,name=name,des=intro,picurl=picurl,tags=tags,buy_info=[buyinfo])
          node.picinfo=101    #a out sidelink
          node.save()
          share=Share_items(ID=Share_items.objects.count()+1,creatorID=user.ID,itemID=ID,flag=1,content="")
          share.save()
          content=u'''<h1>发布成功</h1><p>你可以<a href="/item/%s/">去看看</a>或者
          <a href="%s">回到刚才的逛的</a>'''%(str(ID),source)
          return render.info(content=content)
          return web.seeother("/item/"+str(ID)+"/")
Exemplo n.º 21
0
  def GET(self):
      page=int(web.input().get("page","1")) 
      me=User.objects(id=Auth.uid()).first()
      #todo ..
      me.tweet_count=Tweet.objects(AutherID=me.ID).count()
      counts = me.followings_count,me.followed_count,me.tweet_count
      c= me.nodes_follow
      if not  c:
         collections=[]
      else:
          collections=[]
          #取最新的收藏
          for _id in c:
            collections.append(Node.objects(ID=_id).first())
      if len(collections)>6:
         collections=collections[0:6]
      print counts[2]   
      if page*20<counts[2]:
         next=page+1
      elif page*20-counts[2]>20 :
         return  web.notfound()
      else:  
         next=None
      datalist=[]
      posts=Tweet.objects(AutherID=me.ID).order_by("-ID")[(page-1)*20:page*20]

      for p in posts:
          if p.SubjectID>0:
              if p.flag==1:
                   datalist.append(("share" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))  
              else:
                  datalist.append(("comment" ,Node.objects(ID=p.SubjectID).first(),p, friendly_time(p.created).decode("utf-8")))
          else:
              datalist.append(("say",p,friendly_time(p.created).decode("utf-8")))
              
      return render.home(datalist=datalist,user=me,counts=counts,next=next,collections=collections)
Exemplo n.º 22
0
 def GET(self):
     return render.login(is_login=Auth.is_login())
Exemplo n.º 23
0
 def GET(self):
     return render.signup(is_login=Auth.is_login(),content=None) 
Exemplo n.º 24
0
 def GET(self):
        uid=Auth.uid()
        user=User.objects(id=uid).first()
        
        return render.profile_avatar(is_login=True,user=user)
Exemplo n.º 25
0
 def GET(self):
     Auth.set_logout()
     return render.logout(is_login=False)
Exemplo n.º 26
0
 def GET(self):
   return render.tools(is_login=Auth.is_login(),user=None)
Exemplo n.º 27
0
 def _check_auth(*args,**kwargs):
     if Auth.is_login():
       return handler(*args,**kwargs)
     else:
       web.seeother("/login")
Exemplo n.º 28
0
 def GET(self):
   return render.about(is_login=Auth.is_login(),user=None)