4 # Remove trailing CR, which may have been added by browser
6 # Collapse white spaces
8 # Remove starting and trailing white spaces
10 # Usernames starting with & # ? @ + will be invalid
12 # Usernames containing a / will be invalid
14 # Usernames must be between 3 and 24 characters
16 # Usernames may not span multiple lines
19 { [ $# -eq 0 ] && cat || printf %s "$*"; } \
20 | sed -E ':X; $!{N;bX;}'"$UNAME_VALID"
23 nickname="$(COOKIE nick |username)"
24 if [ ! "$nickname" ]; then
26 elif [ ! -d "$_DATA/@$nickname" ]; then
29 userclient="$(COOKIE user_client)"
30 secuid="$(cat "$_DATA/@$nickname/secuid")"
31 clientid="${userclient%%-*}"
32 clientid="${clientid}-$(printf '%s%s' "${clientid}" "${secuid}" |sha256sum)"
33 clientid="${clientid%% *}"
34 if [ "$clientid" = "$userclient" ]; then
36 SET_COOKIE +"$((86400 * 365))" "user_client=${clientid}" HttpOnly
37 SET_COOKIE +"$((86400 * 365))" "nick=$(URL "${nickname}")"
43 case $(POST action) in
45 nick="$(POST nickname |username)"
46 if [ ! -d "$_DATA/@$nick" ]; then
47 SET_COOKIE +1209600 "nick=$(POST nickname |URL)"
48 REDIRECT "$(URL "/$LOCATION")"
50 export ERROR=".nick This nickname has already been registered elsewhere"
54 regnick="$(POST regnick |username)"
55 userdir="$_DATA/@${regnick}"
56 if [ "$regnick" ] && mkdir "$userdir"; then
57 secuid="$(randomid)"; clientid="$(randomid)"
58 printf %s\\n "$secuid" >"${userdir}/secuid"
59 clientid="${clientid}-$(printf '%s%s' "${clientid}" "${secuid}" |sha256sum |cut -d\ -f1)"
60 SET_COOKIE +"$((86400 * 365))" "user_client=${clientid}" HttpOnly
61 SET_COOKIE +"$((86400 * 365))" "nick=$(URL "${regnick}")"
62 REDIRECT "$(URL "/$LOCATION")"
64 export ERROR=".register This nickname has already been registered elsewhere"