2021-02-24 18:44:26 +00:00
|
|
|
__filename__ = "webapp_welcome.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "1.2.0"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
|
|
|
import os
|
|
|
|
from shutil import copyfile
|
|
|
|
from utils import getConfigParam
|
2021-02-25 19:15:04 +00:00
|
|
|
from utils import removeHtml
|
2021-02-24 18:44:26 +00:00
|
|
|
from webapp_utils import htmlHeaderWithExternalStyle
|
|
|
|
from webapp_utils import htmlFooter
|
2021-02-24 19:04:51 +00:00
|
|
|
from webapp_utils import markdownToHtml
|
2021-02-24 18:44:26 +00:00
|
|
|
|
|
|
|
|
2021-02-24 21:17:08 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2021-02-25 16:55:40 +00:00
|
|
|
def welcomeScreenIsComplete(baseDir: str,
|
|
|
|
nickname: str, domain: str) -> None:
|
|
|
|
"""Indicates that the welcome screen has been shown for a given account
|
|
|
|
"""
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
2021-02-25 17:06:07 +00:00
|
|
|
def htmlWelcomeScreen(baseDir: str, nickname: str,
|
2021-02-25 10:37:20 +00:00
|
|
|
language: str, translate: {},
|
2021-02-25 17:06:07 +00:00
|
|
|
currScreen='welcome') -> str:
|
2021-02-24 18:44:26 +00:00
|
|
|
"""Returns the welcome screen
|
|
|
|
"""
|
|
|
|
# set a custom background for the welcome screen
|
|
|
|
if os.path.isfile(baseDir + '/accounts/welcome-background-custom.jpg'):
|
|
|
|
if not os.path.isfile(baseDir + '/accounts/welcome-background.jpg'):
|
|
|
|
copyfile(baseDir + '/accounts/welcome-background-custom.jpg',
|
|
|
|
baseDir + '/accounts/welcome-background.jpg')
|
|
|
|
|
|
|
|
welcomeText = 'Welcome to Epicyon'
|
2021-02-25 10:37:20 +00:00
|
|
|
welcomeFilename = baseDir + '/accounts/' + currScreen + '.md'
|
2021-02-24 18:44:26 +00:00
|
|
|
if not os.path.isfile(welcomeFilename):
|
2021-02-25 10:37:20 +00:00
|
|
|
defaultFilename = \
|
|
|
|
baseDir + '/defaultwelcome/' + currScreen + '_' + language + '.md'
|
2021-02-24 21:22:32 +00:00
|
|
|
if not os.path.isfile(defaultFilename):
|
2021-02-25 10:37:20 +00:00
|
|
|
defaultFilename = \
|
|
|
|
baseDir + '/defaultwelcome/' + currScreen + '_en.md'
|
2021-02-24 21:22:32 +00:00
|
|
|
copyfile(defaultFilename, welcomeFilename)
|
2021-02-25 22:25:01 +00:00
|
|
|
|
|
|
|
instanceTitle = \
|
|
|
|
getConfigParam(baseDir, 'instanceTitle')
|
|
|
|
if not instanceTitle:
|
|
|
|
instanceTitle = 'Epicyon'
|
|
|
|
|
2021-02-24 18:44:26 +00:00
|
|
|
if os.path.isfile(welcomeFilename):
|
2021-02-25 10:37:20 +00:00
|
|
|
with open(welcomeFilename, 'r') as welcomeFile:
|
2021-02-25 22:25:01 +00:00
|
|
|
welcomeText = welcomeFile.read()
|
|
|
|
welcomeText = welcomeText.replace('INSTANCE', instanceTitle)
|
|
|
|
welcomeText = markdownToHtml(removeHtml(welcomeText))
|
2021-02-24 18:44:26 +00:00
|
|
|
|
|
|
|
welcomeForm = ''
|
|
|
|
cssFilename = baseDir + '/epicyon-welcome.css'
|
|
|
|
if os.path.isfile(baseDir + '/welcome.css'):
|
|
|
|
cssFilename = baseDir + '/welcome.css'
|
|
|
|
|
|
|
|
welcomeForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle)
|
2021-02-25 17:06:07 +00:00
|
|
|
welcomeForm += \
|
|
|
|
'<form enctype="multipart/form-data" method="POST" ' + \
|
|
|
|
'accept-charset="UTF-8" ' + \
|
|
|
|
'action="/users/' + nickname + '/profiledata">\n'
|
2021-02-24 18:44:26 +00:00
|
|
|
welcomeForm += '<div class="container">' + welcomeText + '</div>\n'
|
|
|
|
welcomeForm += ' <div class="container next">\n'
|
2021-02-25 17:06:07 +00:00
|
|
|
welcomeForm += \
|
|
|
|
' <button type="submit" class="button" ' + \
|
|
|
|
'name="previewAvatar">' + translate['Next'] + '</button>\n'
|
2021-02-24 18:44:26 +00:00
|
|
|
welcomeForm += ' </div>\n'
|
|
|
|
welcomeForm += '</div>\n'
|
2021-02-25 17:06:07 +00:00
|
|
|
welcomeForm += '</form>\n'
|
2021-02-24 18:44:26 +00:00
|
|
|
welcomeForm += htmlFooter()
|
|
|
|
return welcomeForm
|