當前位置: 首頁>>代碼示例>>Python>>正文


Python User.username方法代碼示例

本文整理匯總了Python中core.models.User.username方法的典型用法代碼示例。如果您正苦於以下問題:Python User.username方法的具體用法?Python User.username怎麽用?Python User.username使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在core.models.User的用法示例。


在下文中一共展示了User.username方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: authenticate

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import username [as 別名]
    def authenticate(self, saml_authentication=None):
        if not saml_authentication:  # Using another authentication method
            return None

        if saml_authentication.is_authenticated():
            attributes = saml_authentication.get_attributes()
            user_changed = False
            try:
                user = User.objects.get(username=saml_authentication.get_attributes()['uid'][0])
            except User.DoesNotExist:
                user = User(username=saml_authentication.get_attributes()['uid'][0])
                user.set_unusable_password()
                user.username = attributes['uid'][0]

            map_fields = {
                'realname': 'cn',
                'email': 'mail'
            }

            # ensure realname for users from webid don't contain unverified note
            if 'cn' in attributes:
                attributes['cn'][0] = attributes['cn'][0].replace(' (unverified)', '')

            for field, samlfield in map_fields.items():
                if getattr(user, field) != attributes[samlfield][0]:
                    setattr(user, field, attributes[samlfield][0])
                    user_changed = True

            if user_changed:
                user.save()

            return user
        return None
開發者ID:cybrairai,項目名稱:internsystem,代碼行數:35,代碼來源:auth_backend.py

示例2: test_call_register_channel

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import username [as 別名]
    def test_call_register_channel(self):
        '''
        Test registration to a channel
        '''

        u = User()
        u.username = "sample_post"
        u.first_name = "sample_post"
        u.email = "[email protected]"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "PostSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid5'
        sub1.save()


        resp = ask_subscribe_channel(ch1, sub1.device_id)

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
        self.client.login(username='test_user', password='password')

        data = {
                'channel' : ch1.name,
                'token' : sub1.token,
                'browser' : 'chrome',
                'device_id' : sub1.device_id
        }

        response = self.client.post(reverse('browser-registration'), json.dumps(data), sub1.token)

        self.assertTrue(response.status_code, 200)
開發者ID:Mikelord2,項目名稱:pushetta-api-django,代碼行數:49,代碼來源:test.py

示例3: test_call_delete

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import username [as 別名]
    def test_call_delete(self):
        '''
        Test deleting of a registration of a device from a channel
        '''

        u = User()
        u.username = "sample_del"
        u.first_name = "sample_del"
        u.email = "[email protected]"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "DelSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid6'
        sub1.save()


        resp = ask_subscribe_channel(ch1, sub1.device_id)

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
        self.client.login(username='test_user', password='password')

        response = self.client.delete(reverse('browser-get-registration', kwargs={'device_id': sub1.device_id,
                                                                       'channel_name' : ch1.name}))

        self.assertEqual(response.status_code, 200)

        channels = SubscriberManager().get_device_subscriptions(sub1.device_id)
        sub_channel = next((x for x in channels if x == ch1.name.lower()), None)

        self.assertIsNone(sub_channel)
開發者ID:Mikelord2,項目名稱:pushetta-api-django,代碼行數:48,代碼來源:test.py

示例4: test_call_get

# 需要導入模塊: from core.models import User [as 別名]
# 或者: from core.models.User import username [as 別名]
    def test_call_get(self):
        '''
        Test check if a device is registered to a channel
        '''

        u = User()
        u.username = "sample_un"
        u.first_name = "Sample_un"
        u.email = "[email protected]"
        u.set_password("123")
        u.save()

        ch1 = Channel()

        ch1.owner = u
        ch1.name = "GetSub"
        ch1.image = 'http://www.google.com'
        ch1.description = "A channel description"
        ch1.kind = PUBLIC
        ch1.hidden = False
        ch1.subscriptions = 0

        ch1.save()

        sub1 = Subscriber()
        sub1.sub_type = 'type2'
        sub1.token = 'token2'
        sub1.device_id = 'devid4'
        sub1.save()


        resp = ask_subscribe_channel(ch1, 'devid4')

        self.assertEqual(resp, SubscribeResponse.SUBSCRIBED)
        test_user = User.objects.create_superuser('test_user', '[email protected]', 'password')
        self.client.login(username='test_user', password='password')

        response = self.client.get(reverse('browser-get-registration', kwargs={'device_id': 'devid4', 'channel_name' : 'GetSub'}) )
        
        self.assertTrue(response.status_code, 200)
開發者ID:Mikelord2,項目名稱:pushetta-api-django,代碼行數:42,代碼來源:test.py


注:本文中的core.models.User.username方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。