本文整理汇总了Python中tojauth.TOJAuth类的典型用法代码示例。如果您正苦于以下问题:Python TOJAuth类的具体用法?Python TOJAuth怎么用?Python TOJAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TOJAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user_info_by_uid
def get_user_info_by_uid(self, uid):
cur = self.db.cursor()
sqlstr = ('SELECT "uid", "username", "nickname", "email", "avatar", '
'"aboutme", "cover" FROM "USER" WHERE "uid" = %s;')
sqlarr = (uid, )
cur.execute(sqlstr, sqlarr)
ret = None
for data in cur:
ret = {}
ret['uid'] = data[0]
ret['username'] = data[1]
ret['nickname'] = data[2]
ret['email'] = data[3]
ret['avatar'] = data[4]
ret['aboutme'] = data[5]
ret['cover'] = data[6]
uid = self.get_current_uid()
if uid != ret['uid']:
try:
TOJAuth.check_access_func(
self._accessid, TOJAuth.ACCESS_EXECUTE)
except Exception:
del ret['email']
return ret
示例2: get_notice
def get_notice(self, noticeid):
cur = self.db.cursor()
sqlstr = ('SELECT "noticeid", "uid", "title", "content", "time", '
'"noticemodid", "metadata", "unread" FROM "NOTICE" WHERE '
'"noticeid" = %s;')
sqlarr = (noticeid, )
cur.execute(sqlstr, sqlarr)
ret = None
for data in cur:
ret = {}
ret['noticeid'] = data[0]
ret['uid'] = data[1]
ret['title'] = data[2]
ret['content'] = data[3]
ret['time'] = data[4]
ret['noticemodid'] = data[5]
ret['metadata'] = data[6]
ret['unread'] = data[7]
if ret == None:
return None
uid = mod.UserMg.get_current_uid()
if uid != ret['uid']:
TOJAuth.check_access_func(self._accessid, TOJAuth.ACCESS_EXECUTE)
return ret
示例3: join_square
def join_square(self, sqid):
if(
type(sqid) != int
):
return 'Eparameter'
uid = mod.UserMg.get_current_uid()
if uid == None:
return 'Euid'
sq = self.get_square_info_by_sqid(sqid)
if sq == None:
return 'Eno_such_sqid'
with TOJAuth.change_current_iden(self._idendesc):
sqobj = self.load_square(sqid)
result = sqobj.join_square(uid)
if result == self.JOIN_REJECT:
return 'Ereject'
elif result == self.JOIN_PENDING:
with TOJAuth.change_current_iden(self._idendesc):
self._set_user_square_relation(uid, sqid, False)
return {'active': False}
elif result == self.JOIN_ACCEPT:
with TOJAuth.change_current_iden(self._idendesc):
self._set_user_square_relation(uid, sqid, True)
return {'active': True}
else:
return 'Ejoin_sq_error'
示例4: _create_square
def _create_square(self, title, sqmodid, intro, logo):
cur = self.db.cursor()
sqlstr = ('INSERT INTO "SQUARE" ("title", "hidden", "sqmodid", '
'"intro", "logo", "accessid") VALUES (%s, %s, %s, %s, '
'%s, %s) RETURNING "sqid";')
sqlarr = (title, False, sqmodid, intro, logo, 0)
cur.execute(sqlstr, sqlarr)
sqid = None
for data in cur:
sqid = data[0]
if sqid == None:
return None
user_idenid = TOJAuth.get_current_iden()['idenid']
with TOJAuth.change_current_iden(self._idendesc):
accessid = TOJAuth.instance.create_access(user_idenid)
sqlstr = ('UPDATE "SQUARE" SET "accessid" = %s WHERE "sqid" = %s;')
sqlarr = (accessid, sqid)
cur.execute(sqlstr, sqlarr)
TOJAuth.instance.set_access_list(
accessid, TOJAuth.ROLEID_SQUARE_ADMIN_GROUP,
TOJAuth.ACCESS_ALL
)
sqmodname = self.get_sqmodname_by_sqmodid(sqmodid)
sqmod = mod.load_sqmod(sqmodname)
sqmod.create_square_data(sqid)
return sqid;
示例5: _create_problem
def _create_problem(self, title, pmodid):
cur = self.db.cursor()
sqlstr = ('INSERT INTO "PROBLEM" ("title", "pmodid", "accessid") '
'VALUES (%s, %s, %s) RETURNING "proid";')
sqlarr = (title, pmodid, 0)
cur.execute(sqlstr, sqlarr)
proid = None
for data in cur:
proid = data[0]
if proid == None:
return None
user_idenid = TOJAuth.get_current_iden()['idenid']
with TOJAuth.change_current_iden(self._idendesc):
accessid = TOJAuth.instance.create_access(user_idenid)
sqlstr = ('UPDATE "PROBLEM" SET "accessid" = %s WHERE "proid" = %s;')
sqlarr = (accessid, proid)
cur.execute(sqlstr, sqlarr)
TOJAuth.instance.set_access_list(
accessid, TOJAuth.ROLEID_PROBLEM_ADMIN_GROUP,
TOJAuth.ACCESS_ALL
)
pmodname = self.get_pmodname_by_pmodid(pmodid)
pmod = mod.load_pmod(pmodname)
pmod.create_problem_data(proid)
return proid
示例6: _del_mode
def _del_mode(self, modeid):
TOJAuth.check_access_func(self._accessid, TOJAuth.ACCESS_WRITE)
cur = self.db.cursor()
sqlstr = ('DELETE FROM "PMOD_TEST_MODE" WHERE "proid" = %s AND '
'"modeid" = %s;')
sqlarr = (self._proid, modeid)
cur.execute(sqlstr, sqlarr)
示例7: _add_testmode
def _add_testmode(self, testmodename, timelimit, memlimit):
TOJAuth.check_access_func(self._accessid, TOJAuth.ACCESS_WRITE)
cur = self.db.cursor()
sqlstr = ('INSERT INTO "PMOD_TEST_TESTMODE" ("proid", "testmodename", '
'"timelimit", "memlimit") VALUES (%s, %s, %s, %s);')
sqlarr = (self._proid, testmodename, timelimit, memlimit)
cur.execute(sqlstr, sqlarr)
示例8: _set_mode
def _set_mode(self, modeid, content, testmodeid):
TOJAuth.check_access_func(self._accessid, TOJAuth.ACCESS_WRITE)
cur = self.db.cursor()
sqlstr = ('UPDATE "PMOD_TEST_MODE" SET "content" = %s, '
'"testmodeid" = %s WHERE "proid" = %s AND "modeid" = %s;')
sqlarr = (content, testmodeid, self._proid, modeid)
cur.execute(sqlstr, sqlarr)
示例9: set_problem
def set_problem(self, proid, title):
accessid = self.get_accessid_by_proid(proid)
TOJAuth.check_access_func(accessid, TOJAuth.ACCESS_WRITE)
cur = self.db.cursor()
sqlstr = ('UPDATE "PROBLEM" SET "title" = %s WHERE "proid" = %s;')
sqlarr = (title, proid)
cur.execute(sqlstr, sqlarr)
示例10: _set_testmode
def _set_testmode(self, testmodeid, testmodename, timelimit, memlimit):
TOJAuth.check_access_func(self._accessid, TOJAuth.ACCESS_WRITE)
cur = self.db.cursor()
sqlstr = ('UPDATE "PMOD_TEST_TESTMODE" SET "testmodename" = %s, '
'"timelimit" = %s, "memlimit" = %s WHERE "proid" = %s AND '
'"testmodeid" = %s;')
sqlarr = (testmodename, timelimit, memlimit, self._proid, testmodeid)
cur.execute(sqlstr, sqlarr)
示例11: set_square
def set_square(self, sqid, title, start_time, end_time, intro, logo):
accessid = self.get_accessid_by_sqid(sqid)
TOJAuth.check_access_func(accessid, TOJAuth.ACCESS_WRITE)
cur = self.db.cursor()
sqlstr = ('UPDATE "SQUARE" SET "title" = %s, "start_time" = %s, '
'"end_time" = %s, "intro" = %s, "logo" = %s '
'WHERE "sqid" = %s;')
sqlarr = (title, start_time, end_time, intro, logo, sqid)
cur.execute(sqlstr, sqlarr)
示例12: _set_square_category
def _set_square_category(self, sqid, category):
sq_accessid = self.get_accessid_by_sqid(sqid)
TOJAuth.check_access_func(sq_accessid, TOJAuth.ACCESS_WRITE)
if category == []:
category = [0]
cur = self.db.cursor()
sqlstr = ('UPDATE "SQUARE" SET "cateid" = %s WHERE "sqid" = %s;')
sqlarr = (category, sqid)
cur.execute(sqlstr, sqlarr)
示例13: _list_testdata
def _list_testdata(self):
TOJAuth.check_access_func(self._accessid, TOJAuth.ACCESS_WRITE)
with TOJAuth.change_current_iden(self._idendesc):
testdata_list = mod.TestdataMg.instance._list_testdata(self._proid)
for test in testdata_list:
del test['blobname']
del test['proid']
return testdata_list
示例14: _create_testdata
def _create_testdata(self, info, filekey, expire):
TOJAuth.check_access_func(self._accessid, TOJAuth.ACCESS_WRITE)
# Upload file
blobname = 'TEST_BLOBNAME'
with TOJAuth.change_current_iden(self._idendesc):
testid = mod.TestdataMg.instance._add_testdata(
blobname, expire, self._proid, info)
return testid
示例15: set_user_info
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'