]> git.plutz.net Git - shellwiki/commitdiff
Merge commit '1f887be68c8e777cdaa6853eb942f7b691bc1e4e'
authorPaul Hänsch <paul@plutz.net>
Tue, 17 May 2022 23:27:06 +0000 (01:27 +0200)
committerPaul Hänsch <paul@plutz.net>
Tue, 17 May 2022 23:27:06 +0000 (01:27 +0200)
1  2 
cgilite/common.css
cgilite/markdown.awk
cgilite/users.sh

diff --combined cgilite/common.css
index 359f07d138b7ef91f1441a2738dd1352bbefecb6,a79230a05de2572adcc04eeb236ebfbe60cb19f3..a79230a05de2572adcc04eeb236ebfbe60cb19f3
@@@ -17,6 -17,7 +17,7 @@@ body 
  }
  
  ul, ol, dl, table, p { margin-bottom: .5em; }
+ p:only-child { margin-bottom: 0; }
  
  a {
    font-style: italic;
@@@ -44,6 -45,10 +45,10 @@@ ul, ol { margin-left: 1.125em; 
  dl dt { font-weight: bolder; }
  table th { font-weight: bold; }
  
+ li p + ul, li p + ol {
+   margin-top: -.25em;
+ }
  hr { border-bottom: 1pt solid; }
  
  h1, h2, h3 {
diff --combined cgilite/markdown.awk
index d28c7cfc760a2ed6c9fde6e040a2bf981c008b38,b0647922efdcbf5859dac4d3cda72145035403ed..b0647922efdcbf5859dac4d3cda72145035403ed
@@@ -56,6 -56,7 +56,7 @@@
  # - [ ] Definition lists (php md, pandoc)
  # - [-] Numbered example lists (pandoc)
  # - [-] Metadata blocks (pandoc)
+ # - [x] Metadata blocks (custom)
  # - [x] Fenced Divs (pandoc)
  #
  # Extensions - Inline elements:
@@@ -279,6 -280,12 +280,12 @@@ function _block( block, LOCAL, st, len
    } else if ( AllowHTML && match( block, /^ ? ? ?(<\/[A-Za-z][A-Za-z0-9-]*[[:space:]]*>|<[A-Za-z][A-Za-z0-9-]*([[:space:]]+[A-Za-z_:][A-Za-z0-9_\.:-]*([[:space:]]*=[[:space:]]*([[:space:]"'=<>`]+|"[^"]*"|'[^']*'))?)*[[:space:]]*\/?>)([[:space:]]*\n)([^\n]|\n[ \t]*[^\n])*(\n[[:space:]]*\n|$)/) ) {
      len = RLENGTH; st = RSTART;
      return substr(block, st, len) _block(substr(block, st + len));
+   # Metadata (custom, block starting with %something)
+   # Metadata is ignored but can be interpreted externally
+   } else if ( match(block, /^%[a-zA-Z]+([[:space:]][^\n]*)?(\n|$)(%[a-zA-Z]+([[:space:]][^\n]*)?(\n|$)|%([[:space:]][^\n]*)?(\n|$)|[ \t]+[^\n[:space:]][^\n]*(\n|$))*/) ) {
+     len = RLENGTH; st = RSTART;
+     return  _block( substr( block, len + 1) );
   
    # Blockquote (leading >)
    } else if ( match( block, /^> /) ) {
diff --combined cgilite/users.sh
index 44a5e136c9b9ba1189d55880009e799c9468668b,87143d8718aa1083e1b1d9d5bb3ec93b2cca8372..87143d8718aa1083e1b1d9d5bb3ec93b2cca8372
@@@ -391,9 -391,35 +391,35 @@@ user_logout()
  }
  
  user_update(){
-   # passphrase, email
-   :
+   # todo: username update, email update / email confirm
+   local UID   UNAME   STATUS  EMAIL   PWSALT  PWHASH  EXPIRE  DEVICES FUTUREUSE
+   # local uname="$(POST uname |STRING)"
+   local uid oldpw pw pwconfirm
+         uid="$(POST uid)"
+       oldpw="$(POST oldpw)"
+          pw="$(POST pw |grep -xE '.{6}')"
+   pwconfirm="$(POST pwconfirm)"
+   read -r UID UNAME   STATUS  EMAIL   PWSALT  PWHASH  EXPIRE  DEVICES FUTUREUSE <<-EOF
+       $(grep "^${uid} " "$user_db")
+       EOF
+   if [ "$UID" = "$USER_ID" -a "$PWHASH" = "$(user_pwhash "$PWSALT" "$oldpw")" ]; then
+     if [ "$pw" -a "$pw" = "$pwconfirm" ]; then
+       update_user "${uid}" password="$pw"
+       REDIRECT "${_BASE}${PATH_INFO}#UPDATE_SUCCESS"
+     else
+       REDIRECT "${_BASE}${PATH_INFO}#ERROR_PWMISMATCH"
+     fi
+   elif [ "$UID" = "$USER_ID" ]; then
+     REDIRECT "${_BASE}${PATH_INFO}#ERROR_INVALID_AUTH_PASSWORD"
+   else
+     REDIRECT "${_BASE}${PATH_INFO}#ERROR_NOTLOGGEDIN"
+   fi
  }
  user_recover(){
    # send recover link
    :
@@@ -411,14 -437,34 +437,34 @@@ read_user "$(SESSION_VAR user_id)
    user_invite)   user_invite ;;
    user_login)    user_login ;;
    user_logout)   user_logout ;;
-   user_update)
-     :;;
+   user_update)   user_update ;;
    user_recover)
      :;;
    user_disable)
      :;;
  esac
  
+ w_user_update(){
+   if [ ! "$USER_ID" ]; then
+     cat <<-EOF
+       [div #user_update .nouser
+       This page can only be used by registered users
+       ]
+       EOF
+   else
+     cat <<-EOF
+       [form #user_update method=POST
+         [hidden "uid" "$USER_ID"]
+         [p .username Logged in as $USER_NAME]
+         [input type=password name=oldpw placeholder="Current Passphrase"]
+         [input type=password name=pw placeholder="New Passphrase" pattern=".{6,}"]
+         [input type=password name=pwconfirm placeholder="Confirm New Passphrase" pattern=".{6,}"]
+         [submit "action" "user_update" Update Passphrase]
+       ]
+       EOF
+   fi
+ }
  w_user_register(){
    if [ "$(GET user_confirm)" ]; then
      w_user_confirm
    elif [ "$USER_REQUIREEMAIL" != true ]; then
      cat <<-EOF
        [form #user_register .registername method=POST
-           [input name=uname placeholder="Choose Username" tooltip="Your username may contain any character but the @ sign. It must be at least 3 characters long, and it must start with a letter." pattern="^\[a-zA-Z\]\[a-zA-Z0-9 -~\]{2,127}$" autocomplete=off]
+           [input name=uname placeholder="Choose Username" tooltip="Your username may contain any character but the @ sign. It must be at least 3 characters long, and it must start with a letter." pattern="^\[\\\\p{L}\]\[\\\\p{L}0-9 -~\]{2,127}$" autocomplete=off]
          [input type=password name=pw placeholder="Choose Passphrase" pattern=".{6,}"]
          [input type=password name=pwconfirm placeholder="Confirm Passphrase" pattern=".{6,}"]
          [submit "action" "user_register" Sign Up]
@@@ -467,7 -513,7 +513,7 @@@ w_user_confirm()
          $([ "$EMAIL" != '\' ] && printf \
            '[input disabled=disabled value="%s" placeholder="Email"]' "$(UNSTRING "$EMAIL" |HTML)"
          )
-           [input name=uname placeholder="Choose Username" tooltip="Your username may contain any character but the @ sign. It must be at least 3 characters long, and it must start with a letter." pattern="^\[a-zA-Z\]\[a-zA-Z0-9 -~\]{2,127}$" autocomplete=off]
+           [input name=uname placeholder="Choose Username" tooltip="Your username may contain any character but the @ sign. It must be at least 3 characters long, and it must start with a letter." pattern="^\[\\\\p{L}\]\[\\\\p{L}0-9 -~\]{2,127}$" autocomplete=off]
          [input type=password name=pw placeholder="Choose Passphrase" pattern=".{6,}"]
          [input type=password name=pwconfirm placeholder="Confirm Passphrase" pattern=".{6,}"]
          [submit "action" "user_confirm" Finish Registration]