示例#1
0
文件: page.py 项目: ergatea/gitpub2
    def post(self):
        mid = self.get_argument("mid")
        do = self.get_argument("do")
        coll = self.get_argument("coll")
        # Get collection class by name
        coll_class = eval(coll.capitalize())
        try:
            coll_obj = coll_class.getObjectByObjectId(mid)
        except:
            coll_obj = None

        if coll_obj:

            if do == "add":
                Member.addToCollections(self.current_user, coll_obj)
                coll_class.addToCollectors(coll_obj, self.current_user)
                _do = "remove"
                label = self._t("remove collection")
                self.finishedMsg(status="success", info="Add from collection success", do=_do, label=label)
            elif do == "remove":
                Member.removeFromCollections(self.current_user, coll_obj)
                coll_class.removeFromCollectors(coll_obj, self.current_user)
                _do = "add"
                label = self._t("add collection")
                self.finishedMsg(status="success", info="Remove to collection success", do=_do, label=label)
            else:
                self.finishedMsg(status="error", info="Action not found")
            

        else:
            self.finishedMsg(status="error", info="Collection object not found")
示例#2
0
文件: page.py 项目: ergatea/gitpub2
 def post(self):
     mid = self.get_argument("mid")
     do = self.get_argument("do")
     member = Member.getObjectByObjectId(mid)
     if do == "accept":
         Member.accpetFriendRequest(self.current_user, member)
         _do = "suspend"
         label = self._t("Accept friend request")
     elif do == "refuse":
         Member.refuseFriendRequest(self.current_user, member)
         _do = "refuse"
         label = None
     else:
         self.finishedMsg(status="error", info="Action not found")
     self.finishedMsg(status="success", info="execute friends operation", do=_do, label=label)
示例#3
0
 def get(self):
     to = self.get_argument("to")
     receiver = Member.getObjectByObjectId(to)
     if receiver:
         self.render('accounts/messaging_form.html', member=receiver)
     else:
         self.write_error(500)
示例#4
0
文件: page.py 项目: ergatea/gitpub2
 def post(self):
     screen_name = self.get_argument("screen_name", '')
     intro = self.get_argument("intro", '')
     port = self.get_argument("port", None)
     access_token = self.profiles.weibo_access_token
     if not access_token:
         raise HTTPError(500, "Weibo access_token not found")
     
     if 0<len(screen_name)<72 and 0<len(intro)<192:
         if port == "weibo":
             request_url = self._OAUTH_USER_INFO_URL + "?" + urlencode({"access_token":access_token, "screen_name":screen_name.encode("utf-8")})
             http_client = AsyncHTTPClient()
             http_client.fetch(request_url, callback=(yield gen.Callback("resp")))
             response = yield gen.Wait("resp")
             if response.code == 200:
                 content = json.loads(response.body)
                 username = "******" %(content.get("screen_name"), port)
                 member = Member.getMemberByOAuth2ID(str(content.get("id")), port)
                 if member:
                     member.has_fetcher = "suspend"
                     member.task_intro = intro
                     member.save()
                 else:
                     member = Member.create(
                         username=username, 
                         nickname=content.get("screen_name"),
                         port=port,
                         oauth_id=str(content.get("id")),
                         has_fetcher="suspend",
                         task_intro=intro,
                         oauth_info={
                             "description": content.get("description").encode("utf-8"),
                             "province": content.get("province"),
                             "city": content.get("city"),
                             "location": content.get("location"),
                             "profile_image_url": content.get("profile_image_url"),            
                         },
                         created=datetime.now(),
                         modified=datetime.now()
                     )
                 self.finishedMsg(status="success", info="submit success")
             else:
                 self.finishedMsg(status="error", info="could not connect to weibo api")
         else:
             self.finishedMsg(status="error", info="others ports not supported")
     else:
         self.finishedMsg(start="error", info="argument error")
示例#5
0
def fetch_weibo_timeline(username):
    print "[%s]: single started" %formatDatetime(datetime.now())
    access_token = Settings.settings().weibo_access_token
    if access_token:
        member = Member.getMemberByUsername(username)
        if member:
            if member.port == "weibo":
                content = weibo_api_request(weibo_user_timeline_url, "GET", access_token, uid=member.oauth_id)
                if content:
                    save_weibo_content(member, content)
    print "[%s]: single finished" %formatDatetime(datetime.now())
示例#6
0
文件: page.py 项目: ergatea/gitpub2
 def post(self):
     mid = self.get_argument("mid")
     do = self.get_argument("do")
     member = Member.getObjectByObjectId(mid)
     if do == "add":
         Member.appendToFocusing(self.current_user, member)
         Member.appendToFocused(member, self.current_user)
         _do = "remove"
         label = self._t("Remove focusing")
     elif do == "remove":
         Member.removeFromFocusing(self.current_user, member)
         Member.removeFromFocused(member, self.current_user)
         _do = "add"
         label = self._t("Add focusing")
     else:
         self.finishedMsg(status="error", info="Action not found")
     self.finishedMsg(status="success", info="Add to focusing success", do=_do, label=label)
示例#7
0
def fetch_weibo_timelines():
    print "[%s]: schedule tasks started" %formatDatetime(datetime.now())
    access_token = Settings.settings().weibo_access_token

    if access_token:
        members = Member.get_enabled_tasks()
        for member in members:
            if member.port == "weibo":
                content = weibo_api_request(weibo_user_timeline_url, "GET", access_token, uid=member.oauth_id)
                if content:
                    save_weibo_content(member, content)
    print "[%s]: schedule tasks finished" %formatDatetime(datetime.now())
示例#8
0
    def _on_auth(self, user):
        next = self.get_argument("next", self.prefix_url)
        if not user:
            raise HTTPError(500, "Weibo auth failed")
        else:
            user['oauth_info'].update(description=striping(user['oauth_info']['description'], 0, 35))
            member = Member.getObject(oauth_id=user["oauth_id"], port="weibo")
            if member:
                member.access_token = user["access_token"]
                member.oauth_info.update(user["oauth_info"])
                member.save()                
            else:
                user.update(created=datetime.now())
                user.update(modified=datetime.now())
                member = Member.create(**user)

            self.session["logined"] = True
            self.session["mid"] = member.mid
            self.session.save()
            cookie_string = self.dumpsJson(logined=True, mid=member.mid)
            self.set_secure_cookie(self.cookie_name, cookie_string)
            self.redirect(next)
示例#9
0
    def post(self):
        data = self.request.body
        form_data = json.loads(data)
        regist_id = form_data["regist_id"]
        regist_dict = self.mc.get(str(regist_id))

        if regist_dict:
            email       = regist_dict["email"]
            username    = form_data["username"]
            password    = form_data["password"]
            repeat      = form_data["repeat"]

            if password==repeat:
                is_existed = Member.getMemberByEmailAndUsername(email, username)
                if is_existed:
                    self.finishedMsg(status="error", info="email or username existed")
                else:                    
                    if (time.time() - regist_dict["timestamp"]) < 300:
                        is_saved = Member.create(
                            email       = email,
                            username    = username,
                            password    = getSha1(password),
                            created     = datetime.now(),
                            modified    = datetime.now(),
                            is_enabled  = True
                        )
                        if is_saved:
                            del self.mc[regist_id]                       
                            self.finishedMsg(status="success", info="regist success")
                        else:
                            self.finishedMsg(status="error", info="error when save record")
                    else:
                        self.finishedMsg(status="error", info="regist code expired")
            else:
                self.finishedMsg(status="error", info="password not matched")
        else:
            self.finishedMsg(status="error", info="regist_id not found")
示例#10
0
文件: admin.py 项目: ergatea/gitpub2
 def post(self):
     data = json.loads(self.request.body)
     member = Member.getObjectByObjectId(data["data-id"])
     if member:
         member.has_fetcher = data["status"]
         member.save()
         member.reload()
         if member.has_fetcher == "enabled":
             import socket  
             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
             sock.connect(("127.0.0.1", 5000))  
             print "Send start fetch weibo task"
             sock.send(json.dumps({'task':'single', 'port':'weibo', 'operation':'start', 'username':member.username}))
             sock.close()
         self.finishedMsg(status="success", info="change job to %s" %data["status"])
     else:
         self.finishedMsg(status="error", info="object not found")
示例#11
0
    def post(self):
        receiver_id = self.get_argument("receiver_id")
        title = self.get_argument("title")
        content = self.get_argument("content")

        receiver = Member.getObjectByObjectId(receiver_id)

        messaging = self.current_user.send_messaging(
            receiver,
            title=title,
            content=content,
            created=datetime.now()
        )

        self.finishedMsg(
            status="success", 
            info="send message successful", 
            next="%s/accounts/messaging/view/%s" %(self.prefix_url, messaging.mid))
示例#12
0
    def post(self):
        username = self.get_argument("username", None)
        password = self.get_argument("password", None)
        if username and password:
            password = getSha1(password)
            member = Member.getMemberByUsernameAndPassword(username, password)
            if member:                
                self.session["logined"] = True
                self.session["mid"] = member.mid
                self.session.save()
                cookie_string = self.dumpsJson(logined=True, mid=member.mid)
                self.set_secure_cookie(self.cookie_name, cookie_string)
                self.redirect("/")
            else:
                self.finish(json.dumps({"status":"error", "info":"member not found"}))

        else:
            self.finish(json.dumps({"status":"error", "info":"arguments not matched"}))
示例#13
0
 def post(self):
     data = json.loads(self.request.body)
     email = str(data.get("email", ""))
     code = str(data.get("code",""))
     rands_str = self.session.get("regist_verify")
     if matched("email", email) and matched("verify", code):
         if code == rands_str:
             is_existed = Member.getMemberByEmail(email)
             if is_existed:
                 self.finishedMsg(status="error", info="email already existed")
             else:
                 regist_id = getSha1(str(uuid.uuid4()))
                 regist_dict = {"email":email, "timestamp": time.time()}
                 self.mc.set(regist_id, regist_dict, time=1200)
                 regist_url = "%s/accounts/regist_with_code?code=%s" %(self.prefix_url, regist_id)
                 body = {
                     "from": "Administrator <*****@*****.**>",
                     "to": email,
                     "subject": "REGISTRATION",
                     "text": regist_url
                 }                    
                 mail_request = HTTPRequest(
                     url=mailgun_url, 
                     method="POST",
                     auth_username=mailgun_username,
                     auth_password=mailgun_password,
                     body=urlencode(body))
                 http_client = AsyncHTTPClient()
                 http_client.fetch(mail_request, callback=(yield gen.Callback("resp")))
                 response = yield gen.Wait("resp")
                 logging.info(response.body)
                 self.session["regist_verify"] = None
                 self.session.save()
                 if response.code == 200:
                     self.finishedMsg(status="success", info="mail had queued")
                 else:
                     self.finishedMsg(status="error", info="send mail fails")
         else:
             self.finishedMsg(status="error", info="verify not matched")
     else:
         self.finishedMsg(status="error", info="email or verify code not valid")
示例#14
0
    def post(self, prev_id):
        receiver_id = self.get_argument("receiver_id")
        title = self.get_argument("title")
        content = self.get_argument("content")

        receiver = Member.getObjectByObjectId(receiver_id)
        previous_messaging = Messaging.getObjectByObjectId(prev_id)

        if receiver and previous_messaging:
            messaging = self.current_user.send_messaging(
                receiver,
                title=title,
                content=content,
                previous=previous_messaging,
                created=datetime.now()
            )
            self.finishedMsg(
                status="success", 
                info="send message successful", 
                next="%s/accounts/messaging/view/%s" %(self.prefix_url, messaging.mid))
        else:
            self.finishedMsg(status="error", info="reply message error")   
示例#15
0
文件: page.py 项目: ergatea/gitpub2
 def get(self, mid):
     member = Member.getObjectByObjectId(mid)
     if member:
         self.render("page/profile.html", member=member)
     else:
         raise HTTPError(404, "member not found")
示例#16
0
文件: admin.py 项目: ergatea/gitpub2
 def get(self):
     member_tasks = Member.objects(
         Q(has_fetcher="enabled")|Q(has_fetcher="suspend")).order_by("-created")
     self.render("admin/jobs.html", member_tasks=member_tasks)
示例#17
0
def get_random_member():
    members_list = Member.objects(access_token__ne=None)
    members_list = [member for member in members_list if member.port == "weibo"]
    random.shuffle(members_list)
    return random.choice(members_list)