Skip to content

Commit

Permalink
changed admin page and changed database functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mast3rwaf1z committed Nov 5, 2024
1 parent 9c69460 commit 33e2755
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 11 additions & 5 deletions app/Pages/Admin/Admin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Layout (layout)
import Page (Page, PageSetting (Description, Route), getArgs)
import Text.Blaze.Html (Html)
import Network.Wai (Request)
import State (getStates, loggedIn)
import State (getStates, loggedIn, accessToken)

panel :: Html
panel = [hsx|
Expand All @@ -33,8 +33,9 @@ login = [hsx|
})
}).then(response => {
if (response.status == 200)
response.text().then(text => {
setCookie("accessToken="+text)
response.json().then(json => {
setCookie("accessToken="+json.token)
window.location.reload()
})
})
}
Expand All @@ -47,8 +48,13 @@ login = [hsx|
page :: Request -> IO Html
page request = do
let states = getStates request
if loggedIn states then
return panel
if loggedIn states then do
let token = accessToken states
valid <- validateToken token
if valid then
return panel
else
return login
else
return login

Expand Down
6 changes: 2 additions & 4 deletions lib/Database/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Data.Text (Text, pack, unpack)
import Database.Persist.MySQL (ConnectInfo (ConnectInfo, connectDatabase, connectUser), Entity (Entity), EntityNameDB (unEntityNameDB), FieldDef (FieldDef), FieldNameHS (unFieldNameHS), Filter (Filter), FilterValue (FilterValue), PersistFilter (BackendSpecificFilter), PersistStoreWrite (insert_), SqlPersistT, defaultConnectInfo, fieldDBName, getEntityDBName, getEntityFields, runMigration, runSqlConn, selectList, withMySQLConn)
import Database.Persist.TH (mkMigrate, mkPersist, persistLowerCase, share, sqlSettings)
import Database.Persist.Types (EntityDef, FieldDef (fieldSqlType), fieldHaskell)
import Database.Schema (EntityField (TokenToken, VisitUuid), GuestbookEntry (GuestbookEntry), Snake, Token (tokenName), User (userName), Visit, defs, migrateAll)
import Database.Schema (EntityField (TokenToken, VisitUuid), GuestbookEntry (GuestbookEntry), Snake, Token (tokenName, tokenToken), User (userName), Visit, defs, migrateAll)
import Logger (info)
import Tree (Tree (Tree))

Expand Down Expand Up @@ -94,6 +94,4 @@ prettyPrintSchema =
validateToken :: String -> IO Bool
validateToken token = do
tokens <- getTokens
case tokens of
[] -> return False
_ -> return True
return $ any (\x -> tokenToken x == token) tokens

0 comments on commit 33e2755

Please sign in to comment.