Beispiel #1
0
    def loginPress(self):
        #check the match of user name and password
        login = self.__view.getLogin().encode('utf8')
        password = self.__view.getPassword().encode('utf8')
        logging.debug("Login %s, Password %s ", login, password)

        try:
            self.__userConfig.loadUserConfig(login, password)
        except WrongUserException:
            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_value'),
                text=self.__localization.getWord('you_entered_wrong_login'),
                buttonsText=[self.__localization.getWord('ok')])
            return
        except WrongPasswordException:
            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_value'),
                text=self.__localization.getWord('you_entered_wrong_password'),
                buttonsText=[self.__localization.getWord('ok')])
            return

        #send signal about successful logging and pass login and password
        self.__view.destroy()
        self.__notifier.sendSignal(Signal.LOGIN_OK, [login, password])
    def addExistingDB(self, data):
        logging.debug("Add existing DB with parameters {}".format(data))
        #add to config
        self.__userConfig.addDBForCurrentUser(data[DataField.PATH],
                                              data[DataField.PASSWORD])
        try:
            #add to DB manager
            db = self.__dbManager.registerDB(data[DataField.PATH],
                                             data[DataField.PASSWORD])
            #add to panel
            categoryPanel = self.__view.getCategoryPanel()
            categoryPanel.tree.insert(
                "",
                'end',
                db.id,
                text=db.path,
                image=self.__getImage('db_disconnected_image'),
                open=True)
        except Exceptions.DataBaseException:
            md.showError(self.__view,
                         title=self.__localization.getWord('invalid_value'),
                         text=self.__localization.getWord('db_exist'),
                         buttonsText=[self.__localization.getWord('ok')])

        logging.debug("Existing DB {} successfully added".format(data))
 def checkUserValues(self, path, name, password, comments):
     if not self.__dbManager.checkEntryData(path, DataField.PATH):
         md.showError(self.__view, 
                         title = self.__localization.getWord('invalid_value'),
                         text = "{} {}".format(self.__localization.getWord('path'), self.__localization.getWord('contains_invalid_value')), 
                         buttonsText=[self.__localization.getWord('ok')])
         return False
     
     if not self.__dbManager.checkEntryData(name, DataField.NAME):
         md.showError(self.__view, 
                         title = self.__localization.getWord('invalid_value'),
                         text = "{} {}".format(self.__localization.getWord('db_name'), self.__localization.getWord('contains_invalid_value')), 
                         buttonsText=[self.__localization.getWord('ok')])
         return False
     
     if not self.__dbManager.checkEntryData(password, DataField.PASSWORD):
         md.showError(self.__view, 
                         title = self.__localization.getWord('invalid_value'),
                         text = "{} {}".format(self.__localization.getWord('password'), self.__localization.getWord('contains_invalid_value')), 
                         buttonsText=[self.__localization.getWord('ok')])
         return False
     
     if not self.__dbManager.checkEntryData(comments, DataField.COMMENTS):
         md.showError(self.__view, 
                         title = self.__localization.getWord('invalid_value'),
                         text = "{} {}".format(self.__localization.getWord('comments'), self.__localization.getWord('contains_invalid_value')), 
                         buttonsText=[self.__localization.getWord('ok')])
         return False   
     
     return True    
Beispiel #4
0
 def checkUserValues(self, path, password):
     #check path
     if not self.__dbManager.dbPathUniqueCheck(path):
         md.showError(self.__view, 
                         title = self.__localization.getWord('invalid_value'),
                         text = self.__localization.getWord('db_exist'), 
                         buttonsText=[self.__localization.getWord('ok')])
         return False
     
     #check password
     if not self.__dbManager.checkEntryData(password, DataField.PASSWORD):
         md.showError(self.__view, 
                         title = self.__localization.getWord('invalid_value'),
                         text = "{} {}".format(self.__localization.getWord('password'), self.__localization.getWord('contains_invalid_value')), 
                         buttonsText=[self.__localization.getWord('ok')])
         return False 
     
     return True            
    def _doFieldsCheck(self, name, comments):
        if not self.__dbManager.checkEntryData(name, DataField.NAME):
            md.showError(
                self._view,
                title=self.__localization.getWord('invalid_value'),
                text="{} {}".format(
                    self.__localization.getWord('name'),
                    self.__localization.getWord('contains_invalid_value')),
                buttonsText=[self.__localization.getWord('ok')])
            return False

        if not self.__dbManager.checkEntryData(comments, DataField.COMMENTS):
            md.showError(
                self._view,
                title=self.__localization.getWord('invalid_value'),
                text="{} {}".format(
                    self.__localization.getWord('comments'),
                    self.__localization.getWord('contains_invalid_value')),
                buttonsText=[self.__localization.getWord('ok')])
            return False

        return True
 def addNewDB(self, data):
     logging.debug("Add new DB with data {}".format(data))
     try:
         #create new DB add add it to DB manager
         #path, name, password, comments='')
         db = self.__dbManager.createDB(**data)
         #add new DB to config
         self.__userConfig.addDBForCurrentUser(data[DataField.PATH],
                                               data[DataField.PASSWORD])
         #add to the panel
         categoryPanel = self.__view.getCategoryPanel()
         categoryPanel.tree.insert(
             "",
             'end',
             db.id,
             text=db.path,
             image=self.__getImage('db_disconnected_image'),
             open=True)
     except Exceptions.DataBaseException:
         md.showError(self.__view,
                      title=self.__localization.getWord('invalid_value'),
                      text=self.__localization.getWord('db_exist'),
                      buttonsText=[self.__localization.getWord('ok')])
    def connectDB(self, data):
        """
        Connect to the given database
        @type data: DataBase
        @param data: reference of the database to which to connect
        """
        logging.debug("Connecting to DB {}".format(data))
        db = self.__getCurrDB()
        #do checks
        if not db:
            return
        if db.status == DBStatus.CONNECTED:
            return
        categoryPanel = self.__view.getCategoryPanel()
        try:
            db.connect()
            #load root content to panels
            self.__loadSubcategoriesToPanel(db.id, None)
            self.__loadRecordsToPanel(db.id, None)
            #change DB image to connected
            categoryPanel.tree.item(
                db.id, open=True, image=self.__getImage('db_connected_image'))
            #change text to db name if setting
            if (self.__userConfig.getCurrentUserSetting(
                    DataField.CHANGE_DB_PATH_TO_NAME_AFTER_CONN)):
                categoryPanel.tree.item(db.id, text=db.name)

            self.__notifier.sendSignal(Signal.DB_SELECTED_CHANGED, db)

        except Exceptions.NoFileException:
            md.showError(self.__view,
                         title=self.__localization.getWord('invalid_value'),
                         text="{} {} {}".format(
                             self.__localization.getWord('database_with_file'),
                             db.path, self.__localization.getWord('no_exist')),
                         buttonsText=[self.__localization.getWord('ok')])

        except Exceptions.DataBaseException:
            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_value'),
                text="{} {} {}".format(
                    self.__localization.getWord('can_not_connect_to_db'),
                    db.path, self.__localization.getWord('corrupted')),
                buttonsText=[self.__localization.getWord('ok')])
        except Exceptions.WrongPasswordException:
            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_value'),
                text=self.__localization.getWord('wrong_password_provided'),
                buttonsText=[self.__localization.getWord('ok')])
    def _checkData(self):
        """Check if the user provided valid data"""
        #get the values from entries
        site = self._view.getSite()
        if len(site) == 0:
            md.showError(self._view, 
                            title = self.__localization.getWord('invalid_value'),
                            text = self.__localization.getWord('site_empty'), 
                            buttonsText=[self.__localization.getWord('ok')])

            return False
            
        if not self.__dbManager.checkEntryData(site, DataField.SITE):
            md.showError(self._view, 
                            title = self.__localization.getWord('invalid_value'),
                            text = "{} {}".format(self.__localization.getWord('site'), self.__localization.getWord('contains_invalid_value')), 
                            buttonsText=[self.__localization.getWord('ok')])
            return False
                           
        username = self._view.getSite() 
        if not self.__dbManager.checkEntryData(username, DataField.USERNAME):
            md.showError(self._view, 
                            title = self.__localization.getWord('invalid_value'),
                            text = "{} {}".format(self.__localization.getWord('username'), self.__localization.getWord('contains_invalid_value')), 
                            buttonsText=[self.__localization.getWord('ok')])
            return False
                   
        email = self._view.getEmail()
        if not self.__dbManager.checkEntryData(email, DataField.EMAIL):
            md.showError(self._view, 
                            title = self.__localization.getWord('invalid_value'),
                            text = "{} {}".format(self.__localization.getWord('email'), self.__localization.getWord('contains_invalid_value')), 
                            buttonsText=[self.__localization.getWord('ok')])
            return False
                 
        password = self._view.getPassword()
        if not self.__dbManager.checkEntryData(password, DataField.PASSWORD):
            md.showError(self._view, 
                            title = self.__localization.getWord('invalid_value'),
                            text = "{} {}".format(self.__localization.getWord('password'), self.__localization.getWord('contains_invalid_value')), 
                            buttonsText=[self.__localization.getWord('ok')])
            return False   
            
        comments = self._view.getComments()
        if not self.__dbManager.checkEntryData(comments, DataField.COMMENTS):
            md.showError(self._view, 
                            title = self.__localization.getWord('invalid_value'),
                            text = "{} {}".format(self.__localization.getWord('comments'), self.__localization.getWord('contains_invalid_value')), 
                            buttonsText=[self.__localization.getWord('ok')])
            return False 
        
        return True       
 def notImplementedYet(self, data):
     md.showError(self.__view,
                  title=self.__localization.getWord('not_implemented'),
                  text=self.__localization.getWord('not_yet_available'),
                  buttonsText=[self.__localization.getWord('ok')])
    def registerPress(self):
        #get entered information
        login = self.__view.getLoginEntry().get()
        password = self.__view.getPasswordEntry().get()
        confirmPassword = self.__view.getConfirmPasswordEntry().get()
        #check if not 0 in length
        if len(login) == 0:
            #showerror(self.__localization.getWord('invalid_login'),
            #          self.__localization.getWord('login_at_least_1_symbol'))

            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_value'),
                text=self.__localization.getWord('login_at_least_1_symbol'),
                buttonsText=[self.__localization.getWord('ok')])
            return
        #check if user doesn't contains correct symbols
        if not self.__userConfig.checkNewLogin(login):
            #             showerror(self.__localization.getWord('invalid_symbols'),
            #                       "{}. \n{} {}".format(
            #                                            self.__localization.getWord('login_contains_invalid_symbols'),
            #                                            self.__localization.getWord('should_be_only'),
            #                                            self.__localization.getWord('login_valid_symbols')
            #                                            ))

            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_value'),
                text="{} {}. \n{} {}".format(
                    self.__localization.getWord('login'),
                    self.__localization.getWord('contains_invalid_value'),
                    self.__localization.getWord('should_be_only'),
                    self.__localization.getWord('login_valid_symbols')),
                buttonsText=[self.__localization.getWord('ok')])
            return
        #check if there is no such user in the config DB
        if self.__userConfig.userExist(login):
            #showerror(self.__localization.getWord('duplicate_login'),
            #          self.__localization.getWord('user_exist'))
            md.showError(self.__view,
                         title=self.__localization.getWord('duplicate_login'),
                         text=self.__localization.getWord('user_exist'),
                         buttonsText=[self.__localization.getWord('ok')])
            return

        #check length of the password
        if len(password) == 0:
            #showerror(self.__localization.getWord('invalid_password'),
            #          self.__localization.getWord('password_at_least_1_symbol'))
            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_password'),
                text=self.__localization.getWord('password_at_least_1_symbol'),
                buttonsText=[self.__localization.getWord('ok')])
            return

        #check if the password contains correct symbols
        if not self.__userConfig.checkNewPassword(password):
            #             showerror(self.__localization.getWord('invalid_symbols'),
            #                       "{}. \n{} {}".format(
            #                                            self.__localization.getWord('password_contains_invalid_symbols'),
            #                                            self.__localization.getWord('should_be_only'),
            #                                            self.__localization.getWord('password_valid_symbols')
            #                                            ))
            md.showError(
                self.__view,
                title=self.__localization.getWord('invalid_symbols'),
                text="{} {}. \n{} {}".format(
                    self.__localization.getWord('password'),
                    self.__localization.getWord('contains_invalid_value'),
                    self.__localization.getWord('should_be_only'),
                    self.__localization.getWord('password_valid_symbols')),
                buttonsText=[self.__localization.getWord('ok')])
            return

        #check if password and confirm match
        if password != confirmPassword:
            #showerror(self.__localization.getWord('mismatch'),
            #           self.__localization.getWord('password_confirm_mismatch') )
            md.showError(
                self.__view,
                title=self.__localization.getWord('mismatch'),
                text=self.__localization.getWord('password_confirm_mismatch'),
                buttonsText=[self.__localization.getWord('ok')])
            return

        #add new user
        try:
            self.__userConfig.addNewUser(login, password)
        except Exceptions.NotUniqueValueException:
            #showerror(self.__localization.getWord('duplicate_login'),
            #           self.__localization.getWord('user_exist'))
            md.showError(self.__view,
                         title=self.__localization.getWord('duplicate_login'),
                         text=self.__localization.getWord('user_exist'),
                         buttonsText=[self.__localization.getWord('ok')])
            return

        #send signal
        self.__notifier.sendSignal(Signal.NEW_USER_REGISTER_OK,
                                   (login, password))
        #close register dialog
        self.__view.destroy()