Exemplo n.º 1
0
    def add_user(self):
        for key, value in config_loader(dataset="MSC_login", default={}).items():
            if key not in constants.MSC_LOGIN_CACHE:
                constants.MSC_LOGIN_CACHE[key] = value
        auth = constants.MSC_LOGIN_CACHE.get(self.mscolab_server_url, (None, None))

        emailid = self.add_user_dialog.emailid.text()
        password = self.add_user_dialog.password.text()
        re_password = self.add_user_dialog.rePassword.text()
        username = self.add_user_dialog.username.text()
        if password == re_password:
            data = {
                "email": emailid,
                "password": password,
                "username": username
            }
            s = requests.Session()
            s.auth = (auth[0], auth[1])
            s.headers.update({'x-test': 'true'})
            url = '{}/register'.format(self.mscolab_server_url)
            r = s.post(url, data=data)
            if r.status_code == 401:
                r = self.authenticate(data, r, url)
                if r.status_code == 201:
                    constants.MSC_LOGIN_CACHE[self.mscolab_server_url] = (username, password)
            if r.status_code == 201:
                self.error_dialog = QtWidgets.QErrorMessage()
                self.error_dialog.showMessage('You are registered, you can now log in.')
            else:
                self.error_dialog = QtWidgets.QErrorMessage()
                self.error_dialog.showMessage(r.json()["message"])
        else:
            self.error_dialog = QtWidgets.QErrorMessage()
            self.error_dialog.showMessage('Oh no, your passwords don\'t match')
Exemplo n.º 2
0
    def add_project(self):
        path = self.add_proj_dialog.path.text()
        description = self.add_proj_dialog.description.toPlainText()
        if not path:
            self.error_dialog = QtWidgets.QErrorMessage()
            self.error_dialog.showMessage('Path can\'t be empty')
            return
        elif not description:
            self.error_dialog = QtWidgets.QErrorMessage()
            self.error_dialog.showMessage('Description can\'t be empty')
            return

        data = {
            "token": self.token,
            "path": path,
            "description": description
        }
        if self.add_proj_dialog.f_content is not None:
            data["content"] = self.add_proj_dialog.f_content
        r = requests.post('{}/create_project'.format(self.mscolab_server_url), data=data)
        if r.text == "True":
            self.error_dialog = QtWidgets.QErrorMessage()
            self.error_dialog.showMessage('Your project was created successfully')
            self.add_projects()
            p_id = self.get_recent_pid()
            self.conn.handle_new_room(p_id)
        else:
            self.error_dialog = QtWidgets.QErrorMessage()
            self.error_dialog.showMessage('The path already exists')
Exemplo n.º 3
0
 def authorize(self):
     for key, value in config_loader(dataset="MSC_login", default={}).items():
         if key not in constants.MSC_LOGIN_CACHE:
             constants.MSC_LOGIN_CACHE[key] = value
     auth = constants.MSC_LOGIN_CACHE.get(self.mscolab_server_url, (None, None))
     # get mscolab /token http auth credentials from cache
     emailid = self.emailid.text()
     password = self.password.text()
     data = {
         "email": emailid,
         "password": password
     }
     s = requests.Session()
     s.auth = (auth[0], auth[1])
     s.headers.update({'x-test': 'true'})
     url = self.mscolab_server_url + '/token'
     r = s.post(url, data=data)
     if r.status_code == 401:
         r = self.authenticate(data, r, url)
         if r.status_code == 200:
             constants.MSC_LOGIN_CACHE[self.mscolab_server_url] = (auth[0], auth[1])
             self.after_authorize(emailid, r)
     elif r.text == "False":
         # popup that has wrong credentials
         self.error_dialog = QtWidgets.QErrorMessage()
         self.error_dialog.showMessage('Oh no, your credentials were incorrect.')
     else:
         # remove the login modal and put text there
         self.after_authorize(emailid, r)
Exemplo n.º 4
0
 def add_project_handler(self):
     if self.token is None:
         self.error_dialog = QtWidgets.QErrorMessage()
         self.error_dialog.showMessage('Please login to use this feature')
         return
     else:
         logging.debug(self.token)
     self.proj_diag = QtWidgets.QDialog()
     self.add_proj_dialog = add_project_ui.Ui_addProjectDialog()
     self.add_proj_dialog.setupUi(self.proj_diag)
     self.add_proj_dialog.f_content = None
     self.add_proj_dialog.buttonBox.accepted.connect(self.add_project)
     self.add_proj_dialog.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
     self.add_proj_dialog.path.textChanged.connect(self.check_and_enable_project_accept)
     self.add_proj_dialog.description.textChanged.connect(self.check_and_enable_project_accept)
     self.add_proj_dialog.browse.clicked.connect(self.set_exported_file)
     self.proj_diag.show()
Exemplo n.º 5
0
 def show_info(self, text):
     self.error_dialog = QtWidgets.QErrorMessage()
     self.error_dialog.showMessage(text)