Advertisement
Guest User

Untitled

a guest
Aug 28th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.74 KB | None | 0 0
  1. proc authenticateUser(username, password, ip: string): AuthResult =
  2.     #[
  3.         Tries to authenticate the user.
  4.         TODO:
  5.         - Hash the password
  6.         - Return a valid AuthResult
  7.     ]#
  8.  
  9.     let
  10.         pwdHash = "123"
  11.         user = waitFor(db["accounts"].find(bson.`%*`({
  12.             "username": username,
  13.             "password": pwdHash
  14.         })).one())
  15.  
  16.     result = (
  17.         result: false,
  18.         username: username,
  19.         token: nil
  20.     )
  21.  
  22. routes:
  23.     post "/auth/login":
  24.         let
  25.             username = request.formData["username"].body
  26.             password = request.formData["password"].body
  27.             ip = request.ip
  28.  
  29.         var authResponse: string = ""
  30.  
  31.         # Try to authenticate the user
  32.         let auth = authenticateUser(username, password, ip)
  33.  
  34.         if not auth.result:
  35.             # Failed to authenticate, return an error
  36.             authResponse = $$AuthLoginResponse(
  37.                 status: "error",
  38.                 message: "Invalid username and/or password.",
  39.                 username: nil,
  40.                 token: nil)
  41.         else:
  42.             # Success authenticating, return a session and token
  43.             authResponse = $$AuthLoginResponse(
  44.                 status: "success",
  45.                 message: nil,
  46.                 username: auth.username,
  47.                 token: auth.token)
  48.  
  49.         resp authResponse
  50.  
  51. ####
  52. Traceback:
  53. lib/nim/core/macros.nim(359, 13) Error: type mismatch: got (proc (request: Request, response: Response): Future[system.bool]{.locks: <unknown>.}, Settings)
  54. but expected one of:
  55. proc serve(match: proc (request: Request; response: Response): Future[bool];
  56.           settings: Settings = newSettings())
  57.  
  58. stack trace: (most recent call last)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement