From 66f78a6d8a1142403c1614f20a56e66ca16ca168 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Wed, 4 Nov 2020 15:02:28 +0100 Subject: [PATCH] display error messages for invalid nick changes --- index.cgi | 12 +++++++++--- usernick.sh | 8 +++----- webchat.css | 7 +++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/index.cgi b/index.cgi index f44d288..a5665c1 100755 --- a/index.cgi +++ b/index.cgi @@ -32,13 +32,18 @@ yield_page(){ settings_menu(){ printf ' - [form #settings method="POST" action="?" + [form #settings method="POST" action="?settings" [hidden "session_key" "%s"] - [h1 Settings][a .settings href="?" Close]' + [h1 Settings][a .settings href="?" Close] + ' "$SESSION_KEY" + if [ "$ERROR" ]; then + printf '[p .error %s %s]' "${ERROR%% *}" "$(HTML "${ERROR#.* }")" + unset ERROR + fi printf ' [a .section href="#nick" Nickname] [div #nick [input name="nickname" value="%s"][submit "action" "nick" Set Cookie]] - ' "$SESSION_KEY" "$(HTML "${nickname#\?}")" + ' "$(HTML "${nickname#\?}")" printf ' [a .section href="#register" Register Nickname] [div #register @@ -75,6 +80,7 @@ case ${LOCATION} in if [ -d "$_DATA/@${LOCATION#~}" ]; then pubinfo="$_DATA/@${LOCATION#~}/pubinfo" else + # ToDo Edit / Display of public user information REDIRECT / fi ;; diff --git a/usernick.sh b/usernick.sh index 8d62390..3880fbe 100755 --- a/usernick.sh +++ b/usernick.sh @@ -4,7 +4,7 @@ UNAME_VALID=' # Remove trailing CR, which may have been added by browser s;\r$;;; # Collapse white spaces - s;[\r\t\n ]+; ;; + s;[\r\t\n ]+; ;g; # Remove starting and trailing white spaces s;^ ;;; s; $;;; # Usernames starting with & # ? @ + will be invalid @@ -47,8 +47,7 @@ case $(POST action) in SET_COOKIE +1209600 "nick=$(POST nickname |URL)" REDIRECT "$(URL "/$LOCATION")" else - # ToDo: Return Error Message - REDIRECT "$(URL "/$LOCATION")?settings#nick" + export ERROR=".nick This nickname has already been registered elsewhere" fi ;; register) @@ -62,8 +61,7 @@ case $(POST action) in SET_COOKIE +"$((86400 * 365))" "nick=$(URL "${regnick}")" REDIRECT "$(URL "/$LOCATION")" else - # ToDo: Return Error Message - REDIRECT "$(URL "/$LOCATION")?settings#register" + export ERROR=".register This nickname has already been registered elsewhere" fi ;; esac diff --git a/webchat.css b/webchat.css index ff70761..4309596 100644 --- a/webchat.css +++ b/webchat.css @@ -59,6 +59,11 @@ button { content: "x"; padding: 0 1ex; } +#settings .error { + padding: 1ex 1ex .5ex 1ex; + background-color: #FCC; + font-weight: bold; +} #settings a.section { display: block; font-weight: bold; @@ -74,6 +79,8 @@ button { overflow: hidden; transition: max-height .5s; } +#settings .error.nick ~ a.section + #nick, +#settings .error.register ~ a.section + #register, #settings a.section + *:target { max-height: 20ex; padding: 1ex 1ex .5ex 1ex; -- 2.39.2