Beispiel #1
0
    def _doPost(self, dataObject):

        if "email" in dataObject and "password" in dataObject:
            UM = UserMapper()
            ATM = ApitokenMapper()

            # Build user and token objects
            user = User()

            if not checkEmail(dataObject["email"]):
                raise BadRequest("The e-mail supplied was invalid.")

            user.setEmail(dataObject["email"])
            user.setPreHash(dataObject["password"])
            user.setRegistered(True)

            token = Apitoken()

            token.setUser(user)
            token.setToken(getKey())

            # Save changes to user
            try:
                UM.insert(user)

            # handle the possibility the user already exists
            except mdb.IntegrityError, e:
                raise Conflict(
                    "A user with that e-mail address exists already.")

            # handle all other DB errors
            except mdb.DatabaseError, e:
                raise ServerError(
                    "Unable to create user in the database (%s)" % e.args[1])
Beispiel #2
0
    def _doPost(self, dataObject):

        if "email" in dataObject and "password" in dataObject:
            UM = UserMapper()
            ATM = ApitokenMapper()

            # Build user and token objects
            user = User()

            if not checkEmail(dataObject["email"]):
                raise BadRequest("The e-mail supplied was invalid.")

            user.setEmail(dataObject["email"])
            user.setPreHash(dataObject["password"])
            user.setRegistered(True)

            token = Apitoken()

            token.setUser(user)
            token.setToken(getKey())

            # Save changes to user
            try:
                UM.insert(user)

                # handle the possibility the user already exists
            except mdb.IntegrityError, e:
                raise Conflict("A user with that e-mail address exists already.")

                # handle all other DB errors
            except mdb.DatabaseError, e:
                raise ServerError("Unable to create user in the database (%s)" % e.args[1])
Beispiel #3
0
	def _doPost(self, dataObject):

		print str(dataObject)

		if "email" in dataObject and "password" in dataObject:
			try:

				UserMapper = UM.UserMapper()
				ApitokenMapper = ATM.ApitokenMapper()


				# Get the user by E-mail
				acidtest = UserMapper.getUserByEmail(dataObject["email"])

				if acidtest is None:
					user = User()

					if not checkEmail(dataObject["email"]):
						raise BadRequest("The e-mail supplied was invalid.")

					user.setEmail(dataObject["email"])
					user.setPreHash(dataObject["password"])

					token = Apitoken()

					token.setUser(user)
					token.setToken(getKey())

					user.setToken(token)

					UserMapper.insert(user)

					# Retrieve user with ID this time
					user = UserMapper.getUserByEmail(dataObject["email"])

					ApitokenMapper.insert(token)

					return self._response(token.dict(), CODE.CREATED)
				else:
					raise RequestError(CODE.CONFLICT, "A user with that e-mail address exists already.")
				
			except mdb.DatabaseError, e:
				import traceback, sys
				traceback.print_exc(file=sys.stdout)
				raise ServerError("Unable to search the user database (%s)" % e.args[1])
Beispiel #4
0
				ATM_ = ApitokenMapper()
				
				rdata["apitoken"] = ATM_.findTokenByUserId(selectedUser.getId()).getToken()
				rdata["user"] = selectedUser.dict(1)

				return self._response(rdata, CODE.CREATED)

			except mdb.DatabaseError, e:
				raise ServerError("Unable to get API key from the database (%s: %s)" % e.args[0], e.args[1])

		else:
			# Anonymous login
			rdata = {}

			token = Apitoken()
			token.setToken(getKey())
			

			blank = User()
			blank.setToken(token)
			token.setUser(blank)

			umapper = UserMapper()
			ATM = ApitokenMapper()

			blank.setRegistered(False)

			# Save changes to user
			try:
				umapper.insert(blank)
Beispiel #5
0
			# check we have a result
			if selectedUser is None:
				raise NotFound("We have no record of a user with the username %s" % username)

			# check password is correct	return corresponding key
			if not checkHash(password, selectedUser.getPassword()):
				raise Unauthorised("Failed to login with that username and password")

			try:
				data = {}
				ATM_ = ATM.ApitokenMapper()
				data["apitoken"] = ATM_.findTokenByUserId(selectUser.getId())

				return self.__response(201, data)

			except mdb.DatabaseError, e:
				raise ServerError("Unable to get API key from the database (%s: %s)" % e.args[0], e.args[1])

		else:
			# Anonymous login
			data = {}
			data["apitoken"] = getKey()

			return self.__response(201, data)

	def _doPut(self, url, dataObject):
		raise MethodNotAllowed()

	def _doDelete(self, url):
		raise MethodNotAllowed()