示例#1
0
    def signin(self, email, password, hasSessionContext=True):
        from octoprint.server import userManager
        from astroprint.network.manager import networkManager
        user = None
        userLoggedIn = False

        online = networkManager().isOnline()

        if online:
            private_key = self.get_private_key(email, password)

            if private_key:
                public_key = self.get_public_key(email, private_key)

                if public_key:
                    #Let's protect the box now:
                    user = userManager.findUser(email)

                    if user:
                        userManager.changeUserPassword(email, password)
                        userManager.changeCloudAccessKeys(
                            email, public_key, private_key)
                    else:
                        user = userManager.addUser(email, password, public_key,
                                                   private_key, True)

                    userLoggedIn = True

        else:
            user = userManager.findUser(email)
            userLoggedIn = user and user.check_password(
                userManager.createPasswordHash(password))

        if userLoggedIn:
            if hasSessionContext:
                login_user(user, remember=True)

            userId = user.get_id()

            self.settings.set(["cloudSlicer", "loggedUser"], userId)
            self.settings.save()

            boxrouterManager().boxrouter_connect()

            if hasSessionContext:
                identity_changed.send(current_app._get_current_object(),
                                      identity=Identity(userId))

            #let the singleton be recreated again, so new credentials are taken into use
            global _instance
            _instance = None

            eventManager().fire(Events.LOCK_STATUS_CHANGED, userId)

            return True

        elif not online:
            raise AstroPrintCloudNoConnectionException()

        return False
示例#2
0
def changePasswordForUser(username):
    if not userManager.enabled:
        return jsonify(SUCCESS)

    if current_user is not None and not current_user.is_anonymous() and (
            current_user.get_name() == username or current_user.is_admin()):
        if not "application/json" in request.headers["Content-Type"]:
            return make_response("Expected content-type JSON", 400)

        try:
            data = request.json
        except BadRequest:
            return make_response("Malformed JSON body in request", 400)

        if not "password" in data.keys() or not data["password"]:
            return make_response("password is missing from request", 400)

        try:
            userManager.changeUserPassword(username, data["password"])
        except users.UnknownUser:
            return make_response(("Unknown user: %s" % username, 404, []))

        return jsonify(SUCCESS)
    else:
        return make_response(("Forbidden", 403, []))
示例#3
0
	def signin(self, email, password, hasSessionContext = True):
		from octoprint.server import userManager
		from astroprint.network.manager import networkManager
		user = None
		userLoggedIn = False

		online = networkManager().isOnline()

		if online:
			private_key = self.get_private_key(email, password)

			if private_key:
				public_key = self.get_public_key(email, private_key)

				if public_key:
					#Let's protect the box now:
					user = userManager.findUser(email)

					if user:
						userManager.changeUserPassword(email, password)
						userManager.changeCloudAccessKeys(email, public_key, private_key)
					else:
						user = userManager.addUser(email, password, public_key, private_key, True)

					userLoggedIn = True

		else:
			user = userManager.findUser(email)
			userLoggedIn = user and user.check_password(userManager.createPasswordHash(password))

		if userLoggedIn:
			if hasSessionContext:
				login_user(user, remember=True)

			userId = user.get_id()

			self.settings.set(["cloudSlicer", "loggedUser"], userId)
			self.settings.save()

			boxrouterManager().boxrouter_connect()

			if hasSessionContext:
				identity_changed.send(current_app._get_current_object(), identity=Identity(userId))

			#let the singleton be recreated again, so new credentials are taken into use
			global _instance
			_instance = None

			eventManager().fire(Events.LOCK_STATUS_CHANGED, userId)

			return True

		elif not online:
			raise AstroPrintCloudNoConnectionException()

		return False
示例#4
0
    def validatePassword(self, email, password):
        from octoprint.server import userManager
        user = None
        userValidated = False

        online = networkManager().isOnline()

        if online:
            try:
                data_private_key = self.get_private_key(email, password)

                if data_private_key:
                    private_key = data_private_key['private_key']
                    public_key = self.get_public_key(email, private_key)
                    orgId = data_private_key['organization_id']
                    groupId = data_private_key['group_id']

                    if public_key:
                        #Let's update the box now:
                        user = userManager.findUser(email)
                        if user:
                            userManager.changeUserPassword(email, password)
                            userManager.changeCloudAccessKeys(
                                email, public_key, private_key, orgId, groupId)
                        else:
                            user = userManager.addUser(email, password,
                                                       public_key, private_key,
                                                       orgId, groupId, True)

                        userValidated = True

                    else:
                        return False

                else:
                    return False

            except ConnectionError as e:
                self._logger.error(
                    'Connection error when trying to validate password: %s' %
                    e)

        # was offline or couldn't reach astroprint.com
        if not userValidated:
            user = userManager.findUser(email)
            userValidated = user and user.check_password(
                userManager.createPasswordHash(password))

        if userValidated:
            userId = user.get_id()
            self.settings.set(["cloudSlicer", "loggedUser"], userId)
            self.settings.save()

        return userValidated
示例#5
0
def changePasswordForUser(username):
	if userManager is None:
		return jsonify(SUCCESS)

	if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
		if "application/json" in request.headers["Content-Type"]:
			data = request.json
			if "password" in data.keys() and data["password"]:
				try:
					userManager.changeUserPassword(username, data["password"])
				except users.UnknownUser:
					return make_response(("Unknown user: %s" % username, 404, []))
		return jsonify(SUCCESS)
	else:
		return make_response(("Forbidden", 403, []))
示例#6
0
	def validatePassword(self, email, password):
		from octoprint.server import userManager
		from astroprint.network.manager import networkManager
		user = None
		userValidated = False

		online = networkManager().isOnline()

		if online:
			try:
				private_key = self.get_private_key(email, password)

				if private_key:
					public_key = self.get_public_key(email, private_key)

					if public_key:
						#Let's update the box now:
						user = userManager.findUser(email)
						if user:
							userManager.changeUserPassword(email, password)
							userManager.changeCloudAccessKeys(email, public_key, private_key)
						else:
							user = userManager.addUser(email, password, public_key, private_key, True)

						userValidated = True

					else:
						return False

				else:
					return False

			except ConnectionError as e:
				self._logger.error('Connection error when trying to validate password: %s' % e)

		# was offline or couldn't reach astroprint.com
		if not userValidated:
			user = userManager.findUser(email)
			userValidated = user and user.check_password(userManager.createPasswordHash(password))

		if userValidated:
			userId = user.get_id()
			self.settings.set(["cloudSlicer", "loggedUser"], userId)
			self.settings.save()

		return userValidated
示例#7
0
def changePasswordForUser(username):
    if userManager is None:
        return jsonify(SUCCESS)

    if current_user is not None and not current_user.is_anonymous and (
            current_user.get_name() == username or current_user.is_admin()):
        if "application/json" in request.headers["Content-Type"]:
            data = request.json
            if "password" in data.keys() and data["password"]:
                try:
                    userManager.changeUserPassword(username, data["password"])
                except users.UnknownUser:
                    return make_response(
                        ("Unknown user: %s" % username, 404, []))
        return jsonify(SUCCESS)
    else:
        return make_response(("Forbidden", 403, []))
示例#8
0
def changePasswordForUser(username):
	if not userManager.enabled:
		return jsonify(SUCCESS)

	if current_user is not None and not current_user.is_anonymous() and (current_user.get_name() == username or current_user.is_admin()):
		if not "application/json" in request.headers["Content-Type"]:
			return make_response("Expected content-type JSON", 400)

		try:
			data = request.json
		except BadRequest:
			return make_response("Malformed JSON body in request", 400)

		if not "password" in data.keys() or not data["password"]:
			return make_response("password is missing from request", 400)

		try:
			userManager.changeUserPassword(username, data["password"])
		except users.UnknownUser:
			return make_response(("Unknown user: %s" % username, 404, []))

		return jsonify(SUCCESS)
	else:
		return make_response(("Forbidden", 403, []))
示例#9
0
	def validatePassword(self, email, password):
		from octoprint.server import userManager
		from astroprint.network.manager import networkManager
		user = None
		userValidated = False

		online = networkManager().isOnline()

		if online:
			private_key = self.get_private_key(email, password)

			if private_key:
				public_key = self.get_public_key(email, private_key)

				if public_key:
					#Let's update the box now:
					user = userManager.findUser(email)
					if user:
						userManager.changeUserPassword(email, password)
						userManager.changeCloudAccessKeys(email, public_key, private_key)
					else:
						user = userManager.addUser(email, password, public_key, private_key, True)

					userValidated = True

		else:
			user = userManager.findUser(email)
			userValidated = user and user.check_password(userManager.createPasswordHash(password))

		if userValidated:
			userId = user.get_id()
			self.settings.set(["cloudSlicer", "loggedUser"], userId)
			self.settings.save()


		return userValidated