#!/bin/bash source exprash.sh; redirect_stdout 'log'; use_session use_body username='admin' password='password' # Authorization middleware function is_authorized() { if [ "$(session 'authorized')" != "1" ]; then next 'unauthorized' return 1 fi } get '/' && { if [ "$(session 'authorized')" == "1" ]; then html="
You must login to learn secrets
" html+="Login" fi printf '%s\n' "$html" | send } get '/admin' && is_authorized && { html='Try again:
" html+="Login" printf '%s\n' "$html" | send fi } post '/login' && { post_user=$(body 'username') post_pass=$(body 'password') if [ "$post_user" == "$username" ] && [ "$post_pass" == "$password" ]; then session 'authorized' 1 redirect '.' else redirect 'incorrect-password' fi } get '/logout' && { session 'authorized' 0 redirect '.' } (use || use_error) && { if [ "$(get_error_message)" == "unauthorized" ]; then html='