예제 #1
0
	def post(self):
		try:
			post_body = json.decode(self.request.body)
			email = post_body['email']

			existing = User.query(User.email == email).fetch(1)
			if len(existing) > 0:
				error_response(self, "A user with this email has already been registered.")
				return

			user = User()
			user.first_name = post_body['firstName']
			user.last_name = post_body['lastName']
			user.email = email
			user.set_password(post_body['password'])
			user.put()
			self.response.headers['Content-Type'] = 'application/json'
			self.response.write(json.encode({"token": user.generate_JWT()}))
		except:
			error_response(self, "Please enter 'email', 'firstName', 'lastName' and 'password'.")
예제 #2
0
	def post(self):
		post_body = json.decode(self.request.body)
		post_fields = post_body.keys()

		if not ('email' in post_fields and 'password' in post_fields):
			error_response(self, "Please enter both 'email' and 'password'.")
			return

		email = post_body['email']
		password = post_body['password']

		try:
			user = User.query(User.email == email).fetch()[0]
		except:
			error_response(self, "Invalid email / password.")
			return

		if user.valid_password(password):
			self.response.headers['Content-Type'] = 'application/json'
			self.response.write(json.encode({"token": user.generate_JWT()}))
		else:
			error_response(self, "Invalid email / password.")