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


Python User.by_user_name方法代码示例

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


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

示例1: post

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_user_name [as 别名]
 def post(self, *args, **kwargs):
     ''' Attempts to create an account, with shitty form validation '''
     # Check user_name parameter
     try:
         user_name = self.get_argument('username')
     except:
         self.render('public/registration.html', errors = 'Please enter a valid account name')
         
     # Check handle parameter
     try:
         handle = self.get_argument('handle')
     except:
         self.render('public/registration.html', errors = 'Please enter a valid handle')
     
     # Check password parameter
     try:
         password1 = self.get_argument('pass1')
         password2 = self.get_argument('pass2')
         if password1 != password2:
             self.render('public/registration.html', errors = 'Passwords did not match')
         else:
             password = password1
     except:
         self.render('public/registration.html', errors = 'Please enter a password')
     
     # Check recaptcha
     try:
         response = captcha.submit(
             self.get_argument('recaptcha_challenge_field'),
             self.get_argument('recaptcha_response_field'),
             self.application.settings['recaptcha_private_key'],
             self.request.remote_ip,)
     except:
         self.render('public/registration.html', errors = "Please fill out recaptcha!")
 
     # Create account
     if User.by_user_name(user_name) != None:
         self.render('public/registration.html', errors = 'Account name already taken')
     elif user_name == handle:
         self.render('public/registration.html', errors = 'Account name and hacker name must differ')
     elif User.by_display_name(handle) != None:
         self.render('public/registration.html', errors = 'Handle already taken')
     elif not 0 < len(password) <= 7:
         self.render('public/registration.html', errors = 'Password must be 1-7 characters')
     elif not response.is_valid:
         self.render('public/registration.html', errors = 'Invalid Recaptcha!')
     else:
         char_white_list = ascii_letters + digits
         user_name = filter(lambda char: char in char_white_list, user_name)
         display_name = filter(lambda char: char in char_white_list, handle)
         user = User(
             user_name = unicode(user_name),
             display_name = unicode(display_name),
             password = password
         )
         self.dbsession.add(user)
         self.dbsession.flush()
     self.redirect('/login')
开发者ID:xaelek,项目名称:RootTheBox,代码行数:60,代码来源:RootHandlers.py

示例2: wrapper

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_user_name [as 别名]
 def wrapper(self, *args, **kwargs):
     session_manager = SessionManager.Instance()
     session = session_manager.get_session(self.get_secure_cookie('auth'), self.request.remote_ip)
     if session != None:
         user = User.by_user_name(session.data['user_name'])
         if user != None and user.has_permission(permission):
             return method(self, *args, **kwargs)
     logging.warn("Attempted unauthorized access from %s to %s" % (self.request.remote_ip, self.request.uri))
     self.redirect(self.application.settings['forbidden_url'])
开发者ID:xaelek,项目名称:RootTheBox,代码行数:11,代码来源:SecurityDecorators.py

示例3: post

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_user_name [as 别名]
 def post(self, *args, **kwargs):
     try:
         token = self.get_argument("token")
     except:
         self.render('se/submit.html', message="Please enter a token!")
    
     user = User.by_user_name(self.session.data['user_name'])
     se_manager = SEManager.Instance()
     challenge = se_manager.active_challenge
     if token == se_manager.active_challenge.token:
         se_manager.active_challenge.team_id = user.team.id
         action = Action(
                 classification = unicode("Defeated a Social Engineering Challenge"),
                 description = unicode("%s successfully defeated the level %s Social Engineering Challenge" % (user.display_name, se_manager.active_challenge.level)),
                 value = challenge.value,
                 user_id = user.id)
         se_manager.update_challenge()
         self.notify(user, challenge)
         self.dbsession.add(challenge)
         self.dbsession.add(user)
         self.dbsession.add(action)
         self.dbsession.flush()
         self.render('se/submit.html', message = "You have successfully completed a Social Engineering Round!")
开发者ID:xaelek,项目名称:RootTheBox,代码行数:25,代码来源:SocialHandlers.py


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