Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc authenticateUser(username, password, ip: string): AuthResult =
- #[
- Tries to authenticate the user.
- TODO:
- - Hash the password
- - Return a valid AuthResult
- ]#
- let
- pwdHash = "123"
- user = waitFor(db["accounts"].find(bson.`%*`({
- "username": username,
- "password": pwdHash
- })).one())
- result = (
- result: false,
- username: username,
- token: nil
- )
- routes:
- post "/auth/login":
- let
- username = request.formData["username"].body
- password = request.formData["password"].body
- ip = request.ip
- var authResponse: string = ""
- # Try to authenticate the user
- let auth = authenticateUser(username, password, ip)
- if not auth.result:
- # Failed to authenticate, return an error
- authResponse = $$AuthLoginResponse(
- status: "error",
- message: "Invalid username and/or password.",
- username: nil,
- token: nil)
- else:
- # Success authenticating, return a session and token
- authResponse = $$AuthLoginResponse(
- status: "success",
- message: nil,
- username: auth.username,
- token: auth.token)
- resp authResponse
- ####
- Traceback:
- lib/nim/core/macros.nim(359, 13) Error: type mismatch: got (proc (request: Request, response: Response): Future[system.bool]{.locks: <unknown>.}, Settings)
- but expected one of:
- proc serve(match: proc (request: Request; response: Response): Future[bool];
- settings: Settings = newSettings())
- stack trace: (most recent call last)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement