@@ -55,18 +55,19 @@ displayEvents getEventsQuery mUser = do
55
55
newEventAction :: (ListContains n User xs , ListContains m IsAdmin xs ) => Action (HVect xs ) ()
56
56
newEventAction = do
57
57
title <- cfgTitle . appConfig <$> getState
58
+ csrfToken <- getCsrfToken
58
59
let
59
60
-- | Display the form to the user
60
61
formView mErr view = do
61
62
formViewer title " Sign-up" (editEventFormView path " Create" ) mErr view
62
63
63
64
-- Run the form
64
- form <- runForm path (editEventForm Nothing )
65
+ form <- runForm " " (editEventForm csrfToken Nothing )
65
66
-- validate the form.
66
67
-- Nothing means failure. will display the form view back to the user when validation fails.
67
68
case form of
68
69
(view, Nothing ) ->
69
- lucid $ formView Nothing view
70
+ formView Nothing view
70
71
-- If basic validation of fields succeeds, continue to check validation against db
71
72
72
73
(_, Just (EditEvent name desc loc mWhen mDur))
@@ -96,6 +97,7 @@ newEventAction = do
96
97
editEventAction :: (ListContains n User xs , ListContains m IsAdmin xs ) => EventId -> Action (HVect xs ) ()
97
98
editEventAction eid = do
98
99
title <- cfgTitle . appConfig <$> getState
100
+ csrfToken <- getCsrfToken
99
101
let
100
102
-- | Display the form to the user
101
103
formView mErr view = do
@@ -113,12 +115,12 @@ editEventAction eid = do
113
115
Right (Just editedEvent) -> do
114
116
115
117
-- Run the form
116
- form <- runForm path (editEventForm $ Just $ eventToEditEvent editedEvent)
118
+ form <- runForm " " (editEventForm csrfToken $ Just $ eventToEditEvent editedEvent)
117
119
-- validate the form.
118
120
-- Nothing means failure. will display the form view back to the user when validation fails.
119
121
case form of
120
122
(view, Nothing ) ->
121
- lucid $ formView Nothing view
123
+ formView Nothing view
122
124
-- If basic validation of fields succeeds, continue to check validation against db
123
125
124
126
(_, Just (EditEvent name desc loc mWhen mDur))
@@ -143,9 +145,11 @@ editEventAction eid = do
143
145
144
146
-- | Describe the action to do when a user wants to delete an existing event
145
147
--
146
- removeEventAction :: (ListContains n User xs , ListContains m IsAdmin xs ) => EventId -> Action (HVect xs ) ()
147
- removeEventAction eid = do
148
+ deleteEventAction :: (ListContains n User xs , ListContains m IsAdmin xs ) => EventId -> Action (HVect xs ) ()
149
+ deleteEventAction eid = do
148
150
mEvent <- runQuery $ Sql. run (getEventById eid)
151
+ csrfToken <- getCsrfToken
152
+
149
153
case mEvent of
150
154
-- @TODO this is an internal error that we should take care of internally
151
155
Left err ->
@@ -155,14 +159,33 @@ removeEventAction eid = do
155
159
text " Event does not exist"
156
160
157
161
Right (Just event) -> do
158
- result <- runQuery $ Sql. run (removeEvent event)
159
- case result of
160
- -- @TODO this is an internal error that we should take care of internally
161
- Left err -> do
162
- text $ T. pack (show err)
163
-
164
- Right _ ->
165
- redirect " /"
162
+
163
+ let
164
+ path = " /event/" <> T. pack (show eid) <> " /delete"
165
+ -- | Display the form to the user
166
+ formView mErr view = do
167
+ formViewer " Delete Event" " Delete" (deleteEventFormView path $ eventName event) mErr view
168
+
169
+ -- Run the form
170
+ form <- runForm " " (deleteEventForm csrfToken)
171
+ -- validate the form.
172
+ -- Nothing means failure. will display the form view back to the user when validation fails.
173
+ case form of
174
+ (view, Nothing ) ->
175
+ formView Nothing view
176
+
177
+ (_, Just (DeleteEvent False )) -> do
178
+ redirect $ " /event/" <> T. pack (show $ eventId event)
179
+
180
+ (_, Just (DeleteEvent True )) -> do
181
+ result <- runQuery $ Sql. run (removeEvent event)
182
+ case result of
183
+ -- @TODO this is an internal error that we should take care of internally
184
+ Left err -> do
185
+ text $ T. pack (show err)
186
+
187
+ Right _ ->
188
+ redirect " /"
166
189
167
190
168
191
reportEventParsingError :: EditEvent -> Action (HVect xs ) ()
0 commit comments