Пример #1
0
def handleLoginRequest(request):
	# loginfo(request.get_full_path())
	post = request.POST

	email = post.get('email')
	password = post.get('password')

	loginfo("login request")
	loginfo("email: " + email)

	user = models.get_user_via_email(email)
	if user is None:
		loginfo("user is none")

	result = {}
	if user and user.password == password:
		cookie = models.generate_cookie(user.id)
		loginfo(str(cookie.id))
		result['id'] = cookie.id
		result['token'] = cookie.token
		result['userId'] = cookie.userId
		loginfo('login successful: ')
		loginfo('id: ' + str(cookie.userId))
		loginfo('token: ' + cookie.token)
		return HttpResponse(json.dumps(result))
	else:
		logerror('login failed')
		return HttpResponseBadRequest()
Пример #2
0
def handleRegisterRequest(request):

	put = request.REQUEST

	user = models.User()
	user.name = put.get('name')
	user.email = put.get('email')
	user.password = put.get('password')
	user.last_name = put.get('last_name')

	loginfo("register: " + "email " + user.email)

	if models.get_user_via_email(user.email):
		logerror("user with this email is existing")
		return HttpResponseBadRequest()
	user.save()
	loginfo("user registered")
	return HttpResponse()