Alright, let's try this again. I've started over from scratch and we have got the basic functions working. Everything so far has checked out, but I am still trying to get it to pull the right credentials. I can get it to pull one of the rows out of the database, but not particularly the one I desire. I'm sure I have the wrong SQL command or have it phrased weirdly. Other than that it works just fine.

It pulls the same entry every time, regardless of what I put in the login.

import pesto, time, os
import pesto.session.memorysessionmanager
os.environ['PATH']+=";C:\\Program Files (x86)\\PostgreSQL\\8.4\\bin"
import pgdb


form = pesto.dispatcher_app()


@form.match('/', 'GET')
def index(request):

    if 'username' in request.session:
        request.session['username'] = request.session['username']
    else:
        request.session['username'] = ''

    if 'password' in request.session:
        request.session['password']= request.session['password']
    else:
        request.session['password'] = ''


    html = ''
    html += '<h1 align="center"> Welcome to Andrew and Justin\'s Blog. Please enjoy!</h1>'
    html += '<form name="w7l3q2" action="myapp/login" method="post">' 
    html += 'Username: <input type="text" name="name" value="%s"><br>' % request.session['username']
    html += 'Password: <input type="password" name="password" value="%s"><br>' %request.session['password']
    html += '<input type="hidden" name="request" value="login"><br>'
    html += '<input type="submit" value="Submit!"><br>'
    html += '</form>'
    html += '<form name="guest" action="myapp/guest" method="post">'
    html += '<input type="hidden" name="request" value="guestlogin">'
    html += '<input type="submit" value="Guest Access"><br> ^ Justin, this will break until we get the entry view laced in, what is the exact name of it?'
    html += '</form>'

    return pesto.Response ([html])


@form.match('/login', 'POST') #My computer is requiring this for whatever reason.
def login(request):

    request.session['username'] = request.get('name')
    request.session['password'] = request.get('password')

    username = request.get('name')
    password = request.get('password')

    try:
        connection = pgdb.connect(
            user="postgres",
            password="xxxxxx",
            database="postgres")

        cursor = connection.cursor()
        cursor.execute("select username, password from users where ")
        credential = cursor.fetchone()

        html = 'Hello World!<br>'
        html += 'Verifying server. Please wait one moment.<br>'
        html += 'Validating User Name....<BR>'
        html += 'Server is verified, but functions are still under construction. Please step back.<BR>'
        html += '<br><br><a href="/myapp">Go Back</a>'

        html += '<br><br>'
        html += 'Verifiable Credentials: %s' % credential
        html += '<br><br>Did it work? Or is it still showing the same basic credentials? I wonder what the solution might be.'
        return pesto.Response ([html])    


    #    return pesto.Response.redirect('/access')        

    except:         # This will pop up if your db user credentials are wrong.
        html = 'Hello World!<br>'
        html += 'Verifying server. Please wait one moment.<br>'
        html += 'Validating User Name....<BR>'
        html += 'Server is not verified or online. Please step back.<BR>'
        html += '<br><br><a href="/myapp">Go Back</a>'


    return pesto.Response ([html])    

    # return pesto.Response.redirect('/myapp/auth') # Will redirect to auth3.py, ideally, and check the status of the inputs. 


@form.match('/guest', 'POST')
def guest(request):

    html = 'User Name: Guest Access<br>'
    html += 'Password: Guest Access<br>'

    request.session['username'] = 'guest'
    request.session['password'] = 'guest'

    html += '<br><br><a href="/myapp">Go Back</a>'

    # return pesto.Response ([html])

    return pesto.Response.redirect(__file__) #If this is not the name of the file you created, please feel free to change.    

# This is dummy code to be called up as needed -- such as any previous work just flat out breaks!
@form.match('/auth', 'GET')
def getConnection(request):

    try:
        connection = pgdb.connect(
            user="postgres",
            password="gobears07",
            database="postgres")

        cursor = connection.cursor()


        html = 'Hello World!<br>'
        html += 'Verifying server. Please wait one moment.<br>'
        html += 'Validating User Name....<BR>'
        html += 'Server is verified, but functions are still under construction. Please step back.<BR>'

        return pesto.Response.redirect('/access')        


    except:
        html = 'Hello World!<br>'
        html += 'Verifying server. Please wait one moment.<br>'
        html += 'Validating User Name....<BR>'
        html += 'Server is not verified or online. Please step back.<BR>'

    return pesto.Response ([html])


holddata = pesto.session_middleware(
pesto.session.memorysessionmanager.MemorySessionManager())

application = holddata(form)

Recommended Answers

All 2 Replies

Figured it out on my own.

Try these simple functions, which just contain general SQL statements, and see what you get. This assumes that the table name is "postgres" (from your code") and the user name field is named "username" (again from your code). Since we don't know the table name or layout it is impossible to post specific code.

def get_connection():
        connection = pgdb.connect(
            user="postgres",
            password="gobears07",
            database="postgres")
 
        cursor = connection.cursor()

        return connection, cursor

def select_all(cursor):
    cursor.execute("select * from postgres")
    recs_found = cursor.fetchall()

    ## I don't know what type of object pgdb returns
    print type(recs_found)
    print len(recs_found)

def select_user(cursor)
    """ replace 'abc' with a user name that is in the DB
    """
    cursor.execute('select username, password from postgres where username="abc"')
    rec = cursor.fetchone()
    print list(rec)
 
try:
    con, cur = get_connection()
    select_all(cur)
    select_user(cur)
except:
    import traceback
    traceback.print_exc()
    raise
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.