diff options
author | NavaL <mnandri@thoughtworks.com> | 2016-01-27 19:29:36 +0100 |
---|---|---|
committer | NavaL <mnandri@thoughtworks.com> | 2016-01-28 10:43:14 +0100 |
commit | 766c5617007650d90f1d249aaa253755dcd1906c (patch) | |
tree | ebe66b6219cbbab28b5101a72a3338210c69f99c /service/pixelated/resources | |
parent | 29f0bd4576955536d3714b1c095bcfe387ec51b9 (diff) |
making async setup user services after auth
Issue #583
Diffstat (limited to 'service/pixelated/resources')
-rw-r--r-- | service/pixelated/resources/auth.py | 7 | ||||
-rw-r--r-- | service/pixelated/resources/login_resource.py | 22 |
2 files changed, 17 insertions, 12 deletions
diff --git a/service/pixelated/resources/auth.py b/service/pixelated/resources/auth.py index 4eb6bd02..5e0221cb 100644 --- a/service/pixelated/resources/auth.py +++ b/service/pixelated/resources/auth.py @@ -53,12 +53,12 @@ class LeapPasswordChecker(object): def _validate_credentials(): try: srp_auth = SRPAuth(self._leap_provider.api_uri, self._leap_provider.local_ca_crt) - srp_auth.authenticate(credentials.username, credentials.password) + return srp_auth.authenticate(credentials.username, credentials.password) except SRPAuthenticationError: raise UnauthorizedLogin() - def _authententicate_user(_): - return authenticate_user(self._leap_provider, credentials.username, credentials.password) + def _authententicate_user(srp_auth): + return authenticate_user(self._leap_provider, credentials.username, credentials.password, auth=srp_auth) d = threads.deferToThread(_validate_credentials) d.addCallback(_authententicate_user) @@ -131,7 +131,6 @@ class PixelatedAuthSessionWrapper(object): def getChildWithDefault(self, path, request): request.postpath.insert(0, request.prepath.pop()) - return self._authorizedResource(request) def _authorizedResource(self, request): diff --git a/service/pixelated/resources/login_resource.py b/service/pixelated/resources/login_resource.py index 065d71e7..6109f232 100644 --- a/service/pixelated/resources/login_resource.py +++ b/service/pixelated/resources/login_resource.py @@ -96,10 +96,14 @@ class LoginResource(BaseResource): return renderElement(request, site) def render_POST(self, request): + if self.is_logged_in(request): + return util.redirectTo("/", request) - def render_response(response): - util.redirectTo("/", request) + def render_response(leap_user): + request.setResponseCode(OK) + request.write(open(os.path.join(self._startup_folder, 'Interstitial.html')).read()) request.finish() + self._setup_user_services(leap_user, request) def render_error(error): log.info('Login Error for %s' % request.args['username'][0]) @@ -114,15 +118,17 @@ class LoginResource(BaseResource): @defer.inlineCallbacks def _handle_login(self, request): - if self.is_logged_in(request): - request.setResponseCode(OK) - defer.succeed(None) - return + creds = self._get_creds_from(request) + iface, leap_user, logout = yield self._portal.login(creds, None, IResource) + defer.returnValue(leap_user) + + def _get_creds_from(self, request): username = request.args['username'][0] password = request.args['password'][0] - creds = credentials.UsernamePassword(username, password) - iface, leap_user, logout = yield self._portal.login(creds, None, IResource) + return credentials.UsernamePassword(username, password) + @defer.inlineCallbacks + def _setup_user_services(self, leap_user, request): yield self._initialize_after_login(self._services_factory, leap_user) self._init_http_session(request, leap_user) |