Created
May 16, 2016 06:01
-
-
Save ks888/e0a50e1c87b8b4c276844be39ab3dbc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import route, run, request, default_app, HTTPResponse | |
import mysql.connector | |
@route('/login') | |
def login(): | |
username = request.query.id | |
password = request.query.password | |
connect = mysql.connector.connect(db="test", host="localhost", port=3306, user="root") | |
cur = connect.cursor() | |
sql = "select id from user where id='%s' and pass='%s'" % (username, password) | |
cur.execute(sql) | |
rows = cur.fetchall() | |
if len(rows) != 0: | |
body = '\n'.join([user for (user,) in rows]) | |
resp = HTTPResponse(status=200, body=body) | |
else: | |
resp = HTTPResponse(status=401) | |
cur.close() | |
connect.close() | |
return resp | |
@route('/') | |
def healthcheck(): | |
return "" | |
app = default_app() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment