示例#1
0
    def POST(self):
        usercode =  web.ctx.env.get("HTTP_X_COPYPASTA_CODE")

        if usercode:

            split = usercode.split("&")
            user = split[0].split("=")[1]
            code = split[1].split("=")[1]

            if user:
                userinfo = userdb.select('users', where='user=$user', vars=locals())
                userinfo = userinfo[0]
                salt = userinfo.password

                hashed_secretcode = hashlib.sha512(code + salt).hexdigest()

                if hashed_secretcode == userinfo.secretcode:
                    newclip = base64.b64decode(web.data())
                    model.new_clip("by " + user + " on " + strftime("%Y-%m-%d %H:%M"), newclip, user)
                    web.header('Content-Type', 'application/json')
                    dict = {'status':"Clip saved"}
                    return json.dumps(dict)
                else:
                    dict = {'status':"Bad login"}
                    web.header('Content-Type', 'application/json')
                    return json.dumps(dict)
            else:
                dict = {'status':"Invalid user"}
                web.header('Content-Type', 'application/json')
                return json.dumps(dict)
        else:
            raise web.seeother('/')
示例#2
0
    def POST(self):
        form = self.form()
        clips = model.get_clips(getuser())

        if not form.validates():
            return render.index(clips, form)

        model.new_clip(form.d.title, form.d.content, getuser())
        raise web.seeother('/')