! Copyright (C) 2025 Serre
! See https://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs combinators csv
http http.server io.encodings.utf8 io.files
io.sockets io.streams.string kernel math.parser monadics
namespaces present sequences unicode xml.syntax
erinnemori-2.posts
erinnemori-2.users
erinnemori-2.utils
erinnemori-2.xml ;
IN: erinnemori-2.logic
CONSTANT: log-file "resource:www-data/mod/log.csv"
: >log ( resource action -- )
request get by-user?
remote-address get 4array [ present ] map
log-file utf8 [ write-row ] with-file-appender ;
: new-user>req ( E-Error/User -- req )
dup Left?
[ "Creating User..." f rot value>> >m
create-user-page f erinne-common ]
[ value>> "new-user" >log
"User Created!"
<XML <meta http-equiv="refresh"
content="3;url=/" /> XML>
f "New user created, returning to main page" >default f
erinne-common
] if ;
: process-login ( -- req )
params get [ "erinne-user" of ]
[ "erinne-pass" of ] bi
2dup and [ login ] [ 2drop f ] if
[ "Logged in, returning to homepage" >default ]
[ f "Bad Username or Password, try again." >default ] if*
[ "Logging in..."
"1;url=/" refresh-header f ] dip f
erinne-common
swap [ put-cookie ] when* ;
: process-board ( path board -- xml-main xml-footer )
swap [ empty? not ] 1guard
[ first [ topic>thread ] [ new-reply-form ] 2bi ]
[ [ board-topics topics>board ] keep
new-topic-form ]
if* ;
: process-topic ( -- header )
params get
{ [ "board" of ]
[ "session" of string>number
active-users get-global at ]
[ "topic" of ]
[ "body" of ]
[ "images" of ]
[ "tags" of ]
[ "topic" of ]
} cleave "new-topic" >log
<topic> "1;url=" prepend refresh-header ;
: process-reply ( -- header )
params get
{ [ "topic" of ]
[ "board" of ]
[ "board" of ]
[ "topic" of ]
[ "board" of ]
[ "topic" of ]
[ "session" of string>number
active-users get-global at ]
[ "title" of ]
[ "body" of ]
[ "images" of ]
[ "tags" of ]
} cleave <post>
first 3array [ write-row ] with-string-writer
but-last "new-reply" >log
topic-link "1;url=" prepend refresh-header ;
: process-rsrc ( -- header )
params get {
[ "topic" of ]
[ "board" of ]
[ "topic" of ]
[ "board" of ]
[ "link" of ]
[ "desc" of ]
[ "board" of ]
[ "topic" of ]
[ "link" of ]
} cleave 3array [ write-row ] with-string-writer
but-last "resource-added" >log
add-resource
topic-link "1;url=" prepend refresh-header ;