예제 #1
0
    def POST(self, id, encodedURL):
        session_id = session.get_user_id()
        userId = int(id)
        if userId != session_id:
            js = {}
            js['ok'] = False
            js['message'] = "web.notfound()"
            ans = json.dumps(js)
            return ans
            # raise web.notfound()

        newKey = None
        try:
            with open(tmp_img_path(id), 'rb') as f:
                uploadURL = base64.urlsafe_b64decode(str(encodedURL))
                newKey, err = fs.putFile(f, uploadURL)
                if err != None:
                    web.debug(err)
                    js = {}
                    js['ok'] = False
                    js['message'] = u"头像上传失败"
                    ans = json.dumps(js)
                    return ans
                    # raise web.seeother('/personal_edit/' + id)
        except IOError:
            pass

        x = web.input()
        web.debug(x.uname)
        web.debug(x.email)
        web.debug(newKey)

        ans, temp_user = infoDBserver.get_user(session_id)
        if not ans:
            raise web.notfound()

        if x.uname:
            temp_user.userName = x.uname
        if x.email:
            temp_user.mail = x.email
        if newKey:
            temp_user.picKey = newKey

        js = {}
        js['ok'] = True
        js['message'] = "Everything is OK~"

        ret = infoDBserver.modify_user(userId, temp_user)
        if not ret:
            web.debug(ret)
            js['ok'] = False
            js['message'] = 'update user info failed.'
            try:
                os.remove(tmp_img_path(id))
            except:
                pass

        ans = json.dumps(js)
        return ans
예제 #2
0
 def POST(self, encodedURL):
     uploadURL = base64.urlsafe_b64decode(str(encodedURL))
     x = web.input(up_file={})
     filename = x['up_file'].filename
     type1 = web.input().file_type
     key, err = fs.putFile(x['up_file'].file, uploadURL, extension=str(type1))
     if err != None:
         web.debug(err)
         raise web.seeother('/upload')
         # do something
         return
     web.debug(key)
     ans1, video = infoDBserver.insert_video(key, session.get_user_id())
     ans2, video2 = infoDBserver.modify_video(video.videoId,videoName = filename, type = type1)
     ##waiting for type changing
     if ans2:
         ans = upload2json(video2.videoId, True, message = "")
         return ans
     else:
         ans = upload2json(video2.videoId, False, message = '')
         return ans