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)