Beispiel #1
0
    def login(self):
        """Ask the ui to display the login form to the user.

		Validate the results, and return True if validation succeeds.
		"""

        ret = False
        message = self.LoginMessage
        for attempt in range(self.LoginAttemptsAllowed):
            if attempt > 0:
                num, allwd = attempt + 1, self.LoginAttemptsAllowed
                message = _("Login incorrect, please try again. (%(num)s/%(allwd)s)") % locals()
            loginInfo = self.Application.getLoginInfo(message)

            if isinstance(loginInfo[1], dict):
                # loginInfo variable is a tuple (userName (str), loginInfo (dict)).
                # Dictionary keys are: user, password, connection.
                user = loginInfo[1]["user"]
                password = loginInfo[1]
            else:
                # loginInfo variable is a tuple of user name and password.
                user = loginInfo[0]
                password = loginInfo[1]

            if user is None:
                # login form canceled.
                break

            if self.validateLogin(user, password):
                self.__userName = user
                self.UserCaption = self.getUserCaptionFromUserName(user)
                self.__userGroups = self.getUserGroupsFromUserName(user)
                ret = True
                break
            else:
                self.__userName = None
                self.UserCaption = ""
                self.__userGroups = ()
            time.sleep(self.LoginPause)

        if ret:
            self.Application._loggedIn = True
            self.afterLoginSuccess()
        else:
            self.afterLoginFailure()
        return ret
Beispiel #2
0
 def _getLoginMessage(self):
     try:
         m = self._loginMessage
     except AttributeError:
         m = self._loginMessage = _("Please enter your login information.")
     return m