Esempio n. 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])
Esempio n. 2
0
    def _doCreateObject(self, data):
        """Builds the Apitoken object using the raw data provided from the database"""
        from Model.apitoken import Apitoken

        apitoken_ = Apitoken(data["id"])

        apitoken_.setToken(data["key"])
        apitoken_.setGroup(data["group_id"])

        umapper = UserMapper()
        apitoken_.setUser(umapper.find(data["user_id"]))

        return apitoken_
Esempio n. 3
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])
	def _doCreateObject(self, data):
		"""Builds the Apitoken object using the raw data provided from the database"""
		from Model.apitoken import Apitoken

		apitoken_ = Apitoken(data["id"])

		apitoken_.setToken(data["key"])
		apitoken_.setGroup(data["group_id"])
		
		umapper = UserMapper()
		apitoken_.setUser(umapper.find(data["user_id"]))

		return apitoken_
Esempio n. 5
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])
Esempio n. 6
0
				rdata = {}
				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)