forked from nfarina/dropdav
/
app.py
42 lines (32 loc) · 1.53 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from google.appengine.ext.webapp.util import run_wsgi_app
from models import DropboxUser
from oauth.oauth import OAuthToken
from simpledav.wsgi import WSGIApplication
from views import AuthHandler, DropboxDAVHandler, dropbox_client
auth_handler = AuthHandler()
class DropboxWebDAVApplication(WSGIApplication):
def handle_request(self, environ, request, response):
method = environ['REQUEST_METHOD']
if True:# or (method == 'GET' or method == 'POST') and request.path == '/':
return self.handle_main(environ, request, response)
# Check authentication
(email, password) = self.get_credentials(request)
if email:
user = DropboxUser.find_by_email(email)
if user and user.is_password_valid(password):
self._handler.client = dropbox_client(OAuthToken.from_string(user.access_token))
return super(DropboxWebDAVApplication,self).handle_request(environ,request,response)
else:
return self.request_authentication(response)
else:
return self.request_authentication(response)
def handle_main(self, environ, request, response):
method = environ['REQUEST_METHOD']
auth_handler.initialize(request, response)
handler_method = getattr(auth_handler,method.lower())
handler_method()
application = DropboxWebDAVApplication(debug=True,handler_cls=DropboxDAVHandler)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()