Beispiel #1
0
def register():	
	if request.method == "POST":

		print "REGISTRATION"

		expire_date = datetime.now()
		expire_date = expire_date + timedelta(days=0, seconds=config.MAX_LIFE)
		
		username = request.form["username"]
		hashed_password = request.form["password"]
		
		cur_timestamp = datetime.now()
		cur_timestamp = str(cur_timestamp)
		cookie = hashlib.sha512(app.secret_key + username + cur_timestamp).hexdigest()

		db = DbController()
		if db.add_user(username, hashed_password, 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' : 'Username Is Already In Use.'}), status.HTTP_200_OK)
			return response
Beispiel #2
0
def register():	
	if request.method == "POST":
		expire_date = datetime.datetime.now()
		expire_date = expire_date + datetime.timedelta(days=config.MAX_LIFE)
		username = request.form["username"]
		hashed_password = request.form["password"]
		public_key = request.files["public_key"]
		public_key_data = public_key.stream.read().decode('utf-8').strip()

		cur_timestamp = datetime.datetime.now()
		cookie = hashlib.sha512(app.secret_key + username + hashed_password + str(cur_timestamp)).hexdigest()

		db = DbController()
		if db.add_user(username, hashed_password, cookie, public_key_data):
			response = make_response(redirect("/home"))
			response.set_cookie("username", value=cookie, expires=expire_date)
			return response, json.dumps({'success' : True})
		else :
			response = make_response(redirect(""))
			return response, json.dumps({'success' : False, 'error' : 'Username Is Already In Use.'})