当前位置: 首页>>代码示例>>Python>>正文


Python Core.logOut方法代码示例

本文整理汇总了Python中core.Core.logOut方法的典型用法代码示例。如果您正苦于以下问题:Python Core.logOut方法的具体用法?Python Core.logOut怎么用?Python Core.logOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.Core的用法示例。


在下文中一共展示了Core.logOut方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PyAuth

# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import logOut [as 别名]
class PyAuth(QMainWindow):
    """Main window class."""

    def __init__(self):
        super(PyAuth, self).__init__()
        self.setGeometry(500, 300, 200, 100)
        self.setFixedSize(500, 300)

        self.__setupMenu()

        self.app = Core()
        self.requestCredentials()

    def __setupMenu(self):
        """Defines basic top menu"""
        quit_action = QAction("&Exit", self)
        quit_action.setShortcut('Ctrl+Q')
        quit_action.triggered.connect(self.close)

        sign_out_action = QAction("Sign out", self)
        sign_out_action.setShortcut('Ctrl+L')
        sign_out_action.triggered.connect(lambda: (self.app.logOut(), self.hide(), self.requestCredentials()))

        change_password_action = QAction("Change password", self)
        change_password_action.triggered.connect(self.requestPasswordChange)

        about_action = QAction("About", self)
        about_action.triggered.connect(lambda: QMessageBox.about(self, "About", u'© ' + __author__ + ' 2013'))

        self.file_menu = self.menuBar().addMenu("&File")
        self.file_menu.addAction(quit_action)

        self.account_menu = self.menuBar().addMenu("&Account")
        self.account_menu.addAction(sign_out_action)
        self.account_menu.addAction(change_password_action)

        self.help_menu = self.menuBar().addMenu("&Help")
        self.help_menu.addAction(about_action)

    def requestPasswordChange(self):
        """Requests dialog for password change."""
        dialog = None

        def ok_handler(oldPassword, password, confirm):
            if 5 > len(password) > 30:
                QMessageBox.critical(dialog, "Error", "Password must be between 6 and 30 char length")
                return
            if password != confirm:
                QMessageBox.critical(dialog, "Error", "Passwords don't match")
                return
            status = self.app.changePassword(oldPassword, password)
            {
                Core.ERROR_OLD_PASSWORD: lambda:
                QMessageBox.critical(dialog, "Error", "Wrong old password.", modal=True),
                Core.ERROR_PASSWORD_RESTRICTION: lambda:
                QMessageBox.critical(dialog, "Error", "Password is too weak.", modal=True),
                Core.SUCCESS: lambda: dialog.close()
            }[status]()

        def cancel_handler():
            dialog.close()

        dialog = ChangePasswordDialog(self, ok_handler, cancel_handler)
        dialog.show()

    def requestCredentials(self):
        """Requests form for credentials input"""
        dialog = None

        def ok_handler(username, password):
            status = self.app.logIn(username, password)
            {
                Core.ERROR_INCORRECT_CREDENTIALS: lambda:
                QMessageBox.critical(dialog, "Error", "Incorrect username or password", modal=True),
                Core.ERROR_USER_IS_BLOCKED: lambda:
                QMessageBox.critical(dialog, "Error", "Your account is blocked", modal=True),
                Core.ERROR_ATTEMPTS: self.close,
                Core.SUCCESS: lambda: (
                    self.showAdminWidget() if self.app.currentUser.admin else self.showCustomerWidget(),
                    dialog.close()
                )
            }[status]()

        def cancel_handler():
            sys.exit()

        dialog = SignInDialog(self, ok_handler, cancel_handler)
        dialog.show()

    def showAdminWidget(self):
        """Requests admin panel."""
        self.setCentralWidget(AdminWidget(self))
        self.show()

    def showCustomerWidget(self):
        """Requests customers panel."""
        self.setCentralWidget(CustomerWidget(self))
        self.show()
开发者ID:oleksiyivanenko,项目名称:pyAuth,代码行数:100,代码来源:pyAuth.py


注:本文中的core.Core.logOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。