From: Paul Hänsch Date: Wed, 4 Nov 2020 14:02:28 +0000 (+0100) Subject: display error messages for invalid nick changes X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=66f78a6d8a1142403c1614f20a56e66ca16ca168;p=httpchat display error messages for invalid nick changes --- 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;