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

not working now ? #11

Open
2vg opened this issue May 19, 2018 · 1 comment
Open

not working now ? #11

2vg opened this issue May 19, 2018 · 1 comment

Comments

@2vg
Copy link

2vg commented May 19, 2018

:(

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>
@2vg
Copy link
Author

2vg commented May 19, 2018

sorry, forgot comment out "auth.headers_hook(request.headers)" in /login .
but, raised this error.

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(40) matchIter
httpauth.nim(625) require
httpauth.nim(616) current_user
base.nim(58) get_user
sql_backend.nim(218) get_user
sql_backend.nim(60) db_getrow
db_sqlite.nim(229) getRow
db_sqlite.nim(148) setupQuery
db_sqlite.nim(104) dbError
unrecognized token: "'admin"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant