示例#1
0
文件: main.py 项目: blazarus/charmme
def index():
    username = request.cookies.get('username')
    webcode = request.cookies.get('web_code')
    print "username", username, "webcode", webcode
    if request.method == 'POST':
        print "post from GI detected"
        uname = request.form['value']
        resp = make_response( redirect(url_for('profile', username=uname)))
        resp.set_cookie('username', uname)
        return resp
    if webcode == None and username == None:
        print "first time user! no cookie and webcode"
        return redirect(url_for('login'))
    else:
        username = get_username(webcode)
    if username == None:
        print "username is none from webcode"
        error = "Unable to log in." 
        submsg = "Please check your credentials and try again."
        return render_template('error.html', message=error, sub_message=submsg) 

        # return redirect(url_for('login'))
    print "returning user!", username
    resp = make_response( redirect(url_for('profile', username=username)))
    resp.set_cookie('username', username)
    return resp
示例#2
0
文件: main.py 项目: blazarus/charmme
def indexOld():
    print 'webcode??', request.cookies.get('web_code')
    print session
    #TODO must differentiate between redirecting skip from qr OR user landed here directly
    print "cookie webcode", request.cookies.get('web_code')
    if request.cookies.get('web_code') == None:
        return redirect(url_for('login'))
    if request.cookies.get('web_code') != None:
        my_webcode = request.cookies['web_code']
        username = get_username(my_webcode) 
        print "username", username
    #   return redirect(url_for('profile', username=username))
            # go to user's profile
            #return 'Logged in as %s' % escape(session['my_webcode'])

    #    if 'web_code' in request.cookies:
    #   username = get_username(session['my_webcode'])
    #   print "in here", username
        resp = make_response( redirect(url_for('profile', username=username)))
        resp.set_cookie('username', username)
        return resp
    #return redirect("http://qr.media.mit.edu/login?next=http://charmme.media.mit.edu/&noskip=true")    
    return redirect(url_for('login'))