Example #1
0
def run(argv):
    channel = argv[0]
    try:
        fn = 'cmd/push_'+channel+'.txt'
        f = open(fn, 'r')
    except Exception:
        print 'open file %s error'%fn
        return False
    print 'start'
    if channel == 'user':
        u = User()
        while(True):
            line=f.readline()
            if not line:
                break
            n, e, p= line.split('\t')
            r = u.register(n.decode('utf-8'), password=unicode(p.strip()), email=unicode(e))
            print r
    elif channel[:3] == 'tag':
        t = Tag()
        while(True):
            line=f.readline()
            if not line:
                break
            h, d, c = line.split(',')
            c = c.replace('\r\n', '').replace('\n', '').replace('\r', '').decode('utf-8')
            r = t._api.add(SITE_ID, c, relation_l=['place'])
            print r
    else:
        pass
    f.close()
    print 'finish!!!'
    return True
Example #2
0
 def get(self):
     uid = self.SESSION['uid']
     d = {}
     u = User()
     u.whois('_id', uid)
     if u.nick:d['sina_access_token'] = u.sina_access_token
     self.render('profile/setting_thirdpart.html', **d)
Example #3
0
 def post(self):
     a = self.get_argument('act', None)
     extra = self.get_argument('extra', None)
     n = self.get_argument('nick', None)
     if n is None:return self.render('profile/thirdpart.html', **{'warning': '请先报上名号', 'nick': n, 'extra': extra})
     p = self.get_argument('password', None)
     if p is None:return self.render('profile/thirdpart.html', **{'warning': '您接头暗号是?', 'nick': n, 'extra': extra})
     if extra: extra=eval(extra)
     u = User()
     if a == 'reg':
         e= self.get_argument('email', None)
         if e is None:return self.render('profile/thirdpart.html', **{'warning': '设置邮箱,可能帮您找回失散多年的密码', 'nick': n, 'extra': extra})
         r = u.register(n, e, p)
         if r[0]:
             self.set_secure_cookie("user", n, 1)
             uid = r[1]
             self.SESSION['uid']=uid
             if extra.has_key('photo'):self.save_avatar(extra['photo'])
             if extra.has_key('qqid'):u._api.edit(uid, qqid=extra['qqid'])
             if extra.has_key('sinaid'):u._api.edit(uid, sinaid=extra['sinaid'])
             if extra.has_key('sina_access_token'):u._api.edit(uid, sina_access_token=extra['sina_access_token'])
             self.redirect('/account/profile')
         else:
             return self.render('profile/thirdpart.html', **{'warning': r[1], 'nick': n, 'extra': extra})
     elif a == 'bind':
         pass
     else:
         return self.render('profile/thirdpart.html', **{'warning': '系统晕了,不知道您是绑定还是注册!', 'nick': n, 'extra': extra})
Example #4
0
 def post(self):
     mail = self.get_argument('mail')
     u = User()
     r = u.invite(mail)
     if r[0]:
         return self.render_alert(u"发送成功")
     else:
         return self.render('index.html', **{'warning': '邀请邮件发送失败'})
Example #5
0
 def get(self):
     return self.render('profile/register.html')
     icode = self.get_argument('icode', None)
     u = User()
     r = u.is_invited(icode)
     if r:
         return self.render('profile/register.html', email=r)
     else:
         return self.render_alert(u"邀请不可用")
Example #6
0
 def post(self):
     uid = self.SESSION['uid']
     she = self.get_argument('she', None)
     if she:
         u = User()
         u.whois('_id', she)
         nick = u.nick
     p = Permission()
     r = p._api.award(she, u'site', 'VERIFIER', nick=nick)
     return self.redirect("/check/")
Example #7
0
 def is_authed(self, key, value):
     u = User()
     u.whois(key, value)
     if u.uid is None:
         return False
     else:
         self.SESSION['uid']=u._id
         self.SESSION['nick']=u.nick
         self.render('ajax/runjs.html', uid=u._id)
         return True
Example #8
0
 def get(self):
     uid = self.SESSION['uid']
     d = {}
     for n in self.KEYS:d[n] = None
     u = User()
     u.whois('_id', uid)
     if u.nick:d['nick'] = u.nick
     if u.domain:d['domain'] = u.domain
     if u.added.get('avanta', None):d['avanta'] = u.added['avanta']
     if u.live:d['live'] = u.live
     if u.email:d['mail'] = u.email
     if u.added.get('phone', None):d['phone'] = u.added['phone']
     self.render('profile/setting.html', **d)
Example #9
0
 def add_user(self, **extra):
     u = User()
     n = extra.pop('nick')
     if u._api.is_nick_exist(n):return self.render('profile/auth.html', **{'warning': '名称已存在', 'nick': n, 'extra': extra})
     r = u.register(n, **extra)
     if r[0]:
         self.SESSION['uid']=u._id
         self.SESSION['nick']=n
         if extra.has_key('photo'):self.save_avatar(extra['photo'])
         u._api.edit(u._id, **extra)
         return self.render('ajax/runjs.html', uid=u._id)
     else:
         return self.render('profile/auth.html', **{'warning': r[1], 'nick': n, 'extra': extra})
Example #10
0
 def post(self):
     uid = self.SESSION['uid']
     o= self.get_argument('oldpassword', None)
     if o is None:return self.write({'error':'请输入旧密码'})
     n = self.get_argument('newpassword', None)
     if n is None:return self.write({'error':'请输入新密码'})
     c = self.get_argument('confpassword', None)
     if c is None:return self.write({'error':'请输入确认密码?'})
     u = User()
     u.whois("_id", uid)
     if (u.password != unicode(md5(o).hexdigest())):return self.write({'error':'密码不正确?'})
     if (n != c):return self.write({'error':'新密码不匹配?'})
     u._api.edit(uid, password=unicode(md5(n).hexdigest()))
     return self.write({'ret':'ok'})
Example #11
0
 def post(self):
     uid = self.SESSION['uid']
     o= self.get_argument('oldpassword', None)
     if o is None:return self.render('profile/cpassword.html', **{'warning': '请输入旧密码'})
     n = self.get_argument('newpassword', None)
     if n is None:return self.render('profile/cpassword.html', **{'warning': '请输入新密码'})
     c = self.get_argument('confpassword', None)
     if c is None:return self.render('profile/cpassword.html', **{'warning': '请输入确认密码?'})
     u = User()
     u.whois("_id", uid)
     if (u.password != o):return self.render('profile/cpassword.html', **{'warning': '密码不正确'})
     if (n != c):return self.render('profile/cpassword.html', **{'warning': '新密码不匹配'})
     u._api.edit(uid, password=n)
     return self.redirect('/account/setting/')
Example #12
0
    def post(self):
        n = self.get_argument('nick', None)
        if n is None:return self.render('login.html', **{'warning': '请先报上名号', 'n':n})
        p = self.get_argument('password', None)
        if p is None:return self.render('login.html', **{'warning': '您接头暗号是?', 'n':n})
        nt = self.get_argument('next', None)
        u = User()
        r = u.login(n, p)
        if r[0]:
#            self.set_secure_cookie("user", n, 1)
            self.SESSION['uid']=u._id
            self.SESSION['nick']=n
            self.redirect(nt) if nt else self.redirect('/account/profile')
        else:
            return self.render('profile/login.html', **{'warning': r[1], 'n':n})
Example #13
0
    def post(self):
        n = self.get_argument('nick', None)
        if n is None:return self.write({'error':'请先报上名号'})
        p = self.get_argument('password', None)
        if p is None:return self.write({'error':'您接头暗号是'})
        nt = self.get_argument('next', None)
        u = User()
        r = u.login(n, p)
        if r[0]:
#            self.set_secure_cookie("user", n, 1)
            self.SESSION['uid']=u._id
            self.SESSION['nick']=n
            self.write({'uid':u._id})
        else:
            self.write({'error':r[1]})
Example #14
0
    def post(self):
        e= self.get_argument('email', None)
        if e is None:return self.render('profile/register.html', **{'warning': '设置邮箱,可能帮您找回失散多年的密码', 'email':e})
        n = self.get_argument('nick', None)
        if n is None:return self.render('profile/register.html', **{'warning': '请先报上名号', 'email':e})
        p = self.get_argument('password', None)
        if p is None:return self.render('profile/register.html', **{'warning': '您接头暗号是?', 'email':e})
        u = User()
        r = u.register(n, p, email=e)
        if r[0]:
#            self.set_secure_cookie("user", n, 1)
            self.SESSION['uid']=r[1]
            self.SESSION['nick']=n
            self.redirect('/account/profile')
        else:
            return self.render('profile/register.html', **{'warning': r[1], 'email':e})
Example #15
0
    def post(self):
        e= self.get_argument('email', None)
        if e is None:return self.write({'error':'设置邮箱,可能帮您找回失散多年的密码'})
        n = self.get_argument('nick', None)
        if n is None:return self.write({'error':'请报上名号'})
        p = self.get_argument('password', None)
        if p is None:return self.write({'error':'您接头暗号是'})
        u = User()
        r = u.register(n, p, email=e)
        if r[0]:
#            self.set_secure_cookie("user", n, 1)
            self.SESSION['uid']=r[1]
            self.SESSION['nick']=n
            self.write({'uid':u._id})
        else:
            self.write({'error':r[1]})
Example #16
0
 def post(self):
     verification_code = self.request.get("code")
     args = dict(client_id=RENREN_APP_API_KEY, redirect_uri=self.request.path_url)
     error = self.request.get("error")
     if error:
         args["error"] = error
         args["error_description"] = self.request.get("error_description")
         args["error_uri"] = self.request.get("error_uri")
         path = os.path.join(os.path.dirname(__file__), "error.html")
         args = dict(error=args)
         self.response.out.write(template.render(path, args))
     elif verification_code:
         scope = self.request.get("scope")
         scope_array = str(scope).split("[\\s,+]")
         response_state = self.request.get("state")
         args["client_secret"] = RENREN_APP_SECRET_KEY
         args["code"] = verification_code
         args["grant_type"] = "authorization_code"
         response = urllib.urlopen(RENREN_ACCESS_TOKEN_URI + "?" + urllib.urlencode(args)).read()
         access_token = _parse_json(response)["access_token"]
         '''Obtain session key from the Resource Service.'''
         session_key_request_args = {"oauth_token": access_token}
         response = urllib.urlopen(RENREN_SESSION_KEY_URI + "?" + urllib.urlencode(session_key_request_args)).read()
         session_key = str(_parse_json(response)["renren_token"]["session_key"])
         '''Requesting the Renren API Server obtain the user's base info.'''
         params = {"method": "users.getInfo", "fields": "name,tinyurl"}
         api_client = RenRenAPIClient(session_key, RENREN_APP_API_KEY, RENREN_APP_SECRET_KEY)
         response = api_client.request(params);
         if type(response) is list:
             response = response[0]
         user_id = response["uid"]#str(access_token).split("-")[1]
         name = response["name"]
         avatar = response["tinyurl"]
         user = User(key_name = unicode(user_id), id = unicode(user_id), name = unicode(name), avatar = unicode(avatar), access_token = access_token)
         user.put()
         set_cookie(self.response, "renren_user", str(user_id), expires=time.time() + 30 * 86400)
         self.redirect("/")
     else:
         args["response_type"] = "code"
         args["scope"] = "publish_feed email status_update"
         args["state"] = "1 23 abc&?|."
         self.redirect(RENREN_AUTHORIZATION_URI + "?" +urllib.urlencode(args))