Эх сурвалжийг харах

fix webserver errors and remove unused code

jmw327 11 жил өмнө
parent
commit
d9bfc02ae6

+ 36 - 1
.gitignore

@@ -1 +1,36 @@
-*.pyc
+# Project specific
+config.yaml
+venv/
+
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+bin/
+build/
+develop-eggs/
+dist/
+eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+.tox/
+.coverage
+.cache
+nosetests.xml
+coverage.xml

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "web/cleancss"]
+	path = web/cleancss
+	url = https://github.com/raylu/py-cleancss.git

+ 0 - 36
web/.gitignore

@@ -1,36 +0,0 @@
-# Project specific
-config.yaml
-venv/
-
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-
-# C extensions
-*.so
-
-# Distribution / packaging
-bin/
-build/
-develop-eggs/
-dist/
-eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-*.egg-info/
-.installed.cfg
-*.egg
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-.tox/
-.coverage
-.cache
-nosetests.xml
-coverage.xml

+ 0 - 3
web/.gitmodules

@@ -1,3 +0,0 @@
-[submodule "cleancss.git"]
-	path = cleancss.git
-	url = git://github.com/raylu/py-cleancss.git

+ 0 - 1
web/cleancss

@@ -1 +0,0 @@
-cleancss.git/cleancss

+ 1 - 0
web/cleancss

@@ -0,0 +1 @@
+Subproject commit ddc06e44b6022b279dfc5440a6cc30c5334d4866

+ 13 - 9
web/db.py

@@ -1,5 +1,6 @@
 import hashlib
 import hmac
+import binascii
 import os
 
 import tornado.gen
@@ -8,13 +9,13 @@ import momoko
 
 import config
 
-def hash_pw(password, key=None):
-	if key is None:
-		key = os.urandom(16)
-		digest = hmac.new(key, password, hashlib.sha256)
-		key = key.encode("hex")
-		hashed = digest.hexdigest()
-		return key, hashed
+def hash_pw(password, salt=None):
+	if salt is None:
+		salt = os.urandom(16)
+	h = hmac.new(salt, password.encode('utf-8'), hashlib.sha256)
+	hashed = h.hexdigest()
+	salt_hex = binascii.hexlify(salt).decode()
+	return hashed, salt_hex
 
 class MomokoDB:
 	db = momoko.Pool(dsn='dbname=%s user=%s' % (config.db.database, config.db.user), size=2)
@@ -26,7 +27,7 @@ class MomokoDB:
 
 	@tornado.gen.coroutine
 	def create_user(self, username, password):
-		salt, hashed_password = hash_pw(password)
+		hashed_password, salt = hash_pw(password)
 		query = 'INSERT INTO users (username, password, salt) VALUES (%s, %s, %s);'
 		yield self.execute(query, username, hashed_password, salt)
 
@@ -41,6 +42,9 @@ class MomokoDB:
 		user = yield self.get_user(username)
 		if not user:
 			return
-		_, hashed = hash_pw(password, user['salt'].decode("hex"))
+		salt = binascii.unhexlify(bytes(user['salt'], 'ascii'))
+		hashed, _ = hash_pw(password, salt)
+		print(hashed)
+		print(user['password'])
 		if hashed == user['password']:
 			return user

+ 2 - 2
web/schema.sql

@@ -3,7 +3,7 @@ DROP TABLE IF EXISTS users;
 CREATE TABLE users (
 	id serial PRIMARY KEY,
 	username varchar(32) NOT NULL,
-	password char(64) NOT NULL,
-	salt char(32) NOT NULL,
+	password varchar(64) NOT NULL,
+	salt varchar NOT NULL,
 	UNIQUE (username)
 );

+ 3 - 3
web/server.py

@@ -47,8 +47,8 @@ class RegisterHandler(BaseHandler):
 	def post(self):
 		username = self.get_argument("username", "")
 		password = self.get_argument("password", "")
-		yield db.create_user(username, password)
-		self.create_session(user['username'])
+		yield self.db.create_user(username, password)
+		self.create_session(username)
 		self.redirect("/")
 
 class LoginHandler(BaseHandler):
@@ -60,7 +60,7 @@ class LoginHandler(BaseHandler):
 	def post(self):
 		username = self.get_argument("username", "")
 		password = self.get_argument("password", "")
-		user = yield db.check_user(username, password)
+		user = yield self.db.check_user(username, password)
 		if not user:
 			self.render("login.html")
 		else:

+ 0 - 6
web/static/css/account.ccss

@@ -1,6 +0,0 @@
-textarea:
-	display: block
-	margin-top: 5px
-	width: 50%
-	height: 100px
-	font: inherit

+ 2 - 102
web/static/css/base.ccss

@@ -1,9 +1,9 @@
 *:
 	box-sizing: border-box
-
-body:
 	padding: 0
 	margin: 0
+
+body:
 	height: 100%
 	background: #fff
 	color: #777
@@ -11,103 +11,3 @@ body:
 
 a:
 	text-decoration: none
-	color: #00BFA8
-	border-bottom: 2px solid #00BFA8
-
-	&:hover:
-		color: #CB5847
-		border-color: #CB5847
-
-img:
-	border-radius: 4px
-	overflow: hidden
-
-form:
-	input, textarea:
-		border: 1px solid #eaeaea
-		padding: 15px
-		margin-bottom: 15px
-		border-radius: 4px
-		width: 100%
-
-	[type="button"], [type="submit"]:
-		width: auto
-		padding: 15px 30px
-		border-radius: 4px
-		cursor: pointer
-		background: #DC825F
-		color: #fff
-
-ul:
-	list-style: none
-	padding: 0
-	margin: 0
-
-	li:
-		padding: 15px
-		border-top: 1px solid #eaeaea
-
-.clear:
-	clear: both
-
-.wrapper:
-	width: 900px
-	margin: 0px auto
-
-#content:
-	padding: 15px 0px
-
-#topbar:
-	position: relative
-	padding: 30px 0px
-	background: #fff
-	border-bottom: 1px solid #eaeaea
-
-	a:
-		color: #777
-
-		&:hover:
-			color: #333
-
-	#title:
-		display: inline-block
-		
-		a:
-			border: none
-
-	#nav:
-		display: inline-block
-		vertical-align: middle
-		float: right
-
-		img:
-			width: 32px
-			height: 32px
-			margin-right: 15px
-			vertical-align: middle
-			display: inline-block
-			border-radius: 50%
-
-		a:
-			padding-right: 15px
-			vertical-align: middle
-			border: none
-
-			&:last-child:
-				padding-right: 0px
-
-		#user-nav:
-			margin-top: -7px
-
-#profile-avatar:
-	width: 200px
-	height: 200px
-
-.question:
-	margin-bottom: 15px
-	color: #333
-
-.answer:
-	margin-bottom: 30px
-	padding-left: 15px
-	border-left: 6px solid #ddd

+ 0 - 14
web/static/css/users.ccss

@@ -1,14 +0,0 @@
-.user_info:
-	padding: 15px 0px
-	border-top: 1px solid #eaeaea
-
-	img:
-		top: 5px
-		margin-right: 30px
-		width: 64px
-		height: 64px
-		display: inline-block
-		vertical-align: middle
-	
-	a:
-		vertical-align: middle

BIN
web/static/img/favicon.png


BIN
web/static/img/lpmc-logo.png


+ 0 - 30
web/static/js/account.js

@@ -1,30 +0,0 @@
-window.addEvent('domready', function() {
-	'use strict';
-
-	$('update_emails').addEvent('click', function() {
-		new Request.JSON({
-			'url': '/github_emails',
-			'onSuccess': function(response) {
-				var emails = $('emails');
-				response.each(function(email) {
-					var div = new Element('div');
-					div.appendText(email['email']);
-					div.addEvent('click', function() {
-						set_email(email['email']);
-					});
-					emails.grab(div, 'top');
-				});
-			},
-		}).get();
-	});
-
-	function set_email(email) {
-		new Request({
-			'url': '/account/contact_info',
-			'onSuccess': function(response) {
-				if (response)
-					location.reload();
-			},
-		}).post({'info_type': 0, 'info': email});
-	}
-});

+ 1 - 1
web/templates/base.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>
-	<title>LPMC</title>
+	<title>Sys Vitals</title>
 	<link rel="stylesheet" type="text/css" href="/css/base.css" />
 	<script src="//ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools.js"></script>
 	{% block js %}{% end %}