Guest User

Untitled

a guest
Nov 15th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.38 KB | None | 0 0
  1. 1.1" 404 -
  2. /usr/local/lib/python2.7/site-packages/Werkzeug-0.11.11-py2.7.egg/werkzeug/files ystem.py:63: BrokenFilesystemWarning: Detected a misconfigured UNIX filesystem: Will use UTF-8 as filesystem encoding instead of 'ANSI_X3.4-1968'
  3. BrokenFilesystemWarning)
  4. 10.0.2.2 - - [15/Nov/2017 18:23:13] "POST /signin HTTP/1.1" 500 -
  5. Traceback (most recent call last):
  6. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 2000, in __call__
  7. return self.wsgi_app(environ, start_response)
  8. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 1991, in wsgi_app
  9. response = self.make_response(self.handle_exception(e))
  10. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 1567, in handle_exception
  11. reraise(exc_type, exc_value, tb)
  12. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 1988, in wsgi_app
  13. response = self.full_dispatch_request()
  14. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 1641, in full_dispatch_request
  15. rv = self.handle_user_exception(e)
  16. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 1544, in handle_user_exception
  17. reraise(exc_type, exc_value, tb)
  18. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 1639, in full_dispatch_request
  19. rv = self.dispatch_request()
  20. File "/usr/local/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app. py", line 1625, in dispatch_request
  21. return self.view_functions[rule.endpoint](**req.view_args)
  22. File "/home/tc/lynch_matthew_set09103_coursework2/src/index.py", line 136, in signin
  23. complete = validate(username, password)
  24. File "/home/tc/lynch_matthew_set09103_coursework2/src/index.py", line 39, in v alidate
  25. cur = db.execute("SELECT * FROM users")
  26. NameError: global name 'db' is not defined
  27. 10.0.2.2 - - [15/Nov/2017 18:23:14] "GET /signin?__debugger__=yes&cmd=resource&f =style.css HTTP/1.1" 200 -
  28. 10.0.2.2 - - [15/Nov/2017 18:23:14] "GET /signin?__debugger__=yes&cmd=resource&f =jquery.js HTTP/1.1" 200 -
  29. 10.0.2.2 - - [15/Nov/2017 18:23:14] "GET /signin?__debugger__=yes&cmd=resource&f =debugger.js HTTP/1.1" 200 -
  30. 10.0.2.2 - - [15/Nov/2017 18:23:15] "GET /signin?__debugger__=yes&cmd=resource&f =ubuntu.ttf HTTP/1.1" 200 -
  31. 10.0.2.2 - - [15/Nov/2017 18:23:15] "GET /signin?__debugger__=yes&cmd=resource&f =console.png HTTP/1.1" 200 -
  32. 10.0.2.2 - - [15/Nov/2017 18:23:15] "GET /signin?__debugger__=yes&cmd=resource&f =console.png HTTP/1.1" 200 -
  33.  
  34. import sqlite3
  35. import os
  36. import sqlite3 as sql
  37.  
  38. from flask import Flask, g, render_template, url_for, request, redirect, session, escape, flash, abort
  39. from hashlib import md5
  40. from functools import wraps
  41.  
  42. app = Flask(__name__)
  43. app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
  44. db_location = 'var/wish_db.db'
  45.  
  46. def required(f):
  47. @wraps(f)
  48. def decorator(*args, **kwargs):
  49. status = session.get('username', False)
  50. if not status:
  51. return redirect(url_for('signin'))
  52. return f(*args, **kwargs)
  53. return decorator
  54.  
  55. def get_db():
  56. db = getattr(g, 'db', None)
  57. if db is None:
  58. db = sqlite3.connect(db_location)
  59. g.db = db
  60. return db
  61.  
  62. def check_password(hashed_password, user_password):
  63. return hashed_password == hashlib.md5(user_password.encode()).hexdigest()
  64. print hashed_password
  65.  
  66. def validate(username, password):
  67. con = sqlite3.connect(db_location)
  68. complete = False
  69. with con:
  70. cur = con.cursor()
  71.  
  72. cur = db.execute("SELECT * FROM users")
  73. rows = cur.fetchall()
  74. for row in rows:
  75. userdb = row[0]
  76. passdb = row[2]
  77. if userdb == username:
  78. complete = check_password(passdb, password)
  79. return complete
  80.  
  81. @app.teardown_appcontext
  82. def close_db_connection(exception):
  83. db = getattr(g, 'db', None)
  84. if db is not None:
  85. db.close()
  86. def init_db():
  87. with app.app_context():
  88. db = get_db()
  89. with app.open_resource('var/schema.sql', mode='r') as f:
  90. db.cursor().executescript(f.read())
  91. db.commit()
  92.  
  93. #The Sign Up Route
  94. @app.route('/signup', methods=['GET','POST'])
  95. def signup():
  96. error = None
  97. if request.method == 'POST':
  98. db = get_db()
  99. cur = db.execute('INSERT INTO users (username,email,password) VALUES(?,?,?)',
  100. [request.form['username'], request.form['email'], request.form['password']])
  101. db.commit()
  102. return redirect(url_for('dashboard'))
  103. else:
  104. error = "Somthing Went Wrong. Try Again!"
  105. return render_template('signup.html', title='Sign Up')
  106. return render_template('signin.html', title='Sign Up', error=error)
  107.  
  108. #The Homepage Route
  109. @app.route("/")
  110. def home():
  111. return render_template('home.html', title='Home')
  112.  
  113. #The Dashboard Route
  114. @app.route('/dashboard')
  115. def dashboard():
  116. #db = get_db()
  117. #if 'username' in session:
  118. # sess = escape(session['username']).capitalize()
  119. # return render_template('dashboard.html', session_user=sess, title='Dashboard')
  120. #return redirect(url_for('dashboard'))
  121.  
  122. db = get_db()
  123. cur = db.execute('select title, quantity, price, details from wishlists order by wish desc')
  124. wishlists = [dict(title=row[0], quantity=row[1], price=row[2], details=row[3]) for row in cur.fetchall()]
  125. db.close()
  126. return render_template('dashboard.html', wishlists=wishlists)
  127.  
  128. #The Adds a Dream Itam to the List
  129. @app.route('/add', methods=['GET','POST'])
  130. def add():
  131. if not session.get('username'):
  132. abort(401)
  133. db = get_db()
  134. db.execute('INSERT INTO wishlists (title,quantity,price,details) VALUES(?,?,?,?)',
  135. [request.form['title'], request.form['quantity'], request.form['price'], request.form['details']])
  136. db.commit()
  137. flash('Your wish has been added to your list')
  138. return redirect(url_for('dashboard'))
  139.  
  140. #The Removes a Dream Itam to the List
  141. @app.route('/remove', methods=['GET'])
  142. def remove():
  143. delete = request.args.get('wishid', '')
  144. print delete
  145. db = get_db()
  146. db.execute('DELETE FROM wishlists WHERE title=?', [delete])
  147. db.commit()
  148. cur = db.execute("select * from wishlists")
  149. row = cur.fetchall()
  150. flash('Your wish has been removed from your list')
  151. return render_template("dashboard.html",row=row)
  152.  
  153. #The About Route
  154. @app.route('/about', methods=['GET', 'POST'])
  155. def about():
  156. return render_template('about.html', songs=songs, title='About')
  157.  
  158.  
  159. #The Signs In Route
  160. @app.route('/signin', methods=['GET','POST'])
  161. def signin():
  162. db = get_db()
  163. if 'username' in session:
  164. return redirect(url_for('dashboard'))
  165. error = None
  166. if request.method == 'POST':
  167. username = request.form['username']
  168. password = request.form['password']
  169. complete = validate(username, password)
  170. if complete == False:
  171. error = 'Incorrect Username or Password. Please try again.'
  172. else:
  173. return redirect(url_for('dashboard'))
  174. if request.form['username'] != 'admin' or request.form['password'] != 'adminAWT':
  175. error = 'Incorrect Username or Password, Please try again.'
  176. else:
  177. session['username'] = True
  178. flash('Welcome! You Can Now View Your WounderList')
  179. return redirect(url_for('dashboard'))
  180. return render_template('signin.html', error=error, title='Sign In')
  181.  
  182. #Signs Out The User from Their Account
  183. @app.route('/signout')
  184. def signout():
  185. session.pop('username', None)
  186. flash('You Have Successful Signed Out')
  187. return redirect(url_for('home'))
  188.  
  189. #Error Page
  190. @app.errorhandler(404)
  191. def page_not_found(error):
  192. return "We couldn't answer your request. Please try again later or this page might not exist. </br> Please, check your URL", 404
  193.  
  194. if __name__ == "__main__":
  195. app.run(host='0.0.0.0', debug=True)
  196.  
  197. DROP TABLE if EXISTS users;
  198. DROP TABLE if EXISTS wishlists;
  199.  
  200. CREATE TABLE users (
  201. id integer primary key autoincrement,
  202. username text not null,
  203. email text not null,
  204. password text not null
  205. );
  206.  
  207. CREATE TABLE wishlists (
  208. wish integer primary key autoincrement,
  209. title text not null,
  210. quantity number not null,
  211. price text not null,
  212. details text not null
  213. );
  214.  
  215. from index import init_db
  216. init_db()
Add Comment
Please, Sign In to add comment