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


Python User.username_exists方法代碼示例

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


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

示例1: post

# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import username_exists [as 別名]
    def post(self):
        username = self.request.get('user')
        password = self.request.get('password')
        password_repeated = self.request.get('verify')
        email = self.request.get('email')
        # Validate input and generate needed error messages
        if not validations.is_valid_username:
            username_error = 'Invalid Username'
        elif User.username_exists(username):
            username_error = 'That username is already in use.'
        else:
            username_error = ''

        password_error = ('' if validations.is_valid_password(password)
                          else 'Invalid Password.')
        password_repeated_error = ('' if (password_error or
                                          password == password_repeated)
                                   else 'Passwords do not match.')
        email_error = ('' if (not email or validations.is_valid_email(email))
                       else 'Invalid Email Address.')
        errors = [username_error, password_error,
                  password_repeated_error, email_error]

        # If success, send to welcome page
        if all(not error for error in errors):
            # Success!
            # Hash password
            hashed_pwd = auth.make_pw_hash(username, password)
            # Add to database
            new_user_entry = User(username=username,
                                  password=hashed_pwd,
                                  email=email,
                                  parent=ndb.Key('Users', 'user_group'))
            # if email:
            #     new_user_entry.email = email
            new_user_entry.put()
            # Add cookie
            self.force_login(username)
            redirect_when_finished = self.request.get('redirect_when_finished')
            return self.redirect_with_queries(
                '/welcome',
                [('redirect_when_finished', redirect_when_finished)])
        else:
            # If any checks failed, send back to the signup page
            # with error messages. Repopulate fields except for passwords.
            self.response.out.write(self.template.render(
                entered_username=username,
                email=email,
                username_error=username_error,
                password_error=password_error,
                password_repeated_error=password_repeated_error,
                email_error=email_error
            ))
開發者ID:ajyoon,項目名稱:webdev-learning-multi-user-blog,代碼行數:55,代碼來源:sign_up.py


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