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


Python User.by_handle方法代码示例

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


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

示例1: create_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
def create_user(handle, password, bank_password, team):
    if User.by_handle(handle) is not None:
        logging.info("User with handle '%s' alreay exists, skipping" % (handle))
        return User.by_handle(handle)
    logging.info("Create User: %s" % handle)
    user = User(
        handle=unicode(handle[:16]),
        team_id=team.id,
    )
    dbsession.add(user)
    dbsession.flush()
    user.password = password
    user.bank_password = bank_password
    dbsession.add(user)
    dbsession.flush()
    return user
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:18,代码来源:helpers.py

示例2: auth

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def auth(self, req):
     ''' Authenticate user '''
     try:
         user = User.by_handle(req['handle'])
     except:
         user = None
     if user is None or user.has_permission(ADMIN_PERMISSION):
         logging.debug("Monitor socket user does not exist.")
         self.write_message({
             'opcode': 'auth_failure',
             'message': 'Authentication failure',
         })
         self.close()
     elif user.validate_password(req.get('password', '')):
         logging.debug("Monitor socket successfully authenticated as %s" % user.handle)
         self.team_name = ''.join(user.team.name)
         self.bot_manager.add_monitor(self)
         self.write_message({'opcode': 'auth_success'})
         boxes = self.bot_manager.get_boxes(self.team_name)
         self.update(boxes)
     else:
         logging.debug("Monitor socket provided invalid password for user")
         self.write_message({
             'opcode': 'auth_failure',
             'message': 'Authentication failure',
         })
         self.close()
开发者ID:lavalamp-,项目名称:RootTheBox,代码行数:29,代码来源:BotnetHandlers.py

示例3: set_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def set_user(self, req):
     ''' Get user details '''
     if self.team_uuid is not None:
         self.write_message({
             'opcode': 'error',
             'message': 'User is already set'
         })
         self.close()
     else:
         user = User.by_handle(req['user'])
         if user is None or user.has_permission(ADMIN_PERMISSION):
             logging.debug("Received invalid user '%s' from bot on %s" % (
                 req['user'], self.remote_ip,
             ))
             self.write_message({
                 'opcode': 'error',
                 'message': 'Hacker does not exist'
             })
             self.close()
         else:
             self.write_message({
                 'opcode': 'status',
                 'message': 'Found user "%s"' % user.handle,
             })
             self.set_team(user.team)
开发者ID:lavalamp-,项目名称:RootTheBox,代码行数:27,代码来源:BotnetHandlers.py

示例4: on_message

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def on_message(self, message):
     ''' Troll the haxors '''
     user = User.by_handle(message)
     if user is not None:
         self.team = user.team
         self.write_message("team ok")
         self.manager.add_bot(self)
         self.manager.new_bot(self)
     else:
         self.write_message("Invalid hacker name.")
         self.close()
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:13,代码来源:BotHandlers.py

示例5: render

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def render(self, *args, **kwargs):
     ''' Renders the top menu '''
     if self.handler.session is not None:
         user = User.by_handle(self.handler.session['handle'])
         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',
                 handle=user.handle
             )
     return self.render_string('menu/public.html')
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:13,代码来源:Menu.py

示例6: get_current_user

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

示例7: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def post(self, *args, **kwargs):
     ''' Attempts to create an account, with shitty form validation '''
     form = Form(
         account="Please enter an account name",
         handle="Please enter a handle",
         team="Please select a team to join",
         pass1="Please enter a password",
         pass2="Please confirm your password",
         token="Please enter a registration token"
     )
     if form.validate(self.request.arguments):
         config = ConfigManager.Instance()
         account = self.get_argument('account').lower()
         handle = self.get_argument('handle').lower()
         rtok = self.get_argument('token', '__none__').lower()
         passwd = self.get_argument('pass1')
         if User.by_account(account) is not None:
             self.render('public/registration.html',
                 errors=['Account name already taken']
             )
         elif account == handle:
             self.render('public/registration.html',
                 errors=['Account name and hacker name must differ']
             )
         elif User.by_handle(handle) is not None:
             self.render('public/registration.html',
                 errors=['Handle already taken']
             )
         elif not passwd == self.get_argument('pass2'):
             self.render('public/registration.html',
                 errors=['Passwords do not match']
             )
         elif not 0 < len(passwd) <= config.max_password_length:
             self.render('public/registration.html',
                 errors=['Password must be 1-%d characters'
                             % config.max_password_length]
             )
         elif Team.by_uuid(self.get_argument('team', '')) is None:
             self.render('public/registration.html',
                 errors=["Please select a team to join"]
             )
         elif RegistrationToken.by_value(rtok) is None and not config.debug:
             self.render('public/registration.html',
                 errors=["Invalid registration token"]
             )
         else:
             self.create_user(account, handle, passwd, rtok)
             self.render('public/successful_reg.html', account=account)
     else:
         self.render('public/registration.html', errors=form.errors)
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:52,代码来源:PublicHandlers.py

示例8: do_grant

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def do_grant(self, username):
     """
     Add user permissions
     Usage: grant <handle>
     """
     user = User.by_handle(username)
     if user is None:
         print (WARN + "'%s' user not found in database." % username)
     else:
         name = raw_input(PROMPT + "Add permission: ")
         permission = Permission(permission_name=unicode(name), user_id=user.id)
         dbsession.add(permission)
         dbsession.add(user)
         dbsession.flush()
         print (INFO + "Successfully granted %s permissions to %s." % (name, user.name))
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:17,代码来源:recovery.py

示例9: do_chpass

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def do_chpass(self, username):
     """
     Change a user's password
     Usage: reset <handle>
     """
     user = User.by_handle(username)
     if user is None:
         print (WARN + "'%s' user not found in database." % username)
     else:
         sys.stdout.write(PROMPT + "New ")
         sys.stdout.flush()
         user.password = getpass.getpass()
         dbsession.add(user)
         dbsession.flush()
         print (INFO + "Updated %s password successfully." % user.handle)
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:17,代码来源:recovery.py

示例10: do_strip

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def do_strip(self, username):
     """
     Strip a user of all permissions
     Usage: strip <handle>
     """
     user = User.by_handle(username)
     if user is None:
         print (WARN + "'%s' user not found in database." % username)
     else:
         username = user.handle
         permissions = Permission.by_user_id(user.id)
         if len(permissions) == 0:
             print (WARN + "%s has no permissions." % user.handle)
         else:
             for perm in permissions:
                 print (INFO + "Removing permission: " + perm.permission_name)
                 dbsession.delete(perm)
         dbsession.flush()
         print (INFO + "Successfully removed %s's permissions." % user.handle)
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:21,代码来源:recovery.py

示例11: interrogation_response

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def interrogation_response(self, msg):
     """ Steps 3 and 4; validate repsonses """
     logging.debug("Recieved interrogate response, validating ...")
     response_xid = msg["rxid"]
     user = User.by_handle(msg["handle"])
     box = Box.by_name(msg["box_name"])
     if self.config.whitelist_box_ips and self.remote_ip not in box.ips:
         self.send_error("Invalid remote IP for this box")
     elif user is None or user.has_permission(ADMIN_PERMISSION):
         self.send_error("User does not exist")
     elif box is None:
         self.send_error("Box does not exist")
     elif not self.is_valid_xid(box, response_xid):
         self.send_error("Invalid xid response")
     else:
         self.team_name = user.team.name
         self.team_uuid = user.team.uuid
         self.box_uuid = box.uuid
         self.box_name = box.name
         self.add_to_botnet()
开发者ID:harite,项目名称:RootTheBox,代码行数:22,代码来源:BotnetHandlers.py

示例12: do_delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def do_delete(self, username):
     """
     Delete a user from the database
     Usage: delete <handle>
     """
     user = User.by_handle(username)
     if user is None:
         print (WARN + "'%s' user not found in database." % username)
     else:
         username = user.handle
         print (WARN + str("Are you sure you want to delete %s?" % username))
         if raw_input(PROMPT + "Delete [y/n]: ").lower() == "y":
             permissions = Permission.by_user_id(user.id)
             for perm in permissions:
                 print (INFO + "Removing permission: " + perm.permission_name)
                 dbsession.delete(perm)
             dbsession.flush()
             dbsession.delete(user)
             dbsession.flush()
             print (INFO + "Successfully deleted %s from database." % username)
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:22,代码来源:recovery.py

示例13: interrogation_response

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def interrogation_response(self, msg):
     ''' Steps 3 and 4; validate repsonses '''
     logging.debug("Received interrogate response, validating ...")
     response_xid = msg['response_xid']
     user = User.by_handle(msg['handle'])
     box = Box.by_name(msg['box_name'])
     if self.config.whitelist_box_ips and self.remote_ip not in box.ips:
         self.send_error("Invalid remote IP for this box")
     elif user is None or user.is_admin():
         self.send_error("User does not exist")
     elif box is None:
         self.send_error("Box does not exist")
     elif not self.is_valid_xid(box, response_xid):
         self.send_error("Invalid xid response")
     else:
         self.team_name = user.team.name
         self.team_uuid = user.team.uuid
         self.box_uuid = box.uuid
         self.box_name = box.name
         self.add_to_botnet(user)
开发者ID:moloch--,项目名称:RootTheBox,代码行数:22,代码来源:BotnetHandlers.py

示例14: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def get(self, *args, **kwargs):
     """ Registers a reporting service on a remote box """
     box = Box.by_ip_address(self.request.remote_ip)
     if box is not None:
         try:
             handle = self.get_argument("handle")
             user = User.by_handle(handle)
             if user is not None:
                 if not box in user.team.boxes:
                     user.team.boxes.append(box)
                     dbsession.add(user.team)
                     dbsession.flush()
                 self.write(unicode(user.team.listen_port))
             else:
                 self.write("Invalid handle")
         except:
             self.write("Missing parameter")
     else:
         self.write("Invalid ip address")
     self.finish()
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:22,代码来源:ReporterHandlers.py

示例15: transfer

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import by_handle [as 别名]
 def transfer(self):
     user = self.get_current_user()
     source = Team.by_name(self.get_argument('source', ''))
     destination = Team.by_name(self.get_argument('destination', ''))
     try:
         amount = int(self.get_argument('amount', 0))
     except ValueError:
         amount = 0
     victim_user = User.by_handle(self.get_argument('user', None))
     password = self.get_argument('password', '')
     user = self.get_current_user()
     # Validate what we got from the user
     if source is None:
         self.write({"error": "Source account does not exist"})
     elif destination is None:
         self.write({"error": "Destination account does not exist"})
     elif victim_user is None or not victim_user in source.members:
         self.write({"error": "User is not authorized for this account"})
     elif victim_user in user.team.members:
         self.write({"error": "You cannot steal from your own team"})
     elif not 0 < amount <= source.money:
         self.write({
             "error": 
             "Invalid transfer amount; must be greater than 0 and less than $%d" % source.money
         })
     elif destination == source:
         self.write({
             "error": "Source and destination are the same account"
         })
     elif victim_user.validate_password(password):
         logging.info("Transfer request from %s to %s for $%d by %s" % (
             source.name, destination.name, amount, user.handle
         ))
         xfer = self.theft(victim_user, destination, amount)
         self.write({
             "success":
             "Confirmed transfer to '%s' for $%d (after 15%s commission)" % (destination.name, xfer, '%',)
         })
     else:
         self.write({"error": "Incorrect password for account, try again"})
     self.finish()
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:43,代码来源:UpgradeHandlers.py


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