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


Python User.by_handle方法代码示例

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


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

示例1: create_user

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
    def create_user(self):
        ''' Add user to the database '''
        if User.by_handle(self.get_argument('handle', '')) is not None:
            raise ValidationError("This handle is already registered")
        if self.get_argument('pass1', '') != self.get_argument('pass2', ''):
            raise ValidationError("Passwords do not match")
        user = User()
        user.handle = self.get_argument('handle', '')
        user.password = self.get_argument('pass1', '')
        user.bank_password = self.get_argument('bpass', '')
        user.name = self.get_argument('playername', '')
        user.email = self.get_argument('email','')
        team = self.get_team()
        self.dbsession.add(user)
        self.dbsession.add(team)
        self.dbsession.commit()

         # Avatar
        avatar_select = self.get_argument('user_avatar_select', '')
        if avatar_select and len(avatar_select) > 0:
            user._avatar = avatar_select
        elif hasattr(self.request, 'files') and 'avatar' in self.request.files:
            user.avatar = self.request.files['avatar'][0]['body']
        team.members.append(user)
        if not options.teams:
            if avatar_select and len(avatar_select) > 0:
                team._avatar = avatar_select
            elif hasattr(self.request, 'files') and 'avatar' in self.request.files:
                team.avatar = self.request.files['avatar'][0]['body']  
        self.dbsession.add(user)
        self.dbsession.add(team)
        self.dbsession.commit()  
        self.event_manager.user_joined_team(user)
        return user
开发者ID:moloch--,项目名称:RootTheBox,代码行数:36,代码来源:PublicHandlers.py

示例2: wrapper

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
 def wrapper(self, *args, **kwargs):
     if self.session is not None:
         user = User.by_handle(self.session['handle'])
         if user is not 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:AnarKyx01,项目名称:RootTheBox,代码行数:11,代码来源:SecurityDecorators.py

示例3: create_user

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
def create_user():
    user = User.by_handle("HacKer")
    if user is None:
        user = User()
        user.handle = "HacKer"
        user.password = "TestPassword"
        user.bank_password = "Test123"
        dbsession.add(user)
        dbsession.commit()
    return user
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:12,代码来源:Helpers.py

示例4: get_current_user

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.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:harite,项目名称:RootTheBox,代码行数:12,代码来源:BaseHandlers.py

示例5: create_user

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
 def create_user(self, team):
     ''' Add user to the database '''
     if User.by_handle(self.get_argument('handle', '')) is not None:
         raise ValidationError("This hacker name is already registered")
     if self.get_argument('pass1', '') != self.get_argument('pass2', ''):
         raise ValidationError("Passwords do not match")
     user = User()
     user.handle = self.get_argument('handle', '')
     user.password = self.get_argument('pass1', '')
     user.bank_password = self.get_argument('bpass', '')
     team.members.append(user)
     self.dbsession.add(user)
     self.dbsession.add(team)
     self.dbsession.commit()
     self.event_manager.user_joined_team(user)
     return user
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:18,代码来源:PublicHandlers.py

示例6: edit_user

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
 def edit_user(self):
     ''' Update user objects in the database '''
     try:
         user = User.by_uuid(self.get_argument('uuid', ''))
         if user is None:
             raise ValidationError("User does not exist")
         handle = self.get_argument('handle', '')
         if user.handle != handle:
             if User.by_handle(handle) is None:
                 logging.info("Updated user handle %s -> %s" % (
                     user.handle, handle
                 ))
                 user.handle = handle
             else:
                 raise ValidationError("Handle is already in use")
         hash_algorithm = self.get_argument('hash_algorithm', '')
         if hash_algorithm != user.algorithm:
             if hash_algorithm in user.algorithms:
                 if 0 < len(self.get_argument('bank_password', '')):
                     logging.info("Updated %s's hashing algorithm %s -> %s" % (
                         user.handle, user.algorithm, hash_algorithm,
                     ))
                     user.algorithm = hash_algorithm
                 else:
                     raise ValidationError(
                         "You must provide a new bank password when updating the hashing algorithm")
             else:
                 raise ValidationError("Not a valid hash algorithm")
         user.password = self.get_argument('password', '')
         if len(self.get_argument('bank_password', '')):
             user.bank_password = self.get_argument('bank_password', '')
         team = Team.by_uuid(self.get_argument('team_uuid', ''))
         if team is not None:
             if user not in team.members:
                 logging.info("Updated %s's team %s -> %s" % (
                     user.handle, user.team_id, team.name
                 ))
                 user.team_id = team.id
         else:
             raise ValidationError("Team does not exist in database")
         self.dbsession.add(user)
         self.dbsession.commit()
         self.redirect('/admin/users')
     except ValidationError as error:
         self.render("admin/view/users.html",
                     errors=[str(error), ]
                     )
开发者ID:WeiEast,项目名称:RootTheBox,代码行数:49,代码来源:AdminUserHandlers.py

示例7: post

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
 def post(self, *args, **kwargs):
     ''' Checks submitted username and password '''
     user = User.by_handle(self.get_argument('account', ''))
     password_attempt = self.get_argument('password', '')
     if user is not None and user.validate_password(password_attempt):
         if not user.locked:
             if self.game_started(user):
                 self.successful_login(user)
                 if user.logins == 1 and not user.has_permission(ADMIN_PERMISSION):
                     self.redirect('/user/missions/firstlogin')
                 else:
                     self.redirect('/user')
             else:
                 self.render('public/login.html', errors=["The game has not started yet"])
         else:
             self.render('public/login.html', errors=["Your account has been locked"])
     else:
         self.failed_login()
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:20,代码来源:PublicHandlers.py

示例8: transfer

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.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 victim_user not 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_bank_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, password)
         self.write({
             "success":
             "Confirmed transfer to '%s' for $%d (15%s commission)" % (
                 destination.name, xfer, '%'
             )
         })
     else:
         self.write({"error": "Incorrect password for account, try again"})
     self.finish()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:45,代码来源:UpgradeHandlers.py

示例9: post

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
 def post(self, *args, **kwargs):
     ''' Checks submitted username and password '''
     user = User.by_handle(self.get_argument('account', ''))
     password_attempt = self.get_argument('password', '')
     if user is not None:
         if user.validate_password(password_attempt):
             if not user.locked:
                 self.successful_login(user)
                 if self.config.story_mode and user.logins == 1 and not user.is_admin():
                     self.redirect('/user/missions/firstlogin')
                 else:
                     self.redirect('/user')
             else:
                 self.render('public/login.html',
                             info=None, errors=["Your account has been locked"])
         else:
             self.failed_login()
     else:
         if password_attempt is not None:
             PBKDF2.crypt(password_attempt, "BurnTheHashTime")
         self.failed_login()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:23,代码来源:PublicHandlers.py

示例10: edit_user

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import by_handle [as 别名]
    def edit_user(self):
        ''' Update user objects in the database '''
        try:
            user = User.by_uuid(self.get_argument('uuid', ''))
            if user is None:
                raise ValidationError("User does not exist")
            handle = self.get_argument('handle', '')
            if user.handle != handle:
                if User.by_handle(handle) is None:
                    logging.info("Updated user handle %s -> %s" % (
                        user.handle, handle
                    ))
                    user.handle = handle
                else:
                    raise ValidationError("Handle is already in use")
            name = self.get_argument('name', '')
            email = self.get_argument('email', '')
            if user.name != name:
                logging.info("Updated user Name %s -> %s" % (
                        user.name, name
                    ))
                user.name = name
            if user.email != email:
                logging.info("Updated user Email %s -> %s" % (
                        user.email, email
                    ))
                user.email = email
            if options.banking:
                hash_algorithm = self.get_argument('hash_algorithm', '')
                if hash_algorithm != user.algorithm:
                    if hash_algorithm in user.algorithms:
                        if 0 < len(self.get_argument('bank_password', '')):
                            logging.info("Updated %s's hashing algorithm %s -> %s" % (
                                user.handle, user.algorithm, hash_algorithm,
                            ))
                            user.algorithm = hash_algorithm
                        else:
                            raise ValidationError(
                                "You must provide a new bank password when updating the hashing algorithm")
                    else:
                        raise ValidationError("Not a valid hash algorithm")
                if len(self.get_argument('bank_password', '')):
                    user.bank_password = self.get_argument('bank_password', '')
            password = self.get_argument('password', '')
            if password and len(password) > 0:
                user.password = password
            if hasattr(self.request, 'files') and 'avatarfile' in self.request.files:
                user.avatar = self.request.files['avatarfile'][0]['body']
            else:
                avatar = self.get_argument('avatar', user.avatar)
                #allow for default without setting
                user._avatar = avatar
            team = Team.by_uuid(self.get_argument('team_uuid', ''))
            if team is not None:
                if user not in team.members:
                    logging.info("Updated %s's team %s -> %s" % (
                        user.handle, user.team_id, team.name
                    ))
                    user.team_id = team.id
            elif options.teams:
                raise ValidationError("Team does not exist in database")
            self.dbsession.add(user)

            admin = self.get_argument('admin', 'false')
            if admin == 'true' and not user.is_admin():
                permission = Permission()
                permission.name = ADMIN_PERMISSION
                permission.user_id = user.id
                self.dbsession.add(permission)
            elif admin == 'false' and user.is_admin():
                permissions = Permission.by_user_id(user.id)
                for permission in permissions:
                    if permission.name == ADMIN_PERMISSION:
                        self.dbsession.delete(permission)
                
            self.dbsession.commit()
            self.redirect('/admin/users')
        except ValidationError as error:
            self.render("admin/view/users.html",
                        errors=[str(error), ]
                        )
开发者ID:moloch--,项目名称:RootTheBox,代码行数:83,代码来源:AdminUserHandlers.py


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