Beispiel #1
0
def login(login, pwd):

	
	if(login is None) or (pwd is None):
		return jsonify(status="error", error_type="bad parameter")
	
	if(login == "") or (pwd == ""):
		return jsonify(status="error", error_type="empty parameter")

	reqUser = User(login)
	if(not reqUser.userExists(login)):
		return jsonify(status="error", error_type="no such user")
	

	if(reqUser.isUserBanned()):
		return jsonify(status="error", error_type="user banned", ban_time=reqUser.getBanTime())

	if(not reqUser.loginUser(pwd)):
		if(reqUser.shouldBeBanned()):
			reqUser.banUser()
			return jsonify(status="error", error_type="user banned", ban_time=reqUser.getBanTime())

		return jsonify(status="error", error_type="bad password")
	
	#user is logged in at this point	
	return jsonify(status="ok", info="user logged in", token = reqUser.updateToken())
Beispiel #2
0
def new_user(login, content):

	
	if "pwd" not in content:
		return jsonify(status="error", error_type="bad parameter", missing="pwd")

	#user credentials check
	ulogin = login
	upwd = content["pwd"]

	reqUser = User(ulogin)
	if(reqUser.userExists(ulogin)):
		return jsonify(status="error", error_type="user exists")
	
	print("adding user")
	reqUser.createUser(ulogin, upwd)
	return jsonify(status="ok", info="user created")
Beispiel #3
0
def answserPoll():
	content = request.json
	print(content)
	params = ["login", "token", "poll_id", "answer_id"]
	missing = []
	for p in params:
		if p not in content:
			missing.append(p)
	
	if len(missing) != 0:
		return jsonify(status="error", error_type="bad parameter", missing=missing)


	#user credentials check
	ulogin = content["login"]
	utoken = content["token"]
	upollId = content["poll_id"]
	answerId = content["answer_id"]

	reqUser = User(ulogin)

	if(not reqUser.userExists(ulogin)):
		return jsonify(status="error", error_type="no such user")
	
	if(not reqUser.loginUser(token=utoken)):
		return jsonify(status="error", error_type="bad token")


	#check poll integrity
	p = reqUser.getUserPoll(upollId, formated=False)
	if not p.pollExists(upollId):
		return jsonify(status="error", error_type="no such poll for user")


	if not reqUser.hasAnsweredPoll(upollId):
		return jsonify(status="error", error_type="previous user response to poll")	

	if not p.validAnswer(answerId):
		return jsonify(status="error", error_type="invalid answer ID")

	reqUser.answerUserPoll(upollId, answerId)
	return jsonify(status="ok", info="answered poll")
Beispiel #4
0
def polls():
	
	ulogin = request.args.get('login')
	utoken = request.args.get("token")


	if(ulogin is None) or (utoken is None):
		return jsonify(status="error", error_type="bad parameter")
	
	if ulogin == "" or utoken == "":
		return jsonify(status="error", error_type="empty parameters")
	
	reqUser = User(ulogin)
	if(not reqUser.userExists(login)):
		return jsonify(status="error", error_type="no such user")

	if(not reqUser.loginUser(token=utoken)):
		return jsonify(status="error", error_type="bad token")

	return Response(json.dumps(reqUser.getUserPolls()), mimetype='application/json')
Beispiel #5
0
def pollFromId(poll_id, login, methods=['GET']):
	# similar to /poll route

	utoken = request.args.get("token")
	if utoken is None:
		return jsonify(status="error", error_type="bad parameter")

	if utoken == "":
		return jsonify(status="error", error_type="empty parameters")
	
	reqUser = User(login)
	if(not reqUser.userExists(login)):
		return jsonify(status="error", error_type="no such user")
	
	if(not reqUser.loginUser(token=utoken)):
		return jsonify(status="error", error_type="bad token")

	p = reqUser.getUserPoll(poll_id)

	return jsonify(p)
Beispiel #6
0
def poll():

	ulogin = request.args.get('login')
	utoken = request.args.get("token")
	pollId = request.args.get("poll_id")

	if(ulogin is None) or (utoken is None) or (pollId is None):
		return jsonify(status="error", error_type="bad parameter")
	
	if ulogin == "" or utoken == "" or pollId == "":
		return jsonify(status="error", error_type="empty parameters")
	
	reqUser = User(ulogin)
	if(not reqUser.userExists(login)):
		return jsonify(status="error", error_type="no such user")
	

	if(not reqUser.loginUser(token=utoken)):
		return jsonify(status="error", error_type="bad token")

	p = reqUser.getUserPoll(pollId)

	return jsonify(p)
Beispiel #7
0
def new_user():

	content = request.json
	params = ["login", "pwd"]
	missing = []
	for p in params:
		if p not in content:
			missing.append(p)
	
	if len(missing) != 0:
		return jsonify(status="error", error_type="bad parameter", missing=missing)


	#user credentials check
	ulogin = content["login"]
	upwd = content["pwd"]

	reqUser = User(ulogin)
	if(reqUser.userExists(ulogin)):
		return jsonify(status="error", error_type="user exists")
	
	print("adding user")
	reqUser.createUser(ulogin, upwd)
	return jsonify(status="ok", info="user created")