X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=usernick.sh;h=13759eee48fb57169a599e8b2a1bc2ed339cac81;hb=fbeb46144ca938828cd1df9710cb5893483ec1f5;hp=8d62390b2d1872b91d8aa215b3c45c30defd39f1;hpb=a69240820e57ec23017a672d513a22802fb3edc6;p=httpchat diff --git a/usernick.sh b/usernick.sh index 8d62390..13759ee 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 @@ -36,6 +36,8 @@ else SET_COOKIE +"$((86400 * 365))" "user_client=${clientid}" HttpOnly SET_COOKIE +"$((86400 * 365))" "nick=$(URL "${nickname}")" else + export ERROR=".nick Your current nickname has been registered elsewhere." + QUERY_STRING=settings nickname='?Guest' fi fi @@ -43,18 +45,30 @@ fi case $(POST action) in nick) nick="$(POST nickname |username)" - if [ ! -d "$_DATA/@$nick" ]; then - SET_COOKIE +1209600 "nick=$(POST nickname |URL)" + if [ -d "$_DATA/@$nick" ]; then + export ERROR=".nick This nickname has already been registered elsewhere." + elif [ -z "$(POST nickname)" ]; then + SET_COOKIE +1209600 "nick=$(URL "${nickname#\?}")" REDIRECT "$(URL "/$LOCATION")" + elif [ -z "$nick" ]; then + export ERROR='.nick Nicknames must be between 3 and 24 characters long. They may not start with "&", "#", "?", "@", or "+" and they must not contain a "/".' else - # ToDo: Return Error Message - REDIRECT "$(URL "/$LOCATION")?settings#nick" + SET_COOKIE +1209600 "nick=$(URL $nick)" + REDIRECT "$(URL "/$LOCATION")" fi ;; register) regnick="$(POST regnick |username)" userdir="$_DATA/@${regnick}" - if [ "$regnick" ] && mkdir "$userdir"; then + if [ "$NICK_REGISTRATION" != on ]; then + export ERROR='.register Nickname registration is disabled on this server.' + elif [ "$regnick" = Guest ]; then + export ERROR='.register The name "Guest" may not be registered as a permanent nickname.' + elif [ -z "$regnick" ]; then + export ERROR='.register Nicknames must be between 3 and 24 characters long. They may not start with "&", "#", "?", "@", or "+" and they must not contain a "/".' + elif [ -d "$userdir" ]; then + export ERROR=".register This nickname has already been registered elsewhere." + elif mkdir "$userdir"; then secuid="$(randomid)"; clientid="$(randomid)" printf %s\\n "$secuid" >"${userdir}/secuid" clientid="${clientid}-$(printf '%s%s' "${clientid}" "${secuid}" |sha256sum |cut -d\ -f1)" @@ -62,8 +76,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 Registration failed, possibly due to faulty server configuration." fi ;; esac