Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. from eve import Eve
  2. from eve.auth import BasicAuth
  3.  
  4.  
  5. class Authenticate(BasicAuth):
  6.     def check_auth(self, username, password, allowed_roles, resource,
  7.                    method):
  8.         resource_user_req_GET = resource == "user" and method == "GET"
  9.         resource_user_req_POST = resource == 'user' and method == 'POST'
  10.         if resource_user_req_GET:
  11.             user = app.data.driver.db["user"]
  12.             user = user.find_one(
  13.                     {
  14.                         "username":username,
  15.                         "password": password
  16.                     })
  17.             if user:
  18.                 return True
  19.             else:
  20.                 return False
  21.         elif resource_user_req_POST:
  22.             return username == 'admin' and password == 'admin'
  23.         else:
  24.             return True
  25.  
  26.                
  27. if __name__ == '__main__':
  28.     app = Eve(auth=Authenticate)
  29.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement