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


Python User.by_user_name方法代码示例

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


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

示例1: post_password

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def post_password(self, *args, **kwargs):
     user = User.by_user_name(self.session.data['user_name'])
     try:
         old_password = self.get_argument("old_password")
         new_password = self.get_argument("new_password")
         new_password_two = self.get_argument("new_password2")
     except:
         self.render("user/error.html", operation = "Changing Password", errors = "Please fill out all forms")
     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("user/error.html", operation = "Changing Password", errors = "Please fill out recaptcha")
     if user.validate_password(old_password):
         if new_password == new_password_two:
             if len(new_password) <= 7:
                 if response.is_valid:
                     user.password = new_password
                     self.dbsession.add(user)
                     self.dbsession.flush()
                     self.render("user/settings.html", message = "Succesfully Changed Password!")
                 else:
                     self.render("user/error.html", operation = "Changing Password", errors = "Invalid recaptcha")
             else:
                 self.render("user/error.html", operation = "Change Password", errors = "Password must be less than 7 chars")
         else:
             self.render("user/error.html", operation = "Changing Password", errors = "New password's didn't match")
     else:
         self.render("user/error.html", operation = "Changing Password", errors = "Invalid old password")
开发者ID:xaelek,项目名称:RootTheBox,代码行数:35,代码来源:UserHandlers.py

示例2: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def post(self, *args, **kwargs):
     ''' Submit cracked hashes get checked '''
     
     # Get target display_name
     try:
         display_name = self.get_argument("display_name")
     except:
         self.render("hashes/error.html", operation = "Hash cracking", errors = "No user name")
     
     # Get preimage
     try:
         preimage = self.get_argument("preimage")
     except:
         self.render("hashes/error.html", errors = "No password", operation = "Hash cracking")
         
     user = User.by_user_name(self.session.data['user_name'])
     target = User.by_display_name(display_name)
     
     if target == None or user == None or target.has_permission("admin"):
         self.render("hashes/error.html", operation = "Hash cracking", errors = "That user does not exist")
     elif target in user.team.members:
         self.render("hashes/error.html", operation = "Hash cracking", errors = "You can't crack hashes from your own team")
     elif target.score <= 0:
         self.render("hashes/error.html", operation = "Hash cracking", errors = "Target user must have a score greater than zero")
     elif target.validate_password(preimage):
         self.notify(user, target)
         value = self.steal_points(user, target)
         self.add_to_wall(user, target, preimage, value)
         self.render("hashes/success.html", user = user, target = target )
     else:
         self.render("hashes/error.html", operation = "Hash cracking", errors = "Wrong password, try again")
开发者ID:xaelek,项目名称:RootTheBox,代码行数:33,代码来源:HashesHandlers.py

示例3: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def post(self, *args, **kwargs):
     ''' Attempts to create an account '''
     form = Form(
         username="Please enter a username",
         pass1="Please enter a password",
         pass2="Please confirm your password",
         recaptcha_challenge_field="Invalid captcha",
         recaptcha_response_field="Invalid captcha",
     )
     if not form.validate(self.request.arguments):
         self.render("public/registration.html", errors=form.errors)
     elif self.check_recaptcha():
         user_name = self.get_argument('username')
         if User.by_user_name(user_name) != None:
             self.render('public/registration.html',
                         errors=['Account name already taken'])
         elif len(user_name) < 3 or 15 < len(user_name):
             self.render('public/registration.html',
                         errors=['Username must be 3-15 characters'])
         elif not self.get_argument('pass1') == self.get_argument('pass2'):
             self.render('public/registration.html',
                         errors=['Passwords do not match'])
         elif not (12 <= len(self.get_argument('pass1')) <= 100):
             self.render('public/registration.html',
                         errors=['Password must be 12-100 characters'])
         else:
             user = self.create_user(user_name, self.get_argument('pass1'))
             self.render(
                 "public/account_created.html", user_name=user.user_name)
     else:
         self.render("public/registration.html",
                     errors=['Invalid captcha'])
开发者ID:hathcox,项目名称:BlackBook,代码行数:34,代码来源:PublicHandlers.py

示例4: change_password

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def change_password(self, *args, **kwargs):
     ''' Updates a user accounts password '''
     user = User.by_user_name(self.session.data['user_name'])
     try:
         old_password = self.get_argument("old_password")
         new_password = self.get_argument("new_password")
         new_password_two = self.get_argument("new_password2")
     except:
         self.render("user/error.html", operation="Changing Password",
                     errors="Please fill out all forms")
     if user.validate_password(old_password):
         if new_password == new_password_two:
             if 12 <= len(new_password):
                 user.password = new_password
                 self.dbsession.add(user)
                 self.dbsession.flush()
                 self.render("user/settings.html",
                             message="Succesfully Changed Password!")
             else:
                 self.render("user/error.html", operation="Change Password",
                             errors="Password must be at least 12 chars")
         else:
             self.render("user/error.html", operation="Changing Password",
                         errors="New password's didn't match")
     else:
         self.render("user/error.html", operation="Changing Password",
                     errors="Invalid old password")
开发者ID:hathcox,项目名称:ShodanDorks,代码行数:29,代码来源:UserHandlers.py

示例5: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def post(self, *args, **kwargs):
     ''' Checks login creds '''
     try:
         user_name = self.get_argument('username')
         user = User.by_user_name(user_name.encode('utf-8', 'ignore'))
     except:
         self.render('public/login.html', message = "Type in an account name")
         return
     try:
         password = self.get_argument('password')
     except:
         self.render('public/login.html', message = "Type in a password")
         return
     if user != None and user.validate_password(password):
         logging.info("Successful login: %s from %s" % (user.user_name, self.request.remote_ip))
         session_manager = SessionManager.Instance()
         sid, session = session_manager.start_session()
         self.set_secure_cookie(name = 'auth', value = str(sid), expires_days = 1, HttpOnly = True)
         session.data['user_name'] = str(user.user_name)
         session.data['ip'] = str(self.request.remote_ip)
         if user.has_permission('admin'):
             session.data['menu'] = str('admin')
         else:
             session.data['menu'] = str('user')
         self.redirect('/home')
     else:
         logging.info("Failed login attempt from %s " % self.request.remote_ip)
         self.render('public/login.html', message = "Failed login attempt, try again")
开发者ID:saifeinc,项目名称:Yoshimi-Botnet,代码行数:30,代码来源:PublicHandlers.py

示例6: post_avatar

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def post_avatar(self, *args, **kwargs):
     ''' Saves avatar - Reads file header an only allows approved formats '''
     user = User.by_user_name(self.session.data['user_name'])
     if self.request.files.has_key('avatar') and len(self.request.files['avatar']) == 1:
         if len(self.request.files['avatar'][0]['body']) < (1024*1024):
             if user.avatar == "default_avatar.jpeg":
                 user.avatar = unicode(str(uuid1()))
             elif os.path.exists(self.application.settings['avatar_dir']+'/'+user.avatar):
                 os.unlink(self.application.settings['avatar_dir']+'/'+user.avatar)
             # Check image header, reject any unapproved formats
             ext = imghdr.what("", h = self.request.files['avatar'][0]['body'])
             if ext in ['png', 'jpeg', 'gif', 'bmp']:
                 user.avatar = user.avatar[:user.avatar.rfind('.')]+"."+ext
                 file_path = self.application.settings['avatar_dir']+'/'+user.avatar
                 avatar = open(file_path, 'wb')
                 avatar.write(self.request.files['avatar'][0]['body'])
                 avatar.close()
                 self.dbsession.add(user)
                 self.dbsession.flush()
                 self.redirect("/user")
             else:
                 self.render("user/error.html", operation = "Uploading avatar", errors = "Invalid image format")
         else:
             self.render("user/error.html", operation = "Uploading avatar", errors = "The image is too large")
     else:
         self.render("user/error.html", operation = "Uploading avatar", errors = "Please provide and image")
开发者ID:xaelek,项目名称:RootTheBox,代码行数:28,代码来源:UserHandlers.py

示例7: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
    def post(self, *args, **kwargs):
        ''' Check to see if the user correctly entered the crackme's token '''
        try:
            token = self.get_argument("token")
        except:
            self.render('crack_me/error.html', errors = "No token input")

        user = User.by_user_name(self.session.data['user_name'])
        if user != None:
            if(user.team.crack_me.token == token):
                level = user.team.crack_me.id
                user_action = Action(
                    classification = unicode("Cracked a Crack Me"),
                    description = unicode("%s successfully cracked the level %s Crack Me" % (user.display_name, user.team.crack_me.id)),
                    value = user.team.crack_me.value,
                    user_id = user.id
                )
                user.dirty = True
                self.notify(user, user.team.crack_me)
                user.team.solved_crack_me()
                user.actions.append(user_action)
                self.dbsession.add(user)
                self.dbsession.add(user.team)
                self.dbsession.flush()
                self.render('crack_me/success.html', level = level)
            else:
                self.render('crack_me/error.html', errors = "Invalid Token")
        else:
            self.redirect("/login")
开发者ID:xaelek,项目名称:RootTheBox,代码行数:31,代码来源:CrackMeHandlers.py

示例8: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def get(self, *args, **kwargs):
     ''' '''
     user = User.by_user_name(self.session.data['user_name'])
     if user.team != None:
         self.render('crack_me/view.html', crack_me = user.team.crack_me)
     else:
         self.render('crack_me/view.html', crack_me = None)
开发者ID:xaelek,项目名称:RootTheBox,代码行数:9,代码来源:CrackMeHandlers.py

示例9: _post_login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def _post_login(self, **kw):
     # checks if the user is already logged
     user = self.current_user
     # if not, tries to fetch the user
     # from the database and validate the password.
     if not user:
         user = User.by_user_name(kw['user_name'])   
         if user and user.validate_password(kw['password']):
             # sets the auth cookie.
             # don't worry, not the real 'password'.
             # just a piece of the junky salt generated by the User model
             self.set_secure_cookie('auth', dumps({
                 'id': user.id,
                 'password': user.password[0:8]
             }))
         else:
             user = None
     
     # if user logged in successfuly
     # redirects to kw['next'] or '/'
     if user:
         self.redirect(kw['next'] or '/')
     # else, redirects to the /login page
     else:
         kw.pop('password')
         self.redirect('/login?%s'%form_encode(kw))
开发者ID:marxus85,项目名称:teaspoon,代码行数:28,代码来源:root.py

示例10: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def post(self, *args, **kwargs):
     user = User.by_user_name(self.session.data['user_name'])
     try:
         token = self.get_argument("token")
         challenge = Challenge.get_by_id(self.get_argument("challenge"))
     except:
         self.render("user/error.html", operation = "Submit Challenge", errors = "Please enter a token")    
     if user.team != None:
         if not challenge in user.team.challenges:
             if token == challenge.token:
                 action = Action(
                     classification = unicode("Challenge Completed"),
                     description = unicode(user.user_name+" has succesfully completed "+challenge.name+" !"),
                     value = challenge.value,
                     user_id = user.id
                 )
                 challenge.teams.append(user.team)
                 self.dbsession.add(challenge)
                 self.dbsession.add(action)
                 self.dbsession.flush()
                 self.redirect('/challenge')
             else:
                 self.render("user/error.html", operation = "Submit Challenge", errors = "Invalid Token")
         else:
             self.render("user/error.html", operation = "Submit Challenge", errors = "This challenge was already completed")
     else:
         self.render("user/error.html", operation = "Submit Challenge", errors = "You're not on a team")
开发者ID:xaelek,项目名称:RootTheBox,代码行数:29,代码来源:UserHandlers.py

示例11: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def post(self, *args, **kwargs):
     ''' Checks users '''
     try:
         user_name = self.get_argument("username")
     except:
         self.render("admin/error.html", error="No users found")
     user = User.by_user_name(user_name)
     self.dbsession.flush()
开发者ID:brutalhonesty,项目名称:The-Planetary-Assault-System,代码行数:10,代码来源:AdminHandlers.py

示例12: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def get(self, *args, **kwargs):
     session_manager = SessionManager.Instance()
     session = session_manager.get_session(self.get_secure_cookie('auth'), self.request.remote_ip)
     user = User.by_user_name(session.data['user_name'])
     if user.team != None:
         self.render('pastebin/view.html', posts = user.team.posts)
     else:
         self.render('pastebin/view.html', posts = [])
开发者ID:xaelek,项目名称:RootTheBox,代码行数:10,代码来源:PastebinHandlers.py

示例13: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.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',
                     message='Please enter a valid account name')
     # Check password parameter
     try:
         password1 = self.get_argument('pass1')
         password2 = self.get_argument('pass2')
         if password1 != password2:
             self.render('public/registration.html',
                         message='Passwords did not match')
         else:
             password = password1
     except:
         self.render('public/registration.html',
                     message='Please enter a password')
     # Get recaptcha results
     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',
                     message="Please fill out recaptcha")
     # Strip any non-white listed chars
     char_white_list = ascii_letters + digits
     user_name = filter(lambda char: char in char_white_list, user_name)
     # Check parameters
     if not response.is_valid:
         self.render('public/registration.html',
                     message='Invalid Recaptcha!')
     elif User.by_user_name(user_name) != None:
         self.render('public/registration.html',
                     message='Account name already taken')
     elif len(user_name) < 3 or 15 < len(user_name):
         self.render('public/registration.html',
                     message='Username must be 3-15 characters')
     elif not (12 <= len(password) <= 100):
         self.render('public/registration.html',
                     message='Password must be 12-100 characters')
     else:
         user = User(
             user_name=unicode(user_name),
         )
         # Create user, init class variables
         self.dbsession.add(user)
         self.dbsession.flush()
         # Set password for user
         user.password = password
         self.dbsession.add(user)
         self.dbsession.flush()
         self.render("public/account_created.html", user=user)
开发者ID:brutalhonesty,项目名称:The-Planetary-Assault-System,代码行数:60,代码来源:PublicHandlers.py

示例14: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def get(self, *args, **kwargs):
     user = User.by_user_name(self.session.data['user_name'])
     all_challenges = Challenge.get_all()
     correct_challenges = []
     for challenge in all_challenges:
         if user.team != None:
             if not challenge in user.team.challenges:
                 correct_challenges.append(challenge)          
     self.render("user/challenge.html", challenges = correct_challenges)
开发者ID:xaelek,项目名称:RootTheBox,代码行数:11,代码来源:UserHandlers.py

示例15: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_user_name [as 别名]
 def get(self, *args, **kwargs):
     try:
         session_manager = SessionManager.Instance()
         session = session_manager.get_session(
             self.get_secure_cookie('auth'), self.request.remote_ip)
         user = User.by_user_name(session.data['user_name'])
         if user != None:
             tags = Tag.all()
             self.render('user/submit.html', user=user, errors=None, success=None, tags=tags)
         else:
             self.render('public/please_login.html')
     except:
         self.render('public/please_login.html')
开发者ID:hathcox,项目名称:ShodanDorks,代码行数:15,代码来源:PublicHandlers.py


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