fixed a small cookie-bug :)
This commit is contained in:
parent
c75f34cb1d
commit
6c1cb213c0
@ -25,7 +25,9 @@ from lodgeit.controllers import get_controller
|
|||||||
class LodgeIt(object):
|
class LodgeIt(object):
|
||||||
"""The WSGI Application"""
|
"""The WSGI Application"""
|
||||||
|
|
||||||
def __init__(self, dburi):
|
def __init__(self, dburi, secret_key):
|
||||||
|
self.secret_key = secret_key
|
||||||
|
|
||||||
#: database engine
|
#: database engine
|
||||||
self.engine = sqlalchemy.create_engine(dburi, convert_unicode=True)
|
self.engine = sqlalchemy.create_engine(dburi, convert_unicode=True)
|
||||||
#: make sure all tables exist.
|
#: make sure all tables exist.
|
||||||
@ -85,10 +87,7 @@ class LodgeIt(object):
|
|||||||
resp = e.get_response(environ)
|
resp = e.get_response(environ)
|
||||||
else:
|
else:
|
||||||
expires = datetime.utcnow() + timedelta(days=31)
|
expires = datetime.utcnow() + timedelta(days=31)
|
||||||
if request.first_visit:
|
if request.first_visit or request.session.should_save:
|
||||||
resp.set_cookie(COOKIE_NAME, request.user_hash,
|
|
||||||
expires=expires)
|
|
||||||
if request.session.should_save:
|
|
||||||
request.session.save_cookie(resp, COOKIE_NAME,
|
request.session.save_cookie(resp, COOKIE_NAME,
|
||||||
expires=expires)
|
expires=expires)
|
||||||
|
|
||||||
@ -96,10 +95,10 @@ class LodgeIt(object):
|
|||||||
[local._local_manager.cleanup, session.remove])
|
[local._local_manager.cleanup, session.remove])
|
||||||
|
|
||||||
|
|
||||||
def make_app(dburi, debug=False, shell=False):
|
def make_app(dburi, secret_key, debug=False, shell=False):
|
||||||
"""Apply the used middlewares and create the application."""
|
"""Apply the used middlewares and create the application."""
|
||||||
static_path = os.path.join(os.path.dirname(__file__), 'static')
|
static_path = os.path.join(os.path.dirname(__file__), 'static')
|
||||||
app = LodgeIt(dburi)
|
app = LodgeIt(dburi, secret_key)
|
||||||
if debug:
|
if debug:
|
||||||
app.engine.echo = True
|
app.engine.echo = True
|
||||||
if not shell:
|
if not shell:
|
||||||
|
@ -123,7 +123,7 @@ var LodgeIt = {
|
|||||||
*/
|
*/
|
||||||
removeCookie : function() {
|
removeCookie : function() {
|
||||||
if (confirm('Do really want to remove your cookie?')) {
|
if (confirm('Do really want to remove your cookie?')) {
|
||||||
$.cookie('user_hash', '');
|
$.cookie('lodgeit_session', '');
|
||||||
alert('Your cookie was resetted!');
|
alert('Your cookie was resetted!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from os import path, urandom
|
from os import path
|
||||||
from random import random
|
from random import random
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from werkzeug import Request as RequestBase, Response
|
from werkzeug import Request as RequestBase, Response
|
||||||
@ -31,7 +31,6 @@ jinja_environment = Environment(loader=FileSystemLoader(
|
|||||||
#: constants
|
#: constants
|
||||||
_word_only = partial(re.compile(r'[^a-zA-Z0-9]').sub, '')
|
_word_only = partial(re.compile(r'[^a-zA-Z0-9]').sub, '')
|
||||||
COOKIE_NAME = u'lodgeit_session'
|
COOKIE_NAME = u'lodgeit_session'
|
||||||
SECRET_KEY = urandom(50)
|
|
||||||
|
|
||||||
|
|
||||||
def generate_user_hash():
|
def generate_user_hash():
|
||||||
@ -59,7 +58,8 @@ class Request(RequestBase):
|
|||||||
def __init__(self, environ):
|
def __init__(self, environ):
|
||||||
super(Request, self).__init__(environ)
|
super(Request, self).__init__(environ)
|
||||||
self.first_visit = False
|
self.first_visit = False
|
||||||
session = SecureCookie.load_cookie(self, COOKIE_NAME, SECRET_KEY)
|
session = SecureCookie.load_cookie(self, COOKIE_NAME,
|
||||||
|
local.application.secret_key)
|
||||||
user_hash = session.get('user_hash')
|
user_hash = session.get('user_hash')
|
||||||
|
|
||||||
if not user_hash:
|
if not user_hash:
|
||||||
|
@ -10,17 +10,20 @@ from lodgeit.database import session
|
|||||||
|
|
||||||
dburi = 'sqlite:////tmp/lodgeit.db'
|
dburi = 'sqlite:////tmp/lodgeit.db'
|
||||||
|
|
||||||
|
SECRET_KEY = os.urandom(50)
|
||||||
|
|
||||||
|
|
||||||
def run_app(app, path='/'):
|
def run_app(app, path='/'):
|
||||||
env = create_environ(path)
|
env = create_environ(path, SECRET_KEY)
|
||||||
return run_wsgi_app(app, env)
|
return run_wsgi_app(app, env)
|
||||||
|
|
||||||
action_runserver = script.make_runserver(
|
action_runserver = script.make_runserver(
|
||||||
lambda: make_app(dburi),
|
lambda: make_app(dburi, SECRET_KEY),
|
||||||
use_reloader=True)
|
use_reloader=True)
|
||||||
|
|
||||||
action_shell = script.make_shell(
|
action_shell = script.make_shell(
|
||||||
lambda: {
|
lambda: {
|
||||||
'app': make_app(dburi, False, True),
|
'app': make_app(dburi, SECRET_KEY, False, True),
|
||||||
'local': local,
|
'local': local,
|
||||||
'session': session,
|
'session': session,
|
||||||
'run_app': run_app
|
'run_app': run_app
|
||||||
|
Loading…
Reference in New Issue
Block a user