nim-httpauth
nim-httpauth copied to clipboard
not working now ?
:(
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>
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"