diff options
-rw-r--r-- | pastepy.py | 13 | ||||
-rw-r--r-- | templates/paste.tmpl | 2 |
2 files changed, 12 insertions, 3 deletions
@@ -1,4 +1,4 @@ -import templates, pygments, cgi, db, datetime, hashlib, settings, os, mimetypes +import templates, pygments, cgi, db, datetime, hashlib, settings, os, mimetypes, Cookie from pygments import highlight from pygments.lexers import get_all_lexers, get_lexer_by_name from pygments.formatters import HtmlFormatter @@ -22,6 +22,7 @@ class Paste(object): self.formatter = HtmlFormatter(linenos = 'table', lineanchors = 'line', anchorlinenos = True) def paste(self): + c = Cookie.SimpleCookie(self.environ['HTTP_COOKIE'] if 'HTTP_COOKIE' in self.environ else None) if self.environ['REQUEST_METHOD'] == 'POST': mp = cgi.FieldStorage(fp = self.environ['wsgi.input'], environ = self.environ, keep_blank_values = True) if mp['type'].value == 'Preview': @@ -36,6 +37,8 @@ class Paste(object): 'title': settings.pastebin_name, 'header': settings.pastebin_name, 'lexers': self.lexers, + 'nick': c['nick'].value if 'nick' in c else 'Anonymous', + 'remembered': 'nick' in c, }))] def preview(self, mp): @@ -75,7 +78,13 @@ class Paste(object): finally: session.close() - self.start_response('302 Found', [('Location', '/view/%s' % hash)]) + headers = [('Location', '/view/%s' % hash)] + c = Cookie.SimpleCookie() + c['nick'] = nick + dt = (datetime.datetime.utcnow() + datetime.timedelta(days = 30)) if 'remember_me' in mp else datetime.datetime.utcfromtimestamp(0) + c['nick']['expires'] = dt.strftime('%a, %d-%b-%y %H:%M:%S GMT') + headers.append(('Set-Cookie', c['nick'].OutputString())) + self.start_response('302 Found', headers) return [] def view(self): diff --git a/templates/paste.tmpl b/templates/paste.tmpl index 0a201fe..195d463 100644 --- a/templates/paste.tmpl +++ b/templates/paste.tmpl @@ -16,7 +16,7 @@ #end for </select> </li> - <li><input type="text" name="nick" id="nick" value="Anonymous" /></li> + <li><input type="text" name="nick" id="nick" value="$nick" /> <label for="remember_me"><input type="checkbox" name="remember_me" id="remember_me" #if $remembered#checked="true" #end if#/> Remember me</label></li> <li><input type="text" name="title" id="title" value="Untitled" /></li> <li><textarea rows="15" cols="80" name="text" id="text"></textarea></li> <li> |