Esempio n. 1
0
def welcome():
	if request.method == "GET":
		db = DbController()
		db.create_user_table()
		print request.cookies
		if request.cookies.get("username"):
			return redirect("/home")
		return render_template("/html/index.html")
Esempio n. 2
0
		print hashed_password

		if db.verify_user(username, hashed_password):
			cur_timestamp = datetime.now()
			cur_timestamp = str(cur_timestamp)
			cookie = hashlib.sha512(app.secret_key + username + cur_timestamp).hexdigest()
			db.update_cookie(username, cookie, cur_timestamp)
			response = make_response(json.dumps({'success' : True, "cookie": cookie, 'time_stamp': cur_timestamp, 'expire_date': str(expire_date)}), status.HTTP_200_OK)
			
			cookie_data = {"username": username, "user_cookie": cookie, "time_stamp": cur_timestamp}
			response.set_cookie("cookie_data", value=json.dumps(cookie_data), expires=expire_date, max_age=config.MAX_LIFE)
			return response
		else :
			response = make_response(json.dumps({'success' : False, 'error' : 'Incorrect Password'}), status.HTTP_200_OK)
			return response


@app.route("/logout", methods=["GET"])
def logout():
	if request.method == "GET":
		db = DbController()
		response = make_response(redirect("/"))
		response.set_cookie("cookie_data", expires=0)
		return response

if __name__ == "__main__":
	db = DbController()
	db.create_user_table()
	db.create_nonce_table()
	app.run(config.SERVER_HOST, config.SERVER_PORT)