def parseLink(str): ret = '' reResult = re.split( '(\[[^\[\]\s\|]+[^\[\]\s\|]+\])|(\[[^\[\]\|]+\|[^\[\]\|]+\])|(\[[^\[\]\s\|]+\s[^\[\]\s\|]+\])', str) for result in reResult: if (result is None) | (result == ''): continue if len(result) > 4: if (result[0] == '[') & (result[-1] == ']'): _result = toUtf8Str(result)[1:-1].split('|') if len(_result) == 2: ret += '<a href="/page/%s">%s</a>' % (_result[1], _result[0]) continue if len(result) > 2: if (result[0] == '[') & (result[-1] == ']'): _result = toUtf8Str(result)[1:-1].split(' ') if len(_result) == 1: ret += '<a href="/page/%s">%s</a>' % (_result[0], _result[0]) continue elif len(_result) == 2: ret += '<a href="%s">%s</a>' % (_result[1], _result[0]) continue ret += result return ret
def __character(self, attrs): if (len(attrs) > 1): return self._render.character({ 'HOST': WEB_CONF['host'], 'CARD_ID': quote(toUtf8Str(attrs[1])) }) return self.__404(attrs)
def __editpage(self, attrs): if (len(attrs) > 1): return self._render.editpage({ 'HOST': WEB_CONF['host'], 'PAGE': quote(toUtf8Str(attrs[1])) }) return self.__404(attrs)
def __page(self, attrs): if (len(attrs) > 1): if os.path.exists(r'%s/page/%s.html' % (ABS_PATH, attrs[1])): return web.template.frender('page/%s.html' % attrs[1])({ 'HOST': WEB_CONF['host'], 'PAGE': quote(toUtf8Str(attrs[1])) }) else: return self._render.addpage({ 'HOST': WEB_CONF['host'], 'PAGE': 'NONE', 'NAME': quote(toUtf8Str(attrs[1])) }) return self.__404(attrs)
def parseNoWiki(str): ret = '' reResult = re.split('(<nowiki>[\s\S]+</nowiki>)', str) for result in reResult: if (result is None) | (result == ''): continue if len(result) > 17: if (result.find('<nowiki>') != -1) & (result.find('</nowiki>') != -1): ret += quote(toUtf8Str(result)[8:-9]) continue ret += result return ret
def __addpage(self, attrs): if (len(attrs) > 1): return self._render.addpage({ 'HOST': WEB_CONF['host'], 'PAGE': quote(toUtf8Str(attrs[1])), 'NAME': 'NONE' }) else: return self._render.addpage({ 'HOST': WEB_CONF['host'], 'PAGE': 'NEW', 'NAME': 'NONE' })
def login(username, pwdhash, keeplogin=1): item = queryAndFetchOne( Login.CONN_NAME, "SELECT * FROM %s WHERE `username` = '%s'" % (Login.TABLE_NAME, username)) if item is None: return {'status': Login.CONSTANT_LOGIN_WRONG} from common.aes import AESCipher cipher = AESCipher() password = toUtf8Str(cipher.decrypt(item['password'])) pwdhash = toUtf8Str(pwdhash) hash = bcrypt.hashpw(password, pwdhash) if hash == pwdhash: now = ceil(time.time()) Sessions.setUserName(username) Sessions.setUserStatus(Login.CONSTANT_LOGIN_AUTHENTICATED) Sessions.setUserLastLogin(now) Login.updateLastLogin(username, Sessions.getUserLastLogin()) return { 'status': Login.CONSTANT_LOGIN_AUTHENTICATED, 'username': username, 'lastlogin': now } else: return {'status': Login.CONSTANT_LOGIN_WRONG}
def __characters(self, attrs): return self._render.characters({ 'HOST': WEB_CONF['host'], 'CHARACTERSPAGE': (len(attrs) > 1) and (toUtf8Str(attrs[1])) or '1' })
def __rules(self, attrs): return self._render.rules({ 'HOST': WEB_CONF['host'], 'RULEPAGE': (len(attrs) > 1) and (toUtf8Str(attrs[1])) or 'intro' })