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


Python User.set_password方法代碼示例

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


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

示例1: test_normal_user_cannot_set_other_to_admin

# 需要導入模塊: from streetsign_server.models import User [as 別名]
# 或者: from streetsign_server.models.User import set_password [as 別名]
    def test_normal_user_cannot_set_other_to_admin(self):
        user2 = User(loginname="user2",
                     emailaddress='[email protected]',
                     is_admin=False)
        user2.set_password("userpass2")
        user2.save()

        self.login(USERNAME, USERPASS)
        resp = self.post_update_request(userid=user2.id, is_admin=True)

        self.assertEqual(resp.status_code, 403)

        usernow = User.get(id=user2.id)
        self.assertEqual(usernow.is_admin, False)
開發者ID:Fivebread,項目名稱:streetsign,代碼行數:16,代碼來源:test_views_users_and_auth.py

示例2: BasicUsersTestCase

# 需要導入模塊: from streetsign_server.models import User [as 別名]
# 或者: from streetsign_server.models.User import set_password [as 別名]
class BasicUsersTestCase(StreetSignTestCase):
    def setUp(self):
        super(BasicUsersTestCase, self).setUp()
        self.user = User(loginname=USERNAME,
                         emailaddress='[email protected]',
                         is_admin=False)
        self.user.set_password(USERPASS)
        self.user.save()


        self.admin = User(loginname=ADMINNAME,
                          emailaddress='[email protected]',
                          is_admin=True)
        self.admin.set_password(ADMINPASS)
        self.admin.save()
開發者ID:Fivebread,項目名稱:streetsign,代碼行數:17,代碼來源:test_views_users_and_auth.py

示例3: test_cannot_have_matching_usernames

# 需要導入模塊: from streetsign_server.models import User [as 別名]
# 或者: from streetsign_server.models.User import set_password [as 別名]
    def test_cannot_have_matching_usernames(self):
        user2 = User(loginname='user2',
                     emailaddress='[email protected]',
                     is_admin=False)
        user2.set_password(USERPASS)
        user2.save()

        # if this get works, then the user exists:
        usernow = User.get(loginname="user2")
        self.assertEqual(user2.id, usernow.id)

        self.login(ADMINNAME, ADMINPASS)
        resp = self.post_create_request(currpass=ADMINPASS,
                                        newpass='not42', conf_newpass='not42')
        self.assertIn("Username already exists", resp.data)

        # and just make sure we didn't delete them, or set their password...

        usernew = User.get(loginname="user2")
        self.assertEqual(usernow.passwordhash, usernew.passwordhash)
開發者ID:Fivebread,項目名稱:streetsign,代碼行數:22,代碼來源:test_views_users_and_auth.py

示例4: test_cannot_change_other_users_password_even_with_their_currpass

# 需要導入模塊: from streetsign_server.models import User [as 別名]
# 或者: from streetsign_server.models.User import set_password [as 別名]
    def test_cannot_change_other_users_password_even_with_their_currpass(self):

        user2 = User(loginname="user2",
                     emailaddress='[email protected]',
                     is_admin=False)
        user2.set_password("userpass2")
        user2.save()

        self.login(USERNAME, USERPASS)

        with self.ctx():
            resp = self.client.post(url_for('user_edit', userid=user2.id),
                                    data={"action":"update",
                                          "newpass": "200",
                                          "conf_newpass": "200",
                                          "currpass": "userpass2"},
                                    follow_redirects=True)

        self.assertIn("Permission Denied", resp.data)
        self.assertEquals(resp.status_code, 403)

        usernow = User.get(id=user2.id)
        self.assertEqual(usernow.passwordhash, user2.passwordhash)
開發者ID:Fivebread,項目名稱:streetsign,代碼行數:25,代碼來源:test_views_users_and_auth.py

示例5: DeletingUsers

# 需要導入模塊: from streetsign_server.models import User [as 別名]
# 或者: from streetsign_server.models.User import set_password [as 別名]
class DeletingUsers(BasicUsersTestCase):
    ''' Only admin can delete users, and not themselves. '''

    def setUp(self):
        super(DeletingUsers, self).setUp()

        self.user2 = User(loginname='user2',
                          emailaddress='[email protected]',
                          is_admin=False)
        self.user2.set_password(USERPASS)
        self.user2.save()

    def post_delete_request(self, userid=False, **kwargs):
        data = {}
        data.update(kwargs)

        if userid == False:
            userid = self.user2.id

        with self.ctx():
            return self.client.delete(url_for('user_edit', userid=userid),
                                      data=data,
                                      follow_redirects=True)

    def test_logged_out_cannot_delete_user(self):
        resp = self.post_delete_request()
        self.assertEqual(resp.status_code, 403)
        User.get(id=self.user2.id)

    def test_normal_user_cannot_delete_user(self):
        self.login(USERNAME, USERPASS)
        resp = self.post_delete_request()
        self.assertEqual(resp.status_code, 403)
        User.get(id=self.user2.id)

    def test_normal_user_cannot_delete_self(self):
        self.login(USERNAME, USERPASS)
        resp = self.post_delete_request(userid=self.user.id)
        self.assertEqual(resp.status_code, 403)

        User.get(id=self.user.id)

    def test_normal_user_cannot_delete_admin(self):
        self.login(USERNAME, USERPASS)
        resp = self.post_delete_request(userid=self.admin.id)
        self.assertEqual(resp.status_code, 403)

        User.get(id=self.admin.id)

    def test_admin_can_delete_user(self):
        self.login(ADMINNAME, ADMINPASS)
        resp = self.post_delete_request()
        self.assertEqual(resp.status_code, 200)

        with self.assertRaises(User.DoesNotExist):
            User.get(id=self.user2.id)

    def test_admin_cannot_delete_self(self):
        self.login(ADMINNAME, ADMINPASS)
        resp = self.post_delete_request(userid=self.admin.id)
        self.assertIn("You cannot delete yourself", resp.data)

        User.get(id=self.admin.id)

    def test_admin_cannot_delete_nonexistant_user(self):
        self.login(ADMINNAME, ADMINPASS)
        resp = self.post_delete_request(userid=200)
        self.assertEqual(resp.status_code, 404)

    def test_normal_user_cannot_delete_nonexistant_user(self):
        self.login(USERNAME, USERPASS)
        resp = self.post_delete_request(userid=200)
        self.assertEqual(resp.status_code, 404)

    def when_user_deleted_posts_also_deleted(self):
        self.login(ADMINNAME, ADMINPASS)
        # TODO
        pass
開發者ID:Fivebread,項目名稱:streetsign,代碼行數:80,代碼來源:test_views_users_and_auth.py


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