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


Python User.users方法代码示例

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


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

示例1: deleteToken

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
    def deleteToken(self, args):
        self._start(args)
        print('Delete token: please authenticate...')
        
        while True:
            admin_username = raw_input('Enter admin username: ')
            admin_password = getpass.getpass('Enter admin password: ')
            if not User.users().get(username=admin_username).admin: #Db.instance().is_admin(admin_username):
                print('Please sign in using administrator credentials.')
            elif not User.users().get(username=admin_username).authenticate(admin_password): #Db.instance().authenticate_user(admin_username, admin_password):
                print("Username/password don't match.")
            else:
                break

        username = raw_input('Enter username for token to delete: ')
        user = User.users().get(username=username)
        if user:
            token = Token.tokens().get_token_for_user(user=user)
            if token:
                token.delete()
                print('Deleted token belonging to %s.' % username)
            else:
                print('%s has no tokens to delete.' % username)
        else:
            print('%s has no tokens to delete.' % username)
开发者ID:silverfernsys,项目名称:sremote,代码行数:27,代码来源:app.py

示例2: createToken

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
    def createToken(self, args):
        self._start(args)
        # Do a check to see if any admins exist before proceeding.
        print('Create token: please authenticate...')
        
        while True:
            admin_username = raw_input('Enter admin username: ')
            admin_password = getpass.getpass('Enter admin password: ')
            if not User.users().get(username=admin_username).admin:
                print('Please sign in using administrator credentials.')
            elif not User.users().get(username=admin_username).authenticate(admin_password):
                print("Username/password don't match.")
            else:
                break

        username = raw_input('Enter username to create a token for: ')
        user = User.users().get(username=username)
        if user:
            try:
                token = Token(user=user)
                token.save()
                print(str('Token %s created for %s' % (token.token, username)))
            except Exception as e:
                print("EXCEPTION **** %s" % e)
                print('A token already exists for %s. Doing nothing.' % username)
        else:
            print('A user with username %s does not exist.' % username)
开发者ID:silverfernsys,项目名称:sremote,代码行数:29,代码来源:app.py

示例3: createUser

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
    def createUser(self, args):
        self._start(args)

        while True:
            username = raw_input('Enter email address: ')
            if User.users().get(username=username):
                print('Username already exists. Please pick another username.')
            else:
                break
            print('username: %s' % username)
        while True:
            is_admin = raw_input('Admininstrative user? (y/N): ')
            if (len(is_admin) == 0) or (is_admin.upper() == 'N'):
                admin = False
                break
            elif is_admin.upper() == 'Y':
                admin = True
                break
        while True:
            password_1 = getpass.getpass('Enter password: ')
            password_2 = getpass.getpass('Re-enter password: ')
            if password_1 != password_2:
                print('Passwords do not match.')
            else:
                break

        user = User(username, password_1, admin)
        user.save()
        # Db.instance().insert_user(username, password_1, admin)
        print('Successfully created user %s' % username)
开发者ID:silverfernsys,项目名称:sremote,代码行数:32,代码来源:app.py

示例4: listUsers

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
    def listUsers(self, args):
        self._start(args)

        print("%s%sCreated" % ("Username".ljust(70), "Admin".ljust(20)))
        for user in User.users().all():
            if user.admin:
                admin_str = 'Y'
            else:
                admin_str = 'N'
            # https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
            line = "%s%s%s" % (user.username.ljust(70), admin_str.ljust(20), datetime.fromtimestamp(user.created).strftime('%d-%m-%Y %H:%M:%S'))
            print(str(line))
开发者ID:silverfernsys,项目名称:sremote,代码行数:14,代码来源:app.py

示例5: deleteUser

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
    def deleteUser(self, args):
        self._start(args)

        print('Delete user: please authenticate...')
        while True:
            admin_username = raw_input('Enter admin username: ')
            admin_password = getpass.getpass('Enter admin password: ')
            user = User.users().get(username=admin_username)
            if not user.admin:
                print('Please sign in using administrator credentials.')
            elif not user.authenticate(admin_password):
                print("Username/password don't match.")
            else:
                break

        username_to_delete = raw_input('Enter username to delete: ')
        if User.users().get(username=username_to_delete).delete():
            # Db.instance().delete_user(username_to_delete)
            print('Deleted user %s.' % username_to_delete)
        else:
            sys.exit("User doesn't exist. Doing nothing.")
开发者ID:silverfernsys,项目名称:sremote,代码行数:23,代码来源:app.py

示例6: get

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import users [as 别名]
 def get(self):
     try:
         username = self.request.headers.get('username')
         password = self.request.headers.get('password')
         user = User.users().get(username=username)
         if user.authenticate(password):
             token = Token.tokens().get_token_for_user(user)
             if not token:
                 token = Token(user=user)
                 token.save()
             data = {'token': token.token}
         else:
             data = {'error': 'invalid username/password'}
     except Exception as e:
         data = {'error': str(e)}
     self.set_header('Content-Type', 'application/json')
     self.write(json.dumps(data))
开发者ID:silverfernsys,项目名称:sremote,代码行数:19,代码来源:http.py


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