@@ -181,19 +181,57 @@ In the Phoenix Framework, you would use functionality found within the [Plug lib
181181
182182_ Fill out the ` put_resp_cookie/4 ` function arguments with the settings outlined in the previous section, no other code changes should be necessary._
183183
184+ <!-- livebook:{"attrs":"eyJzb3VyY2UiOiIjIENPT0tJRV9TRUNVUklUWToxIFxuXG5jb29raWVfbmFtZSA9IFwiQ0hBTkdFX01FXCJcblxuIyBVbmNvbW1lbnQgYW5kIGNoYW5nZSB0aGUgcHV0X3Jlc3BfY29va2llIGNhbGwgYmVsb3dcbiMgY29ubiA9XG4jICAgUGx1Zy5Db25uLnB1dF9yZXNwX2Nvb2tpZShcbiMgICAgIGNvbm4sXG4jICAgICBjb29raWVfbmFtZSxcbiMgICAgIDw8MDo6OCwgNDI6Ojg+PixcbiMgICAgIGRvbWFpbjogLi4uLFxuIyAgICAgcGF0aDogLi4uLFxuIyAgICAgc2VjdXJlOiAuLi4sXG4jICAgICBodHRwX29ubHk6IC4uLixcbiMgICAgIHNhbWVfc2l0ZTogLi4uXG4jICAgKVxuXG5jb29raWUgPSBcbiAgY29ublxuICB8PiBQbHVnLkNvbm4uZmV0Y2hfY29va2llcygpXG4gIHw+IFBsdWcuQ29ubi5nZXRfcmVzcF9jb29raWVzKClcbiAgfD4gTWFwLmZldGNoIShjb29raWVfbmFtZSlcblxue2Nvb2tpZSwgYmluYXJ5X3BhcnQoY29va2llX25hbWUsIDAsIDYpfSJ9","chunks":null,"kind":"Elixir.GradingClient.GradedCell","livebook_object":"smart_cell"} -->
185+
184186``` elixir
185- cookie_name = " CHANGE_ME_TOO"
186-
187- conn
188- |> Plug .Conn .put_resp_cookie (
189- cookie_name,
190- << 42 :: 16 >>
191- # domain: ,
192- # path: ,
193- # secure: ,
194- # http_only: ,
195- # same_site:
196- )
187+ result =
188+ (
189+ cookie_name = " CHANGE_ME"
190+
191+ cookie =
192+ conn
193+ |> Plug .Conn .fetch_cookies ()
194+ |> Plug .Conn .get_resp_cookies ()
195+ |> Map .fetch! (cookie_name)
196+
197+ {cookie, binary_part (cookie_name, 0 , 6 )}
198+ )
199+
200+ [module_id, question_id] =
201+ " # COOKIE_SECURITY:1 \n\n cookie_name = \" CHANGE_ME\"\n\n # Uncomment and change the put_resp_cookie call below\n # conn =\n # Plug.Conn.put_resp_cookie(\n # conn,\n # cookie_name,\n # <<0::8, 42::8>>,\n # domain: ...,\n # path: ...,\n # secure: ...,\n # http_only: ...,\n # same_site: ...\n # )\n\n cookie = \n conn\n |> Plug.Conn.fetch_cookies()\n |> Plug.Conn.get_resp_cookies()\n |> Map.fetch!(cookie_name)\n\n {cookie, binary_part(cookie_name, 0, 6)}"
202+ |> String .split (" \n " , parts: 2 )
203+ |> hd ()
204+ |> String .trim_leading (" #" )
205+ |> String .split (" :" , parts: 2 )
206+
207+ module_id =
208+ case %{
209+ " COOKIE_SECURITY" => COOKIE_SECURITY ,
210+ " ELIXIR_SECURITY" => ELIXIR_SECURITY ,
211+ " GRAPHQL" => GRAPHQL ,
212+ " OWASP" => OWASP ,
213+ " SDLC" => SDLC
214+ }[String .trim (module_id)] do
215+ nil -> raise " invalid module id: #{ module_id } "
216+ module_id -> module_id
217+ end
218+
219+ question_id =
220+ case Integer .parse (String .trim (question_id)) do
221+ {id, " " } -> id
222+ _ -> raise " invalid question id: #{ question_id } "
223+ end
224+
225+ case GradingClient .check_answer (module_id, question_id, result) do
226+ :correct ->
227+ IO .puts ([IO .ANSI .green (), " Correct!" , IO .ANSI .reset ()])
228+
229+ {:incorrect , help_text} when is_binary (help_text) - >
230+ IO .puts ([IO .ANSI .red (), " Incorrect: " , IO .ANSI .reset (), help_text])
231+
232+ _ ->
233+ IO .puts ([IO .ANSI .red (), " Incorrect." , IO .ANSI .reset ()])
234+ end
197235```
198236
199237## Data Privacy For Cookies
0 commit comments