Skip to content

Instantly share code, notes, and snippets.

@BitPuffin
Created November 29, 2013 14:54
Show Gist options
  • Save BitPuffin/f1bbdc79ff312a67f2e8 to your computer and use it in GitHub Desktop.
Save BitPuffin/f1bbdc79ff312a67f2e8 to your computer and use it in GitHub Desktop.
post "/user/personalogin":
let ass = request.params["assertion"]
if ass == "":
halt(Http400, "assertion was not found in the request")
let data: PJsonNode = %{"assertion": %ass, "audience": %(audiencePrefix & hostname & ":" & $port)}
let response = httpclient.post(personaVerifier, "Content-Type: application/json\c\L", body=($data))
if response.status == "200 OK":
let verificationData = parseJson(response.body)
if $verificationData["status"].str == "okay":
# TODO: Set this to a secure cookie (an hmac)
let email = $verificationData["email"]
setCookie(userCookie, email, daysForward(7))
if not isUser(email):
redirect("/signup")
else:
# TODO: Redirect to current page instead
redirect("/")
else:
halt(Http500, "Something went wrong when authenticating")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment