2021-02-25 10:37:20 +00:00
|
|
|
__filename__ = "webapp_welcome_profile.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "1.2.0"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
2021-09-10 16:14:50 +00:00
|
|
|
__email__ = "bob@libreserver.org"
|
2021-02-25 10:37:20 +00:00
|
|
|
__status__ = "Production"
|
2021-06-26 11:27:14 +00:00
|
|
|
__module_group__ = "Onboarding"
|
2021-02-25 10:37:20 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
from shutil import copyfile
|
2021-02-25 19:15:04 +00:00
|
|
|
from utils import removeHtml
|
2021-02-25 12:17:41 +00:00
|
|
|
from utils import loadJson
|
2021-02-25 10:37:20 +00:00
|
|
|
from utils import getConfigParam
|
|
|
|
from utils import getImageExtensions
|
2021-02-25 12:17:41 +00:00
|
|
|
from utils import getImageFormats
|
2021-07-13 21:59:53 +00:00
|
|
|
from utils import acctDir
|
2021-08-14 11:13:39 +00:00
|
|
|
from utils import localActorUrl
|
2021-02-25 10:37:20 +00:00
|
|
|
from webapp_utils import htmlHeaderWithExternalStyle
|
|
|
|
from webapp_utils import htmlFooter
|
2021-07-22 16:58:59 +00:00
|
|
|
from webapp_utils import editTextField
|
2021-06-25 14:38:31 +00:00
|
|
|
from markdown import markdownToHtml
|
2021-02-25 10:37:20 +00:00
|
|
|
|
|
|
|
|
2021-12-25 16:17:53 +00:00
|
|
|
def htmlWelcomeProfile(base_dir: str, nickname: str, domain: str,
|
2021-12-25 17:09:22 +00:00
|
|
|
http_prefix: str, domainFull: str,
|
2021-02-27 10:27:39 +00:00
|
|
|
language: str, translate: {},
|
|
|
|
themeName: str) -> str:
|
2021-02-25 10:37:20 +00:00
|
|
|
"""Returns the welcome profile screen to set avatar and bio
|
|
|
|
"""
|
|
|
|
# set a custom background for the welcome screen
|
2021-12-25 16:17:53 +00:00
|
|
|
if os.path.isfile(base_dir + '/accounts/welcome-background-custom.jpg'):
|
|
|
|
if not os.path.isfile(base_dir + '/accounts/welcome-background.jpg'):
|
|
|
|
copyfile(base_dir + '/accounts/welcome-background-custom.jpg',
|
|
|
|
base_dir + '/accounts/welcome-background.jpg')
|
2021-02-25 10:37:20 +00:00
|
|
|
|
|
|
|
profileText = 'Welcome to Epicyon'
|
2021-12-25 16:17:53 +00:00
|
|
|
profileFilename = base_dir + '/accounts/welcome_profile.md'
|
2021-02-25 10:37:20 +00:00
|
|
|
if not os.path.isfile(profileFilename):
|
2021-02-27 10:27:39 +00:00
|
|
|
defaultFilename = None
|
|
|
|
if themeName:
|
|
|
|
defaultFilename = \
|
2021-12-25 16:17:53 +00:00
|
|
|
base_dir + '/theme/' + themeName + '/welcome/' + \
|
2021-02-27 10:27:39 +00:00
|
|
|
'profile_' + language + '.md'
|
|
|
|
if not os.path.isfile(defaultFilename):
|
|
|
|
defaultFilename = None
|
|
|
|
if not defaultFilename:
|
|
|
|
defaultFilename = \
|
2021-12-25 16:17:53 +00:00
|
|
|
base_dir + '/defaultwelcome/profile_' + language + '.md'
|
2021-02-25 10:37:20 +00:00
|
|
|
if not os.path.isfile(defaultFilename):
|
2021-12-25 16:17:53 +00:00
|
|
|
defaultFilename = base_dir + '/defaultwelcome/profile_en.md'
|
2021-02-25 10:37:20 +00:00
|
|
|
copyfile(defaultFilename, profileFilename)
|
2021-02-25 22:25:01 +00:00
|
|
|
|
|
|
|
instanceTitle = \
|
2021-12-25 16:17:53 +00:00
|
|
|
getConfigParam(base_dir, 'instanceTitle')
|
2021-02-25 22:25:01 +00:00
|
|
|
if not instanceTitle:
|
|
|
|
instanceTitle = 'Epicyon'
|
|
|
|
|
2021-02-25 10:37:20 +00:00
|
|
|
if os.path.isfile(profileFilename):
|
|
|
|
with open(profileFilename, 'r') as profileFile:
|
2021-02-25 22:25:01 +00:00
|
|
|
profileText = profileFile.read()
|
|
|
|
profileText = profileText.replace('INSTANCE', instanceTitle)
|
|
|
|
profileText = markdownToHtml(removeHtml(profileText))
|
2021-02-25 10:37:20 +00:00
|
|
|
|
|
|
|
profileForm = ''
|
2021-12-25 16:17:53 +00:00
|
|
|
cssFilename = base_dir + '/epicyon-welcome.css'
|
|
|
|
if os.path.isfile(base_dir + '/welcome.css'):
|
|
|
|
cssFilename = base_dir + '/welcome.css'
|
2021-02-25 10:37:20 +00:00
|
|
|
|
2021-11-07 10:38:11 +00:00
|
|
|
profileForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None)
|
2021-02-25 10:37:20 +00:00
|
|
|
|
|
|
|
# get the url of the avatar
|
|
|
|
for ext in getImageExtensions():
|
|
|
|
avatarFilename = \
|
2021-12-25 16:17:53 +00:00
|
|
|
acctDir(base_dir, nickname, domain) + '/avatar.' + ext
|
2021-02-25 10:37:20 +00:00
|
|
|
if os.path.isfile(avatarFilename):
|
|
|
|
break
|
|
|
|
avatarUrl = \
|
2021-12-25 17:09:22 +00:00
|
|
|
localActorUrl(http_prefix, nickname, domainFull) + '/avatar.' + ext
|
2021-02-25 10:37:20 +00:00
|
|
|
|
2021-02-25 12:17:41 +00:00
|
|
|
imageFormats = getImageFormats()
|
2021-02-25 13:26:09 +00:00
|
|
|
profileForm += '<div class="container">' + profileText + '</div>\n'
|
2021-02-25 12:17:41 +00:00
|
|
|
profileForm += \
|
|
|
|
'<form enctype="multipart/form-data" method="POST" ' + \
|
|
|
|
'accept-charset="UTF-8" ' + \
|
2021-02-25 14:53:19 +00:00
|
|
|
'action="/users/' + nickname + '/profiledata">\n'
|
2021-02-25 12:36:06 +00:00
|
|
|
profileForm += '<div class="container">\n'
|
|
|
|
profileForm += ' <center>\n'
|
|
|
|
profileForm += ' <img class="welcomeavatar" src="'
|
2021-02-25 12:17:41 +00:00
|
|
|
profileForm += avatarUrl + '"><br>\n'
|
2021-02-25 12:36:06 +00:00
|
|
|
profileForm += ' <input type="file" id="avatar" name="avatar" '
|
2021-02-25 12:17:41 +00:00
|
|
|
profileForm += 'accept="' + imageFormats + '">\n'
|
2021-02-25 12:36:06 +00:00
|
|
|
profileForm += ' </center>\n'
|
|
|
|
profileForm += '</div>\n'
|
2021-02-25 12:17:41 +00:00
|
|
|
|
2021-02-25 13:26:09 +00:00
|
|
|
profileForm += '<center>\n'
|
|
|
|
profileForm += \
|
|
|
|
' <button type="submit" class="button" ' + \
|
|
|
|
'name="previewAvatar">' + translate['Preview'] + '</button> '
|
|
|
|
profileForm += '</center>\n'
|
|
|
|
|
2021-12-25 16:17:53 +00:00
|
|
|
actorFilename = acctDir(base_dir, nickname, domain) + '.json'
|
2021-02-25 12:17:41 +00:00
|
|
|
actorJson = loadJson(actorFilename)
|
|
|
|
displayNickname = actorJson['name']
|
2021-02-25 12:36:06 +00:00
|
|
|
profileForm += '<div class="container">\n'
|
2021-07-22 16:58:59 +00:00
|
|
|
profileForm += \
|
|
|
|
editTextField(translate['Nickname'], 'displayNickname',
|
|
|
|
displayNickname)
|
2021-02-25 12:17:41 +00:00
|
|
|
|
|
|
|
bioStr = \
|
|
|
|
actorJson['summary'].replace('<p>', '').replace('</p>', '')
|
2021-04-21 20:01:09 +00:00
|
|
|
if not bioStr:
|
|
|
|
bioStr = translate['Your bio']
|
2021-02-25 12:17:41 +00:00
|
|
|
profileForm += ' <label class="labels">' + \
|
2021-02-25 12:24:26 +00:00
|
|
|
translate['Your bio'] + '</label><br>\n'
|
2021-02-25 12:17:41 +00:00
|
|
|
profileForm += ' <textarea id="message" name="bio" ' + \
|
2021-02-28 14:26:04 +00:00
|
|
|
'style="height:130px" spellcheck="true">' + \
|
|
|
|
bioStr + '</textarea>\n'
|
2021-02-25 12:36:06 +00:00
|
|
|
profileForm += '</div>\n'
|
2021-02-25 12:17:41 +00:00
|
|
|
|
2021-02-25 12:36:06 +00:00
|
|
|
profileForm += '<div class="container next">\n'
|
2021-02-25 12:24:26 +00:00
|
|
|
profileForm += \
|
|
|
|
' <button type="submit" class="button" ' + \
|
2021-02-25 16:55:40 +00:00
|
|
|
'name="initialWelcomeScreen">' + translate['Go Back'] + '</button> '
|
2021-02-25 12:24:26 +00:00
|
|
|
profileForm += \
|
|
|
|
' <button type="submit" class="button" ' + \
|
2021-02-25 16:55:40 +00:00
|
|
|
'name="finalWelcomeScreen">' + translate['Next'] + '</button>\n'
|
2021-02-25 12:36:06 +00:00
|
|
|
profileForm += '</div>\n'
|
2021-02-25 12:24:26 +00:00
|
|
|
|
2021-02-25 12:17:41 +00:00
|
|
|
profileForm += '</form>\n'
|
2021-02-25 10:37:20 +00:00
|
|
|
profileForm += htmlFooter()
|
|
|
|
return profileForm
|