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


Python TOJAuth.check_access方法代碼示例

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


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

示例1: set_user_info

# 需要導入模塊: from tojauth import TOJAuth [as 別名]
# 或者: from tojauth.TOJAuth import check_access [as 別名]
    def set_user_info(self, uid, nickname, email, avatar, aboutme, cover):
        if(
            type(uid) != int or
            type(nickname) != str or
            type(email) != str or
            type(avatar) != str or
            type(aboutme) != str or
            type(cover) != str
        ):
            return 'Eparameter'

        if len(nickname) < self.NICKNAME_LEN_MIN:
            return 'Enickname_too_short'
        elif len(nickname) > self.NICKNAME_LEN_MAX:
            return 'Enickname_too_long'
        elif len(email) < self.EMAIL_LEN_MIN:
            return 'Eemail_too_short'
        elif len(email) > self.EMAIL_LEN_MAX:
            return 'Eemail_too_long'
        elif len(avatar) < self.AVATAR_LEN_MIN:
            return 'Eavatar_too_short'
        elif len(avatar) > self.AVATAR_LEN_MAX:
            return 'Eavatar_too_long'
        elif len(aboutme) < self.ABOUTME_LEN_MIN:
            return 'Eaboutme_too_short'
        elif len(aboutme) > self.ABOUTME_LEN_MAX:
            return 'Eaboutme_too_long'
        elif len(cover) < self.COVER_LEN_MIN:
            return 'Ecover_too_short'
        elif len(cover) > self.COVER_LEN_MAX:
            return 'Ecover_too_long'

        idenid = self.get_idenid_by_uid(uid)
        if idenid == None:
            return 'Eno_such_uid'

        if idenid != TOJAuth.get_current_iden()['idenid']:
            TOJAuth.check_access(
                self._accessid, TOJAuth.ACCESS_EXECUTE)(lambda x:x)(0)

        cur = self.db.cursor()
        sqlstr = ('UPDATE "USER" SET "nickname" = %s, "email" = %s, '
                  '"avatar" = %s, "aboutme" = %s, "cover" = %s WHERE '
                  '"uid" = %s;')
        sqlarr = (nickname, email, avatar, aboutme, cover, uid)
        cur.execute(sqlstr, sqlarr)

        return 'Success'
開發者ID:taiwan-online-judge,項目名稱:taiwan-online-judge,代碼行數:50,代碼來源:user.py

示例2: change_user_password

# 需要導入模塊: from tojauth import TOJAuth [as 別名]
# 或者: from tojauth.TOJAuth import check_access [as 別名]
    def change_user_password(self, uid, old_password, new_password):
        if(
            type(uid) != int or
            type(old_password) != str or
            type(new_password) != str
        ):
            return 'Eparameter'

        if len(new_password) < self.PASSWORD_LEN_MIN:
            return 'Epassword_too_short'
        elif len(new_password) > self.PASSWORD_LEN_MAX:
            return 'Epassword_too_long'
        
        idenid = self.get_idenid_by_uid(uid)
        if idenid == None:
            return 'Eno_such_uid'

        if idenid != TOJAuth.get_current_iden()['idenid']:
            TOJAuth.check_access(
                self._accessid, TOJAuth.ACCESS_EXECUTE)(lambda x:x)(0)

        old_passhash = self._password_hash(old_password)

        cur = self.db.cursor()
        sqlstr = ('SELECT "idenid" FROM "USER" WHERE "uid" = %s '
                  'AND "passhash" = %s;')
        sqlarr = (uid, old_passhash)
        cur.execute(sqlstr, sqlarr)

        idenid = None
        for data in cur:
            idenid = data[0]

        if idenid == None:
            return 'Ewrong_old_password'

        new_passhash = self._password_hash(new_password)

        sqlstr = ('UPDATE "USER" SET "passhash" = %s WHERE "uid" = %s;')
        sqlarr = (new_passhash, uid)
        cur.execute(sqlstr, sqlarr)

        return 'Success'
開發者ID:taiwan-online-judge,項目名稱:taiwan-online-judge,代碼行數:45,代碼來源:user.py

示例3: del_mail

# 需要導入模塊: from tojauth import TOJAuth [as 別名]
# 或者: from tojauth.TOJAuth import check_access [as 別名]
    def del_mail(self, mailid):
        if(
            type(mailid) != int
        ):
            return 'Eparameter'

        uid = mod.UserMg.get_current_uid()
        if uid == None:
            return 'Eno_uid'

        with TOJAuth.change_current_iden(self._idendesc):
            mail = self._get_mail(mailid)

        if mail == None:
            return 'Eno_such_mailid'
        if mail['to_uid'] != uid:
            TOJAuth.check_access(
                self._accessid, TOJAuth.ACCESS_EXECUTE)(lambda x:x)(0)
        
        with TOJAuth.change_current_iden(self._idendesc):
            self._del_mail(mailid)

        return 'Success'
開發者ID:taiwan-online-judge,項目名稱:taiwan-online-judge,代碼行數:25,代碼來源:mail.py


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