當前位置: 首頁>>代碼示例>>Python>>正文


Python User.get_by_username方法代碼示例

本文整理匯總了Python中database.User.get_by_username方法的典型用法代碼示例。如果您正苦於以下問題:Python User.get_by_username方法的具體用法?Python User.get_by_username怎麽用?Python User.get_by_username使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在database.User的用法示例。


在下文中一共展示了User.get_by_username方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: attempt_login

# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_username [as 別名]
    def attempt_login(self, entered_username, password):
        """Attempt to login given a username and password.

        If the credentials are invalid, return False and do nothing.

        If the credentials are valid, add a user cookie and return True.

        Args:
            entered_username (str): Username for the attempted login
            password (str): plaintext password user enters

        Returns:
            bool: True if login was successful, False if not
        """
        user_in_db = User.get_by_username(entered_username)

        if (user_in_db is not None and
                auth.password_is_valid(entered_username,
                                       password,
                                       user_in_db.password)):
            # If we have a match, the credentials are good
            self.force_login(entered_username)
            return True
        else:
            return False
開發者ID:ajyoon,項目名稱:webdev-learning-multi-user-blog,代碼行數:27,代碼來源:base_handler.py

示例2: initialize

# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import get_by_username [as 別名]
 def initialize(self, *args, **kwargs):
     # Check if the user is logged in and cookie is secure
     webapp2.RequestHandler.initialize(self, *args, **kwargs)
     username = self.get_secure_cookie('user')
     self.user = User.get_by_username(username)
開發者ID:ajyoon,項目名稱:webdev-learning-multi-user-blog,代碼行數:7,代碼來源:base_handler.py


注:本文中的database.User.get_by_username方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。