2014-09-05 18:40:12 +00:00
|
|
|
module Handler.ProfileDelete where
|
|
|
|
|
|
|
|
import Import
|
2014-12-28 00:08:35 +00:00
|
|
|
import Handler.Commons
|
2014-09-05 18:40:12 +00:00
|
|
|
import qualified Data.Text as T
|
2014-12-07 06:55:03 +00:00
|
|
|
import qualified Data.List as L
|
2014-09-05 18:40:12 +00:00
|
|
|
import System.Directory
|
|
|
|
import System.FilePath
|
|
|
|
|
|
|
|
getProfileDeleteR :: UserId -> Handler Html
|
|
|
|
getProfileDeleteR userId = do
|
2014-12-27 23:01:40 +00:00
|
|
|
checkRes <- profileCheck userId
|
|
|
|
case checkRes of
|
|
|
|
Right user -> do
|
|
|
|
defaultLayout $ do
|
|
|
|
setTitle "Eidolon :: Delete user profile"
|
|
|
|
$(widgetFile "profileDelete")
|
|
|
|
Left (errorMsg, route) -> do
|
|
|
|
setMessage errorMsg
|
|
|
|
redirect $ route
|
2014-09-05 18:40:12 +00:00
|
|
|
|
|
|
|
postProfileDeleteR :: UserId -> Handler Html
|
|
|
|
postProfileDeleteR userId = do
|
2014-12-27 23:01:40 +00:00
|
|
|
checkRes <- profileCheck userId
|
|
|
|
case checkRes of
|
|
|
|
Right user -> do
|
|
|
|
confirm <- lookupPostParam "confirm"
|
|
|
|
case confirm of
|
|
|
|
Just "confirm" -> do
|
|
|
|
albumList <- return $ userAlbums user
|
2014-12-28 06:12:25 +00:00
|
|
|
_ <- mapM (\albumId -> do
|
2014-12-27 23:01:40 +00:00
|
|
|
album <- runDB $ getJust albumId
|
|
|
|
mediaList <- return $ albumContent album
|
2014-12-28 06:12:25 +00:00
|
|
|
_ <- mapM (\med -> do
|
2014-12-27 23:01:40 +00:00
|
|
|
commEnts <- runDB $ selectList [CommentOrigin ==. med] []
|
2014-12-28 06:12:25 +00:00
|
|
|
_ <- mapM (\ent -> runDB $ delete $ entityKey ent) commEnts
|
2014-12-27 23:01:40 +00:00
|
|
|
medium <- runDB $ getJust med
|
|
|
|
liftIO $ removeFile (normalise $ L.tail $ mediumPath medium)
|
|
|
|
liftIO $ removeFile (normalise $ L.tail $ mediumThumb medium)
|
|
|
|
runDB $ delete med
|
|
|
|
) mediaList
|
|
|
|
runDB $ delete albumId
|
|
|
|
) albumList
|
|
|
|
runDB $ delete userId
|
|
|
|
liftIO $ removeDirectoryRecursive $ "static" </> "data" </> (T.unpack $ extractKey userId)
|
|
|
|
deleteSession "userId"
|
|
|
|
setMessage "User deleted successfully"
|
|
|
|
redirect $ HomeR
|
|
|
|
_ -> do
|
|
|
|
setMessage "You must confirm the deletion"
|
|
|
|
redirect $ ProfileSettingsR userId
|
|
|
|
Left (errorMsg, route) -> do
|
|
|
|
setMessage errorMsg
|
|
|
|
redirect $ route
|