1- from ckan .views .user import RegisterView , EditView , PerformResetView , rotate_token , next_page_or_default
2- # from ckan.lib.repoze_plugins.friendly_form import FriendlyFormPlugin
1+ from ckan .views .user import (
2+ RegisterView , EditView , PerformResetView ,
3+ rotate_token , next_page_or_default
4+ )
35import ckan .logic as logic
46import ckan .plugins as plugins
57import ckan .lib .base as base
911import ckan .plugins .toolkit as tk
1012import ckan .lib .helpers as h
1113import ckanext .password_policy .helpers as helper
12- # from webob import Request
13- # from webob.exc import HTTPFound, HTTPUnauthorized
1414from typing import Any , Optional , Union
15- from six import text_type
16- from six .moves .urllib .parse import urlencode
1715from ckan .common import (
1816 _ , config , g , current_user , login_user , logout_user ,
1917 session , config , g , request , repr_untrusted
2018)
2119from ckan .types import Context , Schema , Response , Validator
22- # try:
23- # from webob.multidict import MultiDict
24- # except ImportError:
25- # from webob import UnicodeMultiDict as MultiDict
20+
2621
2722
2823custom_user = Blueprint (u'custom_user' , __name__ , url_prefix = u'/user' )
@@ -124,98 +119,6 @@ def _get_form_password(self):
124119 return password1
125120 msg = _ (u'You must provide a password' )
126121 raise ValueError (msg )
127-
128-
129- # class FriendlyFormPlugin_(FriendlyFormPlugin):
130-
131- # def identify(self, environ):
132- # u'''
133- # Override the parent's identifier to introduce a login counter
134- # (possibly along with a post-login page) and load the login counter into
135- # the ``environ``.
136-
137- # '''
138- # allowed_failes_logins = int(config.get('ckanext.password_policy.failed_logins', 3))
139- # request = Request(environ, charset=self.charset)
140-
141- # path_info = environ[u'PATH_INFO']
142- # script_name = environ.get(u'SCRIPT_NAME') or u'/'
143- # query = request.GET
144- # if path_info == self.login_handler_path:
145- # # We are on the URL where repoze.who processes authentication. #
146- # # Let's append the login counter to the query string of the
147- # # 'came_from' URL. It will be used by the challenge below if
148- # # authorization is denied for this request.
149- # form = dict(request.POST)
150- # form.update(query)
151- # try:
152- # login = form[u'login']
153- # password = form[u'password']
154- # except KeyError:
155- # credentials = None
156- # else:
157- # if request.charset == u'us-ascii':
158- # credentials = {
159- # u'login': str(login),
160- # u'password': str(password),
161- # }
162- # else:
163- # credentials = {u'login': login, u'password': password}
164-
165- # try:
166- # credentials[u'max_age'] = form[u'remember']
167- # except KeyError:
168- # pass
169- # if helper.user_login_count(login) < allowed_failes_logins:
170- # referer = environ.get(u'HTTP_REFERER', script_name)
171- # destination = form.get(u'came_from', referer)
172-
173- # if self.post_login_url:
174- # # There's a post-login page, so we have to replace the
175- # # destination with it.
176- # destination = self._get_full_path(self.post_login_url,
177- # environ)
178- # if u'came_from' in query:
179- # # There's a referrer URL defined, so we have to pass it to
180- # # the post-login page as a GET variable.
181- # destination = self._insert_qs_variable(destination,
182- # u'came_from',
183- # query[u'came_from'])
184- # failed_logins = self._get_logins(environ, True)
185- # new_dest = self._set_logins_in_url(destination, failed_logins)
186-
187- # environ[u'repoze.who.application'] = HTTPFound(location=new_dest)
188- # return credentials
189- # else:
190- # new_dest = 'user/locked'
191- # environ[u'repoze.who.application'] = HTTPFound(location=new_dest)
192- # extra_vars = {}
193- # return extra_vars
194-
195- # elif path_info == self.logout_handler_path:
196- # # We are on the URL where repoze.who logs the user out. #
197- # r = Request(environ)
198- # params = dict(list(r.GET.items()) + list(r.POST.items()))
199- # form = MultiDict(params)
200- # form.update(query)
201- # referer = environ.get(u'HTTP_REFERER', script_name)
202- # came_from = form.get(u'came_from', referer)
203- # # set in environ for self.challenge() to find later
204- # environ[u'came_from'] = came_from
205- # environ[u'repoze.who.application'] = HTTPUnauthorized()
206- # return None
207-
208- # elif path_info == self.login_form_url or self._get_logins(environ):
209- # # We are on the URL that displays the from OR any other page #
210- # # where the login counter is included in the query string. #
211- # # So let's load the counter into the environ and then hide it from
212- # # the query string (it will cause problems in frameworks like TG2,
213- # # where this unexpected variable would be passed to the controller)
214- # environ[u'repoze.who.logins'] = self._get_logins(environ, True)
215- # # Hiding the GET variable in the environ:
216- # if self.login_counter_name in query:
217- # del query[self.login_counter_name]
218- # environ[u'QUERY_STRING'] = urlencode(query, doseq=True)
219122
220123
221124def _get_repoze_handler (handler_name ):
@@ -230,10 +133,7 @@ def custom_login() -> Union[Response, str]:
230133 response = item .login ()
231134 if response :
232135 return response
233-
234- print ("================================" )
235- print ("custom login" )
236- print ("================================" )
136+
237137 extra_vars : dict [str , Any ] = {}
238138
239139 if current_user .is_authenticated :
0 commit comments