def addUser(): if not userManager.enabled: return jsonify(SUCCESS) 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) name = data["name"] password = data["password"] active = data["active"] roles = ["user"] if "admin" in data.keys() and data["admin"]: roles.append("admin") try: userManager.addUser(name, password, active, roles) except users.UserAlreadyExists: abort(409) return getUsers()
def addUser(): if not userManager.enabled: return jsonify(SUCCESS) if not "application/json" in request.headers["Content-Type"]: return make_response("Expected content-type JSON", 400) try: data = request.get_json() except BadRequest: return make_response("Malformed JSON body in request", 400) if data is None: return make_response("Malformed JSON body in request", 400) if not "name" in data: return make_response("Missing mandatory name field", 400) if not "password" in data: return make_response("Missing mandatory password field", 400) if not "active" in data: return make_response("Missing mandatory active field", 400) name = data["name"] password = data["password"] active = data["active"] in valid_boolean_trues roles = ["user"] if "admin" in data and data["admin"] in valid_boolean_trues: roles.append("admin") try: userManager.addUser(name, password, active, roles) except users.UserAlreadyExists: abort(409) return getUsers()
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
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
def addUser(): if userManager is None: return jsonify(SUCCESS) if "application/json" in request.headers["Content-Type"]: data = request.json name = data["name"] password = data["password"] active = data["active"] roles = ["user"] if "admin" in data.keys() and data["admin"]: roles.append("admin") try: userManager.addUser(name, password, active, roles) except users.UserAlreadyExists: abort(409) return getUsers()
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
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
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