def service_get(request):
    login = pyramid.security.authenticated_userid(request)
    did_fail = False
    user = None
    data = {}
    accessKey = request.matchdict['accessKey']
    if login is not None:
        headers = pyramid.security.forget(request)
        '''
        username = login.split("|")[0]
        user = conference_abstract.auth.check_user(request)
        if user is not None:
            loc = request.route_url('dashboard')
            return HTTPFound(location=loc)
        '''
    try:
        sql = """select * from chairs where accesskey = %s"""
        conn = conference_abstract.util.get_connection()
        cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
        sqlOut = cur.mogrify(sql, (accessKey, ))
        cur.execute(sql, (accessKey, ))
        if cur.rowcount == 1:
            data = {"sqlran": sqlOut}
            results = cur.fetchone()
            user = User('*****@*****.**')
            user.get_userObj()
            userObj = user.get_chairObj(accessKey)
            headers = pyramid.security.remember(
                request, '*****@*****.**' + "|" + str(accessKey) + "|" +
                str(userObj["chairId"]))
            session = request.session
            session['fullname'] = userObj["fullname"]
            session['userId'] = userObj["userId"]
            return HTTPFound(location="/dashboard", headers=headers)
        else:
            print "========== \/ look here \/ ========="
            print sqlOut
            print cur.rowcount
            print "========== /\ look here /\ ========="
    except Exception as e:
        print ">>>>>>>>>> ERROR ERROR ERROR >>>>>>>>>>>>"
        print e
        print ">>>>>>>>>> ERROR ERROR ERROR >>>>>>>>>>>>"
    return conference_abstract.util.generate_template('noAccess.mako', {
        "user": user,
        "request": request,
        "pageTitle": "Login"
    })
Beispiel #2
0
def service_post(request):
    login = pyramid.security.authenticated_userid(request)
    did_fail = False
    user = None
    noAccess = False
    data = {}
    templateVars = {
        'message':'Your email or password is incorrect.<br/> Please try again',
        #'user': user,
        'breadCrumbs':[{"url":"/","text":"Home"},{"url":"","text":"Chair Login"}],
        'pageTitle':'Chair Login',
        #'token':token,   # session token
        "request":request
    }
    if 'submit' in request.POST:
        login = request.POST.get('login', '')
        passwd = request.POST.get('passwd', '')
        #user = USERS.get(login, None)
        print login,passwd
        user = User(login,None)

        loginCheck = user.check_password(passwd)
        if user and loginCheck != False:
            # Create session and set cookies
            userObj = user.get_userObj()
            headers = pyramid.security.forget(request)
            conn = conference_abstract.util.get_connection()
            cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
            try:
                sql = """select * from chairs where fk_cusers = %s"""
                sqlOut = cur.mogrify(sql,[userObj["userId"]])
                cur.execute(sql,[userObj["userId"]])
                if cur.rowcount == 1:
                    data = {"sqlran":sqlOut}
                    results = cur.fetchone()
                    accessKey = results["accesskey"]
                    print "*************************************"
                    print "*"
                    print accessKey, sqlOut
                    print "*"
                    print "*************************************"
                    user.get_userObj()
                    userObj = user.get_chairObj(accessKey)
                    headers = pyramid.security.remember(request, login+"|"+str(accessKey)+"|"+str(userObj["chairId"]))
                    print "========== \\/ look here 1 \\/ ========="
                    print login+"|"+str(accessKey)+"|"+str(userObj["chairId"])
                    print "========== /\\ look here /\\ ========="
                    session = request.session
                    session['fullname'] = userObj["fullname"]
                    session['userId'] = userObj["userId"]
                    return HTTPFound(location="/dashboard", headers=headers)
                else:
                    noAccess = True
                    print "========== \/ look here 2 \/ ========="
                    print sqlOut
                    print cur.rowcount
                    print "========== /\ look here /\ ========="
            except Exception as e:
                print ">>>>>>>>>> ERROR ERROR ERROR >>>>>>>>>>>>"
                print e
                print ">>>>>>>>>> ERROR ERROR ERROR >>>>>>>>>>>>"
        did_fail = True
    user = None
    templateVars['failed_attempt'] = did_fail
    templateVars['login'] = login
    #token = login.split("|")[1] if login is not None else ""
    if noAccess == False:
        return conference_abstract.util.generate_template('login.mako',templateVars)
    else:
        return conference_abstract.util.generate_template('noAccess.mako',{"user":user,"request":request,"pageTitle":"Chair Login"})