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


Python User.set_password方法代码示例

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


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

示例1: test_reset_password_post_failure_invalid_input

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_reset_password_post_failure_invalid_input(self):
        """
            Test posting to the password reset form with an anonymous user, a valid token, and an invalid form.

            Expected result: The password is not updated and the user is shown the reset password form.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        token_obj = ResetPasswordToken()
        token_obj.user_id = user_id
        token = token_obj.create()

        new_password = 'abcdef'
        response = self.client.post(f'/user/reset-password/{token}', follow_redirects=True, data=dict(
            password=new_password,
            password_confirmation=new_password + 'ghi'
        ))
        data = response.get_data(as_text=True)

        self.assertIn('Reset Your Password', data)
        self.assertNotIn('The token is invalid.', data)
        self.assertNotIn('Your password has successfully been changed.', data)
        self.assertFalse(user.check_password(new_password))
        self.assertTrue(user.check_password(password))
开发者ID:BMeu,项目名称:Aerarium,代码行数:35,代码来源:password_reset_test.py

示例2: test_user_settings_post

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_user_settings_post(self):
        """
            Test posting to the user settings page.

            Expected result: The form is shown with the new data, the language is updated.
        """
        email = '[email protected]'
        name = 'Jane Doe'
        password = '123456'
        user = User(email, name)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()

        self.assertEqual('en', user.settings.language)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        new_language = 'de'
        response = self.client.post('/user/settings', follow_redirects=True, data=dict(
            language=new_language,
        ))
        data = response.get_data(as_text=True)

        self.assertNotIn('Settings', data)
        self.assertNotIn('Your changes have been saved.', data)
        self.assertIn('Einstellungen', data)
        self.assertIn('Deine Änderungen wurden gespeichert.', data)

        self.assertEqual(new_language, user.settings.language)
开发者ID:BMeu,项目名称:Aerarium,代码行数:35,代码来源:user_settings_test.py

示例3: test_reset_password_get_logged_in

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_reset_password_get_logged_in(self):
        """
            Test accessing the password reset form with a user who is logged in, and a valid token.

            Expected result: The user is redirected to the home page.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        token_obj = ResetPasswordToken()
        token_obj.user_id = user_id
        token = token_obj.create()

        response = self.client.get(f'/user/reset-password/{token}', follow_redirects=True)
        data = response.get_data(as_text=True)

        self.assertIn('Dashboard', data)
        self.assertNotIn('The token is invalid.', data)
        self.assertNotIn('Reset Your Password', data)
        self.assertNotIn('Your password has successfully been changed.', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:35,代码来源:password_reset_test.py

示例4: test_login_refresh_get_fresh

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_login_refresh_get_fresh(self):
        """
            Test accessing the login refresh page with an freshly authorized user.

            Expected result: The user is redirected to the home page.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        response = self.client.get('/user/login/refresh', follow_redirects=True)
        data = response.get_data(as_text=True)

        self.assertNotIn('<h1>Confirm Login</h1>', data)
        self.assertIn('<h1>Dashboard</h1>', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:29,代码来源:authentication_test.py

示例5: test_user_settings_get

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_user_settings_get(self):
        """
            Test getting the user settings.

            Expected result: The form is shown with prepopulated data.
        """
        email = '[email protected]'
        name = 'Jane Doe'
        password = '123456'
        user = User(email, name)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        response = self.client.get('/user/settings', follow_redirects=True)
        data = response.get_data(as_text=True)

        self.assertIn('Settings', data)
        self.assertNotIn('Your changes have been saved.', data)

        # Ensure that the user's current language is preselected in the form.
        self.assertIn(f'<option selected value="{user.settings.language}">', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:29,代码来源:user_settings_test.py

示例6: test_reset_password_request_post_existing_user

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_reset_password_request_post_existing_user(self):
        """
            Test accessing the password reset request form via POST with an existing user.

            Expected result: The password reset mail is sent to the user and a message is displayed.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        with mail.record_messages() as outgoing:
            response = self.client.post('/user/reset-password', follow_redirects=True, data=dict(
                email=email
            ))
            data = response.get_data(as_text=True)

            self.assertEqual(1, len(outgoing))
            self.assertIn('Reset Your Password', outgoing[0].subject)

            self.assertIn('<h1>Log In</h1>', data)
            self.assertIn('An email has been sent to the specified address.', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:30,代码来源:password_reset_test.py

示例7: test_permission_required_one_of_has_permission

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_permission_required_one_of_has_permission(self):
        """
            Test the `permission_required` decorator if the user has one of the requested permission, but not all.

            Expected result: The decorated view function is returned.
        """

        email = '[email protected]'
        name = 'Jane Doe'
        password = '123456'
        user = User(email, name)
        user.set_password(password)
        user.role = Role('Administrator')
        user.role.permissions = Permission.EditRole

        db.session.add(user)
        db.session.commit()

        user.login(email, password)

        self.assertTrue(user.role.has_permission(Permission.EditRole))
        self.assertFalse(user.role.has_permission(Permission.EditUser))

        view_function = permission_required_one_of(Permission.EditRole, Permission.EditUser)(self.view_function)
        response = view_function()
        self.assertEqual(self.view_function(), response)
开发者ID:BMeu,项目名称:Aerarium,代码行数:28,代码来源:decorators_test.py

示例8: test_delete_profile_failure

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_delete_profile_failure(self):
        """
            Test deleting the account with an invalid token.

            Expected result: The account is not deleted.
        """

        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        response = self.client.get('/user/delete/invalid-token', follow_redirects=True)
        data = response.get_data(as_text=True)

        self.assertEqual(404, response.status_code)
        self.assertIsNotNone(User.load_from_id(user_id))
        self.assertNotIn('Your user profile and all data linked to it have been deleted.', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:31,代码来源:delete_profile_test.py

示例9: test_delete_profile_request_failure

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_delete_profile_request_failure(self):
        """
            Test requesting the deletion of the user's account with an invalid form.
            Expected result: No email is sent.
        """

        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        with mail.record_messages() as outgoing:
            response = self.client.post('/user/delete', follow_redirects=True, data=dict())
            data = response.get_data(as_text=True)

            self.assertEqual(0, len(outgoing))

            self.assertNotIn('An email has been sent to your email address.', data)
            self.assertNotIn('to delete your user profile.', data)
            self.assertIn('<h1>User Profile</h1>', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:33,代码来源:delete_profile_test.py

示例10: test_index_logged_in

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_index_logged_in(self):
        """
            Test accessing the dashboard with a logged in user.

            Expected result: The user is shown the dashboard.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        response = self.client.get('/', follow_redirects=True)
        data = response.get_data(as_text=True)

        self.assertIn('<h1>Dashboard</h1>', data)
        self.assertNotIn('<h1>Log In</h1>', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:29,代码来源:routes_test.py

示例11: test_delete_profile_success

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_delete_profile_success(self):
        """
            Test deleting the account with a valid token.

            Expected result: The account is successfully deleted.
        """

        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        token_obj = DeleteAccountToken()
        token_obj.user_id = user.id

        token = token_obj.create()
        response = self.client.get('/user/delete/' + token, follow_redirects=True)
        data = response.get_data(as_text=True)

        self.assertIsNone(User.load_from_id(user_id))
        self.assertIn('Your user profile and all data linked to it have been deleted.', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:34,代码来源:delete_profile_test.py

示例12: test_login_post_success

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_login_post_success(self):
        """
            Test logging in with valid credentials.

            Expected result: The login succeeds, the user is redirected to the home page and greeted.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        response = self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))
        data = response.get_data(as_text=True)

        self.assertNotIn('<h1>Log In</h1>', data)
        self.assertIn('<h1>Dashboard</h1>', data)
        self.assertIn(f'Welcome, {name}!', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:28,代码来源:authentication_test.py

示例13: test_logout_logged_in

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_logout_logged_in(self):
        """
            Test logging out with a logged in user.

            Expected result: The user is logged out, redirected to the home page (and from there to the login page),
                             and shown a success message.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        response = self.client.get('/user/logout', follow_redirects=True)
        data = response.get_data(as_text=True)

        self.assertIn('You were successfully logged out.', data)
        self.assertIn('<h1>Log In</h1>', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:30,代码来源:authentication_test.py

示例14: test_login_refresh_post_valid_password

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_login_refresh_post_valid_password(self, mock_login_fresh: MagicMock):
        """
            Test refreshing the login with a valid password.

            Expected result: The refresh home page is shown, the login is refreshed.
        """
        mock_login_fresh.return_value = False

        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        self.client.post('/user/login', follow_redirects=True, data=dict(
            email=email,
            password=password
        ))

        response = self.client.post('/user/login/refresh', follow_redirects=True, data=dict(
            password=password
        ))
        data = response.get_data(as_text=True)

        self.assertNotIn('<h1>Confirm Login</h1>', data)
        self.assertNotIn('Invalid password', data)
        self.assertIn(f'Welcome, {name}!', data)
        self.assertIn('<h1>Dashboard</h1>', data)
开发者ID:BMeu,项目名称:Aerarium,代码行数:35,代码来源:authentication_test.py

示例15: test_reset_password_post_failure_invalid_token

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import set_password [as 别名]
    def test_reset_password_post_failure_invalid_token(self):
        """
            Test posting to the password reset form with an anonymous user, an invalid token, and a valid form.

            Expected result: The password is not updated and the user is shown a 404 error page.
        """
        email = '[email protected]'
        password = '123456'
        name = 'John Doe'
        user_id = 1
        user = User(email, name)
        user.set_password(password)

        db.session.add(user)
        db.session.commit()
        self.assertEqual(user_id, user.id)

        new_password = 'abcdef'
        response = self.client.post('/user/reset-password/just-some-token', follow_redirects=True, data=dict(
            password=new_password,
            password_confirmation=new_password
        ))
        data = response.get_data(as_text=True)

        self.assertEqual(404, response.status_code)
        self.assertNotIn('Your password has successfully been changed.', data)
        self.assertFalse(user.check_password(new_password))
        self.assertTrue(user.check_password(password))
开发者ID:BMeu,项目名称:Aerarium,代码行数:30,代码来源:password_reset_test.py


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