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


Python User.set_password方法代码示例

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


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

示例1: test_change_password_form

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
    def test_change_password_form(self):
        # Set up a test user
        user = User(email='[email protected]')
        user.set_password('password')
        
        # The form should fail to validate if the current password is wrong.
        form = auth_forms.ChangePasswordForm({
                'current_password': 'incorrect password',
                'new_password': 'foo',
                'confirm_new_password': 'foo',
                })
        form.set_user(user)
        self.assertFalse(form.is_valid())

        # The form should fail to validate if the two versions of the
        # new password do not agree.
        form = auth_forms.ChangePasswordForm({
                'current_password': 'password',
                'new_password': 'foo',
                'confirm_new_password': 'bar',
                })
        form.set_user(user)
        self.assertFalse(form.is_valid())

        # This should work.
        form = auth_forms.ChangePasswordForm({
                'current_password': 'password',
                'new_password': 'foo',
                'confirm_new_password': 'foo',
                })
        form.set_user(user)
        self.assertTrue(form.is_valid())
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:34,代码来源:test_views.py

示例2: test_login_form

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
 def test_login_form(self):
     # Set up a test user.
     email = '[email protected]'
     user = User(email=email)
     user.set_password('password')
     user.save()
     # Missing required data
     form = auth_forms.LoginForm({'redirect': '/'})
     self.assertFalse(form.is_valid())
     form = auth_forms.LoginForm({'redirect': '/', 'email': email})
     self.assertFalse(form.is_valid())
     # Form should fail to validate if password is incorrect.
     form = auth_forms.LoginForm({'redirect': '/',
                                  'email': email,
                                  'password': 'incorrect password'})
     self.assertFalse(form.is_valid())
     # This should succeed.
     form = auth_forms.LoginForm({'redirect': '/',
                                  'email': email,
                                  'password': 'password'})
     self.assertTrue(form.is_valid())
     # The form should reject inactive users.
     user.is_active = False
     user.save()
     form = auth_forms.LoginForm({'redirect': '/',
                                  'email': email,
                                  'password': 'password'})
     self.assertFalse(form.is_valid())
     # The form should reject unknown users.
     form = auth_forms.LoginForm({'redirect': '/',
                                  'email': '[email protected]',
                                  'password': 'password'})
     self.assertFalse(form.is_valid())
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:35,代码来源:test_views.py

示例3: test_forgot_password_form_case_insensitive_email

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
 def test_forgot_password_form_case_insensitive_email(self):
     # Set up a test user
     user = User(email='[email protected]')
     user.set_password('password')
     user.save()
     
     form = auth_forms.ForgotPasswordForm({'email': '[email protected]'})
     self.assertTrue(form.is_valid())
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:10,代码来源:test_views.py

示例4: test_login_with_case_insensitive_email

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
 def test_login_with_case_insensitive_email(self):
     # Set up a test user.
     email = '[email protected]'
     user = User(email=email)
     user.set_password('password')
     user.save()
     
     # This should succeed.
     form = auth_forms.LoginForm({'redirect': '/',
                                  'email': '[email protected]',
                                  'password': 'password'})
     self.assertTrue(form.is_valid())
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:14,代码来源:test_views.py

示例5: test_forgot_password_form

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
 def test_forgot_password_form(self):
     # Set up a test user
     user = User(email='[email protected]')
     user.set_password('password')
     user.save()
     # The form will validate if given a known email address.
     form = auth_forms.ForgotPasswordForm({'email': user.email})
     self.assertTrue(form.is_valid())
     # Check that the user gets attached to the form's user
     # property.
     self.assertEqual(user.email, form.user.email)
     # The form will not validate for an unknown email address.
     form = auth_forms.ForgotPasswordForm({'email': '[email protected]'})
     self.assertFalse(form.is_valid())
     self.assertEqual(None, form.user)
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:17,代码来源:test_views.py

示例6: bootstrap

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def bootstrap(request):
    """If the visitor is a chirpradio admin, create a user for them."""
    if request.user is None:
        g_user = google_users.get_current_user()
        if g_user is None:
            return http.HttpResponseRedirect(
                google_users.create_login_url(request.path))
        if not google_users.is_current_user_admin():
            return http.HttpResponseForbidden('Not a chirpradio project admin')
        user = User.get_by_email(g_user.email())
        if user:
            return http.HttpResponseForbidden(
                'User %s already exists' % user.email)
        user = User(email=g_user.email(), is_superuser=True)
        user.set_password("test")
        user.save()
        return http.HttpResponseRedirect(auth.create_login_url('/'))
    return http.HttpResponseForbidden("Already logged in")
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:20,代码来源:views.py

示例7: CoreTest

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
class CoreTest(unittest.TestCase):
    def setUp(self):
        self.user = User(username="core_tester",
                         first_name="first",
                         last_name="last", 
                         email="[email protected]")
        self.user.set_password("test")
        self.user.save()
    
    def tearDown(self):
        self.user.delete()
        
    def test_email_backend(self):
        #from django.contrib.auth import login
        request =  object()
        request.POST = {'username': 'core_tester',
                        'password': 'test'}
        
        from auth import login
        login(request, self.user)
开发者ID:HengWang,项目名称:CollectorCity-Market-Place,代码行数:22,代码来源:tests.py

示例8: to_user

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
    def to_user(self):
        data = self.cleaned_data.copy()

        user_roles = []
        for r in roles.ALL_ROLES:
            key = "is_" + r
            if key in data:
                if data[key]:
                    user_roles.append(r)
                del data[key]
        data["roles"] = user_roles

        if data["original_email"]:
            # update the user (edit form)...
            user = User.get_by_email(data["original_email"])
            for key, val in data.items():
                # update all attributes with form values except our
                # placeholder field, original_email; also handle password as a special case
                if key == "password":
                    if val:
                        # only change the password if it was filled in on the edit form:
                        user.set_password(val)
                elif key != "original_email":
                    setattr(user, key, val)
            user.save()
        else:
            # creating new user...
            del data["original_email"]
            initial_password = None
            if data["password"]:
                # this is uncommon
                initial_password = data["password"]
            del data["password"]
            user = User(**data)
            if initial_password:
                user.set_password(initial_password)
                user.save()
        return user
开发者ID:kumar303,项目名称:chirpradio,代码行数:40,代码来源:forms.py

示例9: test_user_password_checks

# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
 def test_user_password_checks(self):
     user = User(email='[email protected]')
     self.assertFalse(user.check_password('foo'))
     user.set_password('foo')
     self.assertTrue(user.check_password('foo'))
     self.assertFalse(user.check_password('bar'))
开发者ID:BubbleTouchSoftware,项目名称:chirpradio,代码行数:8,代码来源:test_views.py


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