Example #1
0
def before_request():
    """Make sure we are connected to the database each request and look
    up the current user so that we know he's there.
    """
    g.redis = app.redis
    g.user = None
    if request.path.startswith('/static/'):
        return
    ua = httpagentparser.detect(request.user_agent.string)
    g.useragent = ua
    g.using_html5 = False
    if 'dist' in ua and ua['dist'].get('name', '').lower() in ['iphone', 'ipad', 'macintosh'] \
        and 'browser' in ua and ua['browser'].get('name', '').lower() in ['safari']:
        g.using_html5 = True
    if 'user_id' in session:
        g.user = f.load_user(session['user_id'])
    if g.user and 'guide_step' in g.user.extra and not request.path.startswith('/guide/') and not request.path.startswith('/m/'):
        p = None
        if request.referrer:
            parsedurl = urlparse(request.referrer)
            p = parsedurl.path
        if request.path == "/logout/":
            pass
        elif not p or not p.startswith('/guide/'):
            return redirect('/guide/')
Example #2
0
def before_request():
    """Make sure we are connected to the database each request and look
    up the current user so that we know he's there.
    """
    g.redis = app.redis
    g.user = None
    if request.path.startswith('/static/'):
        return
    ua = httpagentparser.detect(request.user_agent.string)
    g.useragent = ua
    g.using_html5 = False
    if 'dist' in ua and ua['dist'].get('name', '').lower() in ['iphone', 'ipad', 'macintosh'] \
        and 'browser' in ua and ua['browser'].get('name', '').lower() in ['safari']:
        g.using_html5 = True
    if 'user_id' in session:
        g.user = f.load_user(session['user_id'])
    if g.user and 'guide_step' in g.user.extra and not request.path.startswith(
            '/guide/') and not request.path.startswith('/m/'):
        p = None
        if request.referrer:
            parsedurl = urlparse(request.referrer)
            p = parsedurl.path
        if request.path == "/logout/":
            pass
        elif not p or not p.startswith('/guide/'):
            return redirect('/guide/')
Example #3
0
 def login_wrapped(*argt, **argd):
     if g.user is None:
         return redirect(url_for('mobile.m_login', next=request.url))
     if g.user.isparent:
         return redirect(url_for('mobile.m_selectchild'))
     g.parent = None
     if 'parent_id' in session:
         import lib.functions as f
         g.parent = f.load_user(session['parent_id'])
     ret = fn(*argt, **argd)
     return ret