##// END OF EJS Templates
authn: Fix container auth in login view.
johbo -
r104:26bb2eb5 default
parent child Browse files
Show More
@@ -28,6 +28,7 b' from pyramid.httpexceptions import HTTPF'
28 28 from pyramid.view import view_config
29 29 from recaptcha.client.captcha import submit
30 30
31 from rhodecode.authentication.base import authenticate, HTTP_TYPE
31 32 from rhodecode.events import UserRegistered
32 33 from rhodecode.lib.auth import (
33 34 AuthUser, HasPermissionAnyDecorator, CSRFRequired)
@@ -115,11 +116,25 b' class LoginView(object):'
115 116 route_name='login', request_method='GET',
116 117 renderer='rhodecode:templates/login.html')
117 118 def login(self):
119 came_from = get_came_from(self.request)
118 120 user = self.request.user
119 121
120 122 # redirect if already logged in
121 123 if user.is_authenticated and not user.is_default and user.ip_allowed:
122 raise HTTPFound(get_came_from(self.request))
124 raise HTTPFound(came_from)
125
126 # check if we use container plugin, and try to login using it.
127 try:
128 log.debug('Running PRE-AUTH for container based authentication')
129 auth_info = authenticate(
130 '', '', self.request.environ, HTTP_TYPE, skip_missing=True)
131 if auth_info:
132 headers = _store_user_in_session(
133 self.session, auth_info.get('username'))
134 raise HTTPFound(came_from, headers=headers)
135 except UserCreationError as e:
136 log.error(e)
137 self.session.flash(e, queue='error')
123 138
124 139 return self._get_template_context()
125 140
@@ -157,23 +172,6 b' class LoginView(object):'
157 172 # with user creation, explanation should be provided in
158 173 # Exception itself
159 174 session.flash(e, queue='error')
160
161 # check if we use container plugin, and try to login using it.
162 from rhodecode.authentication.base import authenticate, HTTP_TYPE
163 try:
164 log.debug('Running PRE-AUTH for container based authentication')
165 auth_info = authenticate(
166 '', '', self.request.environ, HTTP_TYPE, skip_missing=True)
167 except UserCreationError as e:
168 log.error(e)
169 session.flash(e, queue='error')
170 # render login, with flash message about limit
171 return self._get_template_context()
172
173 if auth_info:
174 headers = _store_user_in_session(auth_info.get('username'))
175 raise HTTPFound(came_from, headers=headers)
176
177 175 return self._get_template_context()
178 176
179 177 @CSRFRequired()
General Comments 0
You need to be logged in to leave comments. Login now