def doShowMore(self): """Show the more dialog.""" # Trigger the login dialog if we detect a change to client_id or # client_secret. pre_client_id = settings.read('gmeconnector/CLIENT_ID') pre_client_secret = settings.read('gmeconnector/CLIENT_SECRET') self.moreDialog = more_dialog.Dialog(self.iface) if self.token: self.moreDialog.groupBoxAccount.setEnabled(True) self.moreDialog.populateProjects() else: self.moreDialog.groupBoxAccount.setEnabled(False) self.moreDialog.exec_() # Read the client_id and client_secret again to compare. post_client_id = settings.read('gmeconnector/CLIENT_ID') post_client_secret = settings.read('gmeconnector/CLIENT_SECRET') # If both client_id and client_secret are not empty and if either one has # changed, trigger the sign-in dialog. if (post_client_id and post_client_secret and (post_client_id != pre_client_id or post_client_secret != pre_client_secret)): self.signInDlg.setInitialUrl() result = self.signInDlg.exec_() if not result: self.handleAuthChange(False, None, '')
def doSignInOrOut(self, checked): """Show the sign-in dialog and manage authentication status. Args: checked: bool, whether the sign-in action was checked. """ if checked: # check if client_id and client_secret exist client_id = settings.read('gmeconnector/CLIENT_ID') client_secret = settings.read('gmeconnector/CLIENT_SECRET') if client_id and client_secret: token = oauth2_utils.getToken() if token: self.token = token self.handleAuthChange(True, token, '') else: # The sign-in dialog is initialized when the plugin is loaded. # We need to have setInitialUrl outside the dialog constructor to make # sure it's called everytime the sign-in button is clicked. self.signInDlg.setInitialUrl() result = self.signInDlg.exec_() if not result: self.handleAuthChange(False, None, '') else: self.signIn.setChecked(False) warnText = ('You must enter valid OAuth2.0 Client ID ' 'and Client secret in Advanced Settings.') QMessageBox.warning(self.iface.mainWindow(), 'Warning', warnText) self.doShowMore() else: self.token = None self.signIn.setText('Logged out. Click to log in.') self.signIn.setChecked(False) self.disableAllTools() # Revoke the token oauth2_utils.revokeToken() # Remove the access credientials from settings settings.clear()