Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

not working now ? #11

@2vg

Description

@2vg

:(

An error has occured in one of your routes.
Detail: test.nim(45) test
asyncdispatch.nim(1507) runForever
asyncdispatch.nim(1511) poll
asyncdispatch.nim(1277) runOnce
asyncdispatch.nim(183) processPendingCallbacks
asyncmacro.nim(37) processRequest_continue
asynchttpserver.nim(143) processRequestIter
jester.nim(350) :anonymous
jester.nim(321) handleHTTPRequest
asyncmacro.nim(401) handleRequest
asyncmacro.nim(34) handleRequest_continue
jester.nim(283) handleRequestIter
asyncmacro.nim(401) match
asyncmacro.nim(34) match_continue
test.nim(21) matchIter
httpcore.nim(130) []
tables.nim(405) []
tables.nim(151) []
key not found: set-cookie

here is code.

import asyncdispatch,
  httpauth,
  jester,
  json,
  strutils

# Create a backend as needed and an HTTPAuth instance
let backend = newSQLBackend("sqlite://./auth.sqlite3")
var auth = newHTTPAuth("MyIPAddress", backend, https_only_cookies=false)

# Create admin user - you need to run this only once
auth.initialize_admin_user(password="demo")

routes:
  post "/login":
    ## Perform login
    #auth.headers_hook(request.headers)
    try:
      auth.login(@"username", @"password")
      # move set-cookie to right place - FIXME
      response.data[2]["Set-Cookie"] = request.headers["set-cookie"]
      resp "Success"
    except LoginError:
      resp "Failed"
  get "/logout":
    ## Logout
    auth.headers_hook(request.headers)
    try:
      auth.logout()
      # move set-cookie to right place - FIXME
      if request.headers.hasKey("set-cookie"):
        response.data[2]["Set-Cookie"] = request.headers["set-cookie"]
      resp "Success"
    except AuthError:
      resp "Failed"
  get "/private":
    ## Only authenticated users can see this
    auth.headers_hook(request.headers)
    try:
      auth.require()
    except AuthError:
      resp "Sorry, you are not authorized."
    resp """Welcome! <a href="/admin">Admin page</a> <a href="/logout">Logout</a>"""

runForever()
<form action="login" method="post">
  <div>
    <label for="username">Username</label>
    <input name="username" type="text"></input>
  </div>
  <div>
    <label for="password">password</label>
    <input name="password" type="password"></input>
  </div>
  <div>
    <input type="submit" value="login"></input>
  </div>
</form>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions