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


Python UserModel.find_by_username方法代码示例

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


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

示例1: test_crud

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
    def test_crud(self):
        with self.app_context():
            user = UserModel('test', 'abcd')

            self.assertIsNone(UserModel.find_by_username('test'), "Found an user with name 'test' before save_to_db")
            self.assertIsNone(UserModel.find_by_id(1), "Found an user with id '1' before save_to_db")

            user.save_to_db()

            self.assertIsNotNone(UserModel.find_by_username('test'),
                                 "Did not find an user with name 'test' after save_to_db")
            self.assertIsNotNone(UserModel.find_by_id(1), "Did not find an user with id '1' after save_to_db")
开发者ID:senarclens,项目名称:testing-python-apps,代码行数:14,代码来源:user_test.py

示例2: test_register_user

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
 def test_register_user(self):
     with self.app() as client:
         with self.app_context():
             response = client.post('/register', data={'username':'test', 'password':'1234'})
             self.assertEqual(response.status_code, 201)
             self.assertIsNotNone(UserModel.find_by_username('test'))
             self.assertDictEqual({'message':'User created successfully.'}, json.loads(response.data))
开发者ID:b9007,项目名称:Python,代码行数:9,代码来源:test_user.py

示例3: post

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
    def post(self):
        data = UserRegister.parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {"message": "User with that username already exists."}, 400
        user = UserModel(**data)
        user.save_to_db()
        return {"message": "User created successfully."}, 201
开发者ID:harrysoer,项目名称:flask-api,代码行数:10,代码来源:user.py

示例4: test_register_user

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
    def test_register_user(self):
        with self.app() as client:
            with self.app_context():
                response = client.post('/register', data = {'username': 'test', 'password': '1234'})

                self.assertEqual(response.status_code, 201)
                self.assertIsNotNone(UserModel.find_by_username('test'))
                # json.loads() used to convert json format to python dictionary
                self.assertDictEqual({"message": "User created successfully."}, json.loads(response.data))
开发者ID:lilitam,项目名称:stores_rest_api_test,代码行数:11,代码来源:test_user.py

示例5: post

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
    def post(self):
        data = _user_parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {"message": "A user with that username already exists"}, 400

        user = UserModel(data['username'], data['password'])
        user.save_to_db()

        return {"message": "User created successfully."}, 201
开发者ID:kpgdsc,项目名称:rest-api-sections,代码行数:12,代码来源:user.py

示例6: authenticate

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
def authenticate(username, password):
    """
    Function that gets called when a user calls the /auth endpoint with their username and password
    :param username: User's username in string format.
    :param password: User's un-encrypted password in string format.
    :return: A user if authentication was successful, None otherwise.
    """

    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user
开发者ID:b9007,项目名称:Python,代码行数:13,代码来源:security.py

示例7: post

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
    def post(self):
        data = _user_parser.parse_args()

        user = UserModel.find_by_username(data['username'])

        # this is what the `authenticate()` function did in security.py
        if user and safe_str_cmp(user.password, data['password']):
            # identity= is what the identity() function did in security.py—now stored in the JWT
            access_token = create_access_token(identity=user.id, fresh=True) 
            refresh_token = create_refresh_token(user.id)
            return {
                'access_token': access_token,
                'refresh_token': refresh_token
            }, 200

        return {"message": "Invalid Credentials!"}, 401
开发者ID:tecladocode,项目名称:flask-jwt-extended-section-lectures,代码行数:18,代码来源:user.py

示例8: authenticate

# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import find_by_username [as 别名]
def authenticate(username, password):
    user = UserModel.find_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user
开发者ID:harrysoer,项目名称:flask-api,代码行数:6,代码来源:security.py


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