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


Python User.by_name方法代码示例

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


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

示例1: done

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
 def done(self):
     u = User.by_name(self.username)
     if u:
         msg = " The user already exists"
         self.render('signup_page.html', error1=msg)
     else:
         u = User.register(self.username, self.password, self.email)
         u.put()
         self.login(u)
         self.redirect('/welcome')
开发者ID:pribala,项目名称:udacity_projects,代码行数:12,代码来源:main.py

示例2: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
    def post(self):
        '''
        creates a new user instance and inserts it into the db.
        logs the user in, then redirects the user to the welcome page.

        if there are any errors, render the signup form again with
        the appropriate saved data and error messages
        '''
        have_error = False

        self.username = self.request.get("username").encode("latin-1")
        self.password = self.request.get("password").encode("latin-1")
        self.verify = self.request.get("verify").encode("latin-1")
        self.email = self.request.get("email").encode("latin-1")

        params = dict(username=self.username,
                      email=self.email)

        # check for any errors
        if not valid_username(self.username):
            params['username_error'] = "That's not a valid username"
            have_error = True
        elif User.by_name(self.username):
                params['username_error'] = 'That user already exists'
                have_error = True

        if not valid_password(self.password):
            params['password_error'] = "That's not a valid password"
            have_error = True
        elif self.password != self.verify:
            params['verify_error'] = "Your passwords don't match"

        if not valid_email(self.email):
            params['email_error'] = "That's not a valid email"
            have_error = True

        # there's some error(s)
        if have_error:
            self.render("users/signup.html", **params)
        # succest!!
        else:
            user = User.register(self.username, self.password, self.email)
            user.put()

            self.login(user)
            self.redirect('/welcome')
开发者ID:tiffanyhan,项目名称:poetry-blog,代码行数:48,代码来源:users.py

示例3: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
    def post(self):
        username_error = invalid_email = invalid_password = verify_password_error = None

        #Retrieve form information from user sign up submission
        user_username = self.request.get("username")
        user_password = self.request.get("password")
        user_verify_password = self.request.get("verify")
        user_email = self.request.get("email")

        params = dict(username = user_username,
                    email = user_email)

        username = valid_name(user_username)
        password = valid_password(user_password)
        verify_password = None
        email = None

        if user_email:
            email = valid_email(user_email)
            if not email:
                params['invalid_email'] = "That's not a valid email."

        if not username:
            params['username_error'] = "That's not a valid username."
        elif (User.by_name(user_username)):
            username = None
            params['username_error'] = "User already exists !"

        if password:
            verify_password = valid_verify_password(user_password, user_verify_password)
            if not verify_password:
                params['verify_password_error'] = "Your passwords didn't match."
        else:
            params['invalid_password'] = "That wasn't a valid password."

        if username and password and verify_password and not invalid_email:
            password_hash = hash_pwd(user_username, user_password)
            user = User(username = user_username, password = password_hash, email = user_email)
            user.put()
            self.response.headers.add_header('Set-Cookie','user_id=%s; Path=/' % make_secure_value(str(user.key().id())))
            self.redirect("/blog/welcome")
        else:
            self.render("signup.html", **params)
开发者ID:harikrish00,项目名称:blogit,代码行数:45,代码来源:sign_up.py

示例4: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import by_name [as 别名]
    def post(self):
        params = {}
        have_error = False
        
        params['username'] = user_username = self.request.get('username')
        user_password = self.request.get('password')
        user_verify   = self.request.get('verify')
        params['email']    = user_email    = self.request.get('email')
                
        valid_user = valid_username(user_username)
        valid_pass = valid_password(user_password)
        valid_mail = valid_email(user_email)
        
        if not valid_user:
            have_error = True
            params['error_username'] = 'That was not a valid username'
        if User.by_name(user_username):
            have_error = True
            params['error_username'] = 'Username already exists'
        if not valid_pass:
            have_error = True
            params['error_password'] = 'Not a valid password'
        if user_password != user_verify:
            have_error = True
            params['error_verify'] = "Your passwords didn't match"
        if not valid_mail:
            have_error = True
            params['error_email'] = 'That was not a valid e-mail'

        if have_error:
            self.render('signup.html', **params)
        else:
            new_user = User.register(user_username, user_password, user_email)
            new_user.put()
            self.user = new_user
            self.login(self.user)
            self.redirect('/welcome')
开发者ID:simzou,项目名称:udacity-google-app-engine,代码行数:39,代码来源:signup.py


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