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


Python User.by_name方法代码示例

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


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

示例1: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
    def post(self):
        have_error = False
        self.username = self.request.get('username')
        self.password = self.request.get('password')
        self.verify = self.request.get('verify')
        self.email = self.request.get('email')

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

        if not valid_username(self.username):
            params['error_username'] = "That's not a valid username."
            have_error = True
        elif User.by_name(self.username):
            params['error_username'] = 'That user already exists.'
            have_error = True

        if not valid_password(self.password):
            params['error_password'] = "That wasn't a valid password."
            have_error = True
        elif self.password != self.verify:
            params['error_verify'] = "Your passwords didn't match."
            have_error = True

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

        if have_error:
            self.render('signup.html', **params)
        else:
            u = User.register(self.username, self.password, self.email)
            u.put()
            self.login(u)
            self.redirect('/blogs')
开发者ID:DerrickSee,项目名称:Udacity-Blog,代码行数:36,代码来源:users.py

示例2: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
    def post(self):
        # get all the required params
        username = self.request.get('username')
        password = self.request.get('password')
        email = self.request.get('email')
        verify = self.request.get('verify')

        # build an array of errors
        # if there is any error set return_error to true
        errors = []
        return_error = False
        if not username or not password or not email or not verify:
            return_error = True
            errors.append('All fields are required.')
        if password != verify:
            return_error = True
            errors.append('Passwords did not match.')
        if username:
            # check if username exists
            u = User.by_name(username)
            if u:
                errors.append('That username is already taken.')
                return_error = True

        if return_error == True:
            self.render_form(username, email, errors)
        else:
            user = User.register(username, password, email)
            user.put()
            self.set_login_cookie(user)
            self.redirect(HOME_PATH + '/welcome/')
开发者ID:jdiii,项目名称:gae_blog,代码行数:33,代码来源:main.py

示例3: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
    def post(self):
        error = False
        self.username = self.request.get('username')
        self.password = self.request.get('password')

        params = { 'username':self.username,
                   'password':self.password }

        if not self.valid_username(self.username):
            params['username_error'] = "That's not a valid username."
            error = True

        #Check if user already exists
        u = User.by_name(self.username)
        if u:
            params['username_error'] = 'That user already exists.'
            error = True

        if not self.valid_password(self.password):
            params['password_error'] = "That wasn't a valid password."
            error = True
        
        if error:
            self.render('index.html', **params)
        else:
            self.render('signup.html', **params)
开发者ID:ecmendenhall,项目名称:Hackertranscript,代码行数:28,代码来源:main.py

示例4: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
    def post(self):
        have_error = False
        self.username = self.request.get("username")
        self.password = self.request.get("password")
        self.verify = self.request.get("verify")
        self.email = self.request.get("email")

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

        if not valid_username(self.username):
            params['username_error'] = "That's not a valid username."
            have_error = True

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

        if have_error:
            self.render("signup-form.html", **params)
        else:
            user = User.by_name(self.username)
            if user:
                username_error = "That user already exists."
                self.render("signup-form.html", username_error = username_error)
            else:
                self.done()
开发者ID:kuncetto,项目名称:udacity-cs253,代码行数:36,代码来源:handlers.py

示例5: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
 def post(self, *args, **kwargs):
     ''' Attempts to create an account, with shitty form validation '''
     username = self.get_argument('username', None)
     pass1 = self.get_argument('pass1', None)
     pass2 = self.get_argument('pass1', None)
     if username is None or User.by_name(username) is not None:
         self.render('public/registration.html', 
             errors=['Invalid username']
         )
     elif pass1 is None or pass2 is None:
         self.render('public/registration.html', 
             errors=['Please type your password twice']
         )
     elif pass1 != pass2:             
         self.render('public/registration.html', 
             errors=['Passwords do not match']
         )
     elif len(pass1) < 12:
         self.render('public/registration.html', 
             errors=['Passwords too shore (min. 12)']
         )            
     else:
         password = self.get_argument('pass1')
         user = self.create_user(username, password)
         self.render('public/successful_reg.html', user=user)
开发者ID:DJHartley,项目名称:Veil,代码行数:27,代码来源:PublicHandlers.py

示例6: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
 def post(self):
     username = self.request.get('username')
     password = self.request.get('password')
     password_verify = self.request.get('verify')
     email = self.request.get('email')
     params = dict(username=username, email=email)
     have_error = False
     if valid_username(username):
         user = User.by_name(username)
         if user:
             params['error_username'] = "That user already exists."
             have_error = True
     else:
         params['error_username'] = "That's not a valid username."
         have_error = True
     if not valid_password(password):
         params['error_password'] = "That's not a valid password."
         have_error = True
     elif password != password_verify:
         params['error_verify'] = "Your passwords didn't match."
         have_error = True
     if not valid_email(email):
         params['error_email'] = "That's not a valid email."
         have_error = True
     if have_error:
         self.render('signup-form.html', **params)
     else:
         user = User.register(username, password, email)
         user.put()
         self.login(user)
         self.redirect('/')
开发者ID:yijiaow,项目名称:multi-user-blog,代码行数:33,代码来源:main.py

示例7: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
    def post(self):
        print('[POST]', self.request)
        username = self.request.get('username')
        password = self.request.get('password')
        verify = self.request.get('verify')
        email = self.request.get('email')

        # Signup on any page and get redirected to that page when complete.
        next_url = str(self.request.get('referer'))
        if not next_url or next_url.startswith('/login'):
            next_url = '/'

        if username and password and verify:
            existing_user = User.by_name(username)
            # Make sure user doesnt already exists
            if existing_user:
                error = 'Error, user already exists: ' + username
                self.render_page(username, password, verify, email, error)
            else:
                new_user = User.register(username, password, email)
                new_user.put()

                self.set_secure_cookie('userId', str(new_user.key().id()))

                # Redirect to the referring page
                self.redirect(next_url)
        else:
            error = 'Error, you need to fill in all values.'
            self.render_page(username, password, verify, email, error, next_url=next_url)
开发者ID:iingemar,项目名称:dazzling-octo-wiki,代码行数:31,代码来源:signup.py

示例8: render

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
 def render(self, *args, **kwargs):
     ''' Renders the top menu '''
     if self.handler.session is not None:
         user = User.by_name(self.handler.session['username'])
         if self.handler.session['menu'] == 'user':
             return self.render_string('menu/user.html', user=user)
         elif self.handler.session['menu'] == 'admin':
             return self.render_string('menu/admin.html', user=user)
     return self.render_string('menu/public.html')
开发者ID:DJHartley,项目名称:Veil,代码行数:11,代码来源:Menu.py

示例9: done

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

示例10: done

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
 def done(self):
     u = User.by_name(self.username)
     if u:
         msg = 'That user already exists.'
         self.render('signup-form.html', error_username=msg)
     else:
         u = User.register(self.username, self.password, self.email)
         u.put()
         self.login(u)
         self.redirect(self.next_url)
开发者ID:michaelhuang,项目名称:udacity-cs253,代码行数:12,代码来源:handlers.py

示例11: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
 def post(self, *args, **kwargs):
     ''' Checks submitted username and password '''
     if self.form.validate(self.request.arguments):
         user = User.by_name(self.request.arguments['username'][0])
         if user != None and user.validate_password(self.request.arguments['password'][0]):
             self.successful_login(user)
             self.redirect('/user')
         else:
             self.failed_login()
     else:
         self.render('public/login.html', errors=self.form.errors)
开发者ID:hathcox,项目名称:Arthur,代码行数:13,代码来源:PublicHandlers.py

示例12: done

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
    def done(self):
        #make sure the user has not already existed
        u = User.by_name(self.username)
        if u:
            msg = 'That user already exists.'
            self.render('signup-form.html', error_username = msg)
        else:
            u = User.register(self.username, self.password, self.email)
            u.put()

            self.login(u)
            self.redirect("/welcome")   
开发者ID:kensupernova,项目名称:simple-multiuser-blog,代码行数:14,代码来源:blog.py

示例13: save_user_info

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
 def save_user_info(self, username):
     self.name = self.request.get('name')
     self.twitter = self.request.get('twitter')
     self.github = self.request.get('github')
     self.website = self.request.get('website')
     
     u = User.by_name(username)
     u.name = self.name
     u.twitter = self.twitter
     u.github = self.github
     u.website = self.website
     u.put()
开发者ID:ecmendenhall,项目名称:Hackertranscript,代码行数:14,代码来源:main.py

示例14: add_user_info

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
    def add_user_info(self, params, username):
        #Check if user exists
        u = User.by_name(username)
        if not u:
            self.response.out.write('404 Not Found')

        else:
            params['username'] = username
            params['name'] = u.name
            params['twitter'] = u.twitter
            params['github'] = u.github
            params['website'] = u.website 
开发者ID:ecmendenhall,项目名称:Hackertranscript,代码行数:14,代码来源:main.py

示例15: get_current_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_name [as 别名]
 def get_current_user(self):
     ''' Get current user object from database '''
     if self.session is not None:
         try:
             return User.by_name(self.session['username'])
         except KeyError:
             logging.exception(
                 "Malformed session: %r" % self.session
             )
         except:
             logging.exception("Failed call to get_current_user()")
     return None
开发者ID:DJHartley,项目名称:Veil,代码行数:14,代码来源:BaseHandlers.py


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