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


Python User.load_from_id方法代码示例

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


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

示例1: test_change_email_failure_invalid_token

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [as 别名]
    def test_change_email_failure_invalid_token(self):
        """
            Test accessing the change email page with an invalid token.

            Expected result: The email address is not changed and a 404 error page is shown.
        """
        email = '[email protected]'
        name = 'John Doe'
        user = User(email, name)

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

        user_id = user.id
        new_email = '[email protected]'
        token_obj = ChangeEmailAddressToken()
        token_obj.user_id = user_id
        token_obj.new_email = new_email
        token = token_obj.create()

        response = self.client.get(f'/user/change-email-address/invalid-{token}', follow_redirects=True)
        user = User.load_from_id(user_id)

        self.assertEqual(404, response.status_code)
        self.assertEqual(email, user.get_email())
开发者ID:BMeu,项目名称:Aerarium,代码行数:27,代码来源:profile_test.py

示例2: test_change_email_failure_email_in_use

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [as 别名]
    def test_change_email_failure_email_in_use(self):
        """
            Test accessing the change email page with an email address that already is in use by another user.

            Expected result: The email address is not changed.
        """
        existing_email = '[email protected]'
        existing_name = 'Jane Doe'
        existing_user = User(existing_email, existing_name)

        email = '[email protected]'
        name = 'John Doe'
        user = User(email, name)

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

        user_id = user.id
        token_obj = ChangeEmailAddressToken()
        token_obj.user_id = user_id
        token_obj.new_email = existing_email
        token = token_obj.create()

        response = self.client.get(f'/user/change-email-address/{token}', follow_redirects=True)
        data = response.get_data(as_text=True)
        user = User.load_from_id(user_id)

        self.assertIn('The email address already is in use.', data)
        self.assertEqual(email, user.get_email())
开发者ID:BMeu,项目名称:Aerarium,代码行数:32,代码来源:profile_test.py

示例3: test_change_email_success

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [as 别名]
    def test_change_email_success(self):
        """
            Test accessing the change email page with a valid token.

            Expected result: The email address is changed.
        """
        email = '[email protected]'
        name = 'John Doe'
        user = User(email, name)

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

        user_id = user.id
        new_email = '[email protected]'
        token_obj = ChangeEmailAddressToken()
        token_obj.user_id = user_id
        token_obj.new_email = new_email
        token = token_obj.create()

        response = self.client.get(f'/user/change-email-address/{token}', follow_redirects=True)
        data = response.get_data(as_text=True)
        user = User.load_from_id(user_id)

        self.assertIn('Your email address has successfully been changed.', data)
        self.assertEqual(new_email, user.get_email())
开发者ID:BMeu,项目名称:Aerarium,代码行数:28,代码来源:profile_test.py

示例4: test_delete_profile_failure

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [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

示例5: test_delete_profile_success

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [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

示例6: test_user_profile_post_name_and_password_and_email

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [as 别名]
    def test_user_profile_post_name_and_password_and_email(self):
        """
            Test posting to the user profile page with the name, the password, and the email changed.

            Expected result: The form is shown with the new data. The user's name and password are changed, the email
                             is not, but a mail has been sent to the new address.
        """
        email = '[email protected]'
        name = 'John Doe'
        password = '123456'
        user = User(email, name)
        user.set_password(password + '!')
        with mail.record_messages() as outgoing:
            user.set_password(password)
            self.assertEqual(1, len(outgoing))
            self.assertIn('Your Password Has Been Changed', outgoing[0].subject)
        db.session.add(user)
        db.session.commit()

        user_id = user.id

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

        new_name = 'Jane Doe'
        new_password = '654321'
        new_email = '[email protected]'
        with mail.record_messages() as outgoing:
            response = self.client.post('/user/profile', follow_redirects=True, data=dict(
                name=new_name,
                email=new_email,
                password=new_password,
                password_confirmation=new_password
            ))
            data = response.get_data(as_text=True)

            self.assertEqual(2, len(outgoing))
            self.assertIn('Change Your Email Address', outgoing[1].subject)
            self.assertEqual([new_email], outgoing[1].recipients)

            self.assertIn('User Profile', data)
            self.assertIn(f'value="{new_name}"', data)
            self.assertIn(f'value="{email}"', data)
            self.assertIn('Your changes have been saved.', data)
            self.assertIn('An email has been sent to the new address', data)

            user = User.load_from_id(user_id)
            self.assertEqual(new_name, user.name)
            self.assertEqual(email, user.get_email())
            self.assertTrue(user.check_password(new_password))
开发者ID:BMeu,项目名称:Aerarium,代码行数:54,代码来源:profile_test.py

示例7: test_user_profile_post_only_name

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [as 别名]
    def test_user_profile_post_only_name(self):
        """
            Test posting to the user profile page with only the name changed.

            Expected result: The form is shown with the new data. The user's name is changed, everything else is not.
        """
        email = '[email protected]'
        name = 'John Doe'
        password = '123456'
        user = User(email, name)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()

        user_id = user.id

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

        new_name = 'Jane Doe'
        with mail.record_messages() as outgoing:
            response = self.client.post('/user/profile', follow_redirects=True, data=dict(
                name=new_name,
                email=email
            ))
            data = response.get_data(as_text=True)

            self.assertEqual(0, len(outgoing))

            self.assertIn('User Profile', data)
            self.assertIn(f'value="{new_name}"', data)
            self.assertIn(f'value="{email}"', data)
            self.assertIn('Your changes have been saved.', data)
            self.assertNotIn('An email has been sent to the new address', data)

            user = User.load_from_id(user_id)
            self.assertEqual(new_name, user.name)
            self.assertEqual(email, user.get_email())
            self.assertTrue(user.check_password(password))
开发者ID:BMeu,项目名称:Aerarium,代码行数:43,代码来源:profile_test.py

示例8: user_profile

# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import load_from_id [as 别名]
def user_profile() -> str:
    """
        Show a page to edit account details. Upon submission, change the account details.

        :return: The HTML response.
    """

    profile_form = UserProfileForm(obj=current_user, email=current_user.get_email())
    if profile_form.validate_on_submit():

        # Always change the name.
        user = User.load_from_id(current_user.get_id())
        user.name = profile_form.name.data

        # If the user entered a password, change that as well.
        if profile_form.password.data:
            user.set_password(profile_form.password.data)

        # Write the changes to the database.
        db.session.commit()

        # If the email address changed send a confirmation mail to the new address.
        if user.get_email() != profile_form.email.data:
            token = user.send_change_email_address_email(profile_form.email.data)

            validity = token.get_validity(in_minutes=True)
            flash(Markup(_('An email has been sent to the new address %(email)s. Please open the link included in the \
                            mail within the next %(validity)d minutes to confirm your new email address. Otherwise, \
                            your email address will not be changed.',
                           email='<em>{email}</em>'.format(email=profile_form.email.data), validity=validity)),
                  category='warning')

        flash(_('Your changes have been saved.'))
        return redirect(url_for('userprofile.user_profile'))

    delete_form = DeleteUserProfileForm()
    return render_template('userprofile/profile.html', title=_('User Profile'), profile_form=profile_form,
                           delete_form=delete_form)
开发者ID:BMeu,项目名称:Aerarium,代码行数:40,代码来源:profile.py


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