Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is the ajaxlogin.py file,
- # which creates the sessions userid
- # and password, which is md5-encoded.
- #!/usr/bin/env python
- import sys, md5
- import cgitb; cgitb.enable()
- sys.path.append("/home/toxic_elegant/python")
- from wsgiref.handlers import CGIHandler
- from beaker.middleware import SessionMiddleware
- from weberror.errormiddleware import ErrorMiddleware
- from webob import Request, Response
- import elixir
- from sqlalchemy import create_engine, and_
- from model import * # My functions
- # Elixir and SQLAlchemy stuff
- elixir.metadata.bind = create_engine('mysql://username:password@mysql.host.com/db_name')
- elixir.setup_all()
- def app(environ, start_response):
- session = environ['beaker.session']
- request = Request(environ)
- response = Response()
- headers = [('Content-type', 'text/html')]
- username = request.POST['username']
- password = request.POST['password']
- password = md5.new(password).hexdigest()
- myquery = User.query.filter(and_(User.user==username, User.password==password))
- result = myquery.count()
- if myquery.count() == 1:
- myquery = myquery.one()
- session['userid'] = myquery.id
- session['password'] = myquery.password
- result = "You've been successfully logged in!"
- session.save()
- else:
- result = "Sorry, but the combination you entered seems to be nonexistent. Either try again or contact the admin."
- start_response('200 OK', headers)
- return [str(result)]
- session_opts = {'session.cookie_expires': True}
- app = ErrorMiddleware(app, debug=True)
- app = SessionMiddleware(app, session_opts)
- CGIHandler().run(app)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement