Displaying welcome screen

merge-requests/21/head
Bob Mottram 2021-02-24 21:17:08 +00:00
parent 93f7aa7889
commit b8ac29a515
4 changed files with 51 additions and 8 deletions

View File

@ -181,6 +181,8 @@ from webapp_search import htmlSearchEmojiTextEntry
from webapp_search import htmlSearch
from webapp_hashtagswarm import getHashtagCategoriesFeed
from webapp_hashtagswarm import htmlSearchHashtagCategory
from webapp_welcome import htmlWelcomeScreen
from webapp_welcome import isWelcomeScreenComplete
from shares import getSharesFeedForPerson
from shares import addShare
from shares import removeShare
@ -10670,6 +10672,29 @@ class PubServer(BaseHTTPRequestHandler):
'show about screen done',
'robots txt')
if htmlGET and authorized and \
'/users/' in self.path and self.path.endswith('/welcome'):
nickname = self.path.split('/users/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
if not isWelcomeScreenComplete(self.server.baseDir,
nickname,
self.server.domain):
msg = \
htmlWelcomeScreen(self.server.baseDir,
self.server.systemLanguage,
self.server.translate)
msg = msg.encode('utf-8')
msglen = len(msg)
self._login_headers('text/html', msglen, callingDomain)
self._write(msg)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'following accounts done',
'show welcome screen')
return
else:
self.path = self.path.replace('/welcome', '')
# if not authorized then show the login screen
if htmlGET and self.path != '/login' and \
not self._pathIsImage(self.path) and \

View File

@ -3290,7 +3290,7 @@ def testMarkdownToHtml():
markdown = '# Title1\n### Title3\n## Title2\n'
assert markdownToHtml(markdown) == \
'<h1>Title1</h1><br><h3>Title3</h3><br><h2>Title2</h2><br>'
'<h1>Title1</h1><h3>Title3</h3><h2>Title2</h2>'
markdown = \
'This is [a link](https://something.somewhere) to something\n' + \

View File

@ -56,18 +56,23 @@ def markdownToHtml(markdown: str) -> str:
if line.startswith('#####'):
line = line.replace('#####', '').strip()
line = '<h5>' + line + '</h5>'
ctr = -1
elif line.startswith('####'):
line = line.replace('####', '').strip()
line = '<h4>' + line + '</h4>'
ctr = -1
elif line.startswith('###'):
line = line.replace('###', '').strip()
line = '<h3>' + line + '</h3>'
ctr = -1
elif line.startswith('##'):
line = line.replace('##', '').strip()
line = '<h2>' + line + '</h2>'
ctr = -1
elif line.startswith('#'):
line = line.replace('#', '').strip()
line = '<h1>' + line + '</h1>'
ctr = -1
htmlStr += line
ctr += 1
return htmlStr

View File

@ -14,17 +14,30 @@ from webapp_utils import htmlFooter
from webapp_utils import markdownToHtml
def welcomeScreenShown(baseDir: str, nickname: str, domain: str):
def isWelcomeScreenComplete(baseDir: str, nickname: str, domain: str) -> bool:
"""Returns true if the welcome screen is complete for the given account
"""
accountPath = baseDir + '/accounts/' + nickname + '@' + domain
if not os.path.isdir(accountPath):
return
completeFilename = accountPath + '/.welcome_complete'
return os.path.isfile(completeFilename)
def welcomeScreenIsComplete(baseDir: str, nickname: str, domain: str) -> None:
"""Indicates that the welcome screen has been shown for a given account
"""
shownFilename = baseDir + '/accounts/.welcome_shown'
shownFile = open(shownFilename, 'w+')
if shownFile:
shownFile.write('\n')
shownFile.close()
accountPath = baseDir + '/accounts/' + nickname + '@' + domain
if not os.path.isdir(accountPath):
return
completeFilename = accountPath + '/.welcome_complete'
completeFile = open(completeFilename, 'w+')
if completeFile:
completeFile.write('\n')
completeFile.close()
def htmlWelcomeScreen(baseDir: str, nickname: str, domain: str,
def htmlWelcomeScreen(baseDir: str,
language: str, translate: {}) -> str:
"""Returns the welcome screen
"""