本文整理汇总了Python中django.conf.settings.LOGIN_URL属性的典型用法代码示例。如果您正苦于以下问题:Python settings.LOGIN_URL属性的具体用法?Python settings.LOGIN_URL怎么用?Python settings.LOGIN_URL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.conf.settings
的用法示例。
在下文中一共展示了settings.LOGIN_URL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_passes_test
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def user_passes_test(test_func: Callable[[HttpResponse], bool], login_url: Optional[str]=None,
redirect_field_name: str=REDIRECT_FIELD_NAME) -> Callable[[ViewFuncT], ViewFuncT]:
"""
Decorator for views that checks that the user passes the given test,
redirecting to the log-in page if necessary. The test should be a callable
that takes the user object and returns True if the user passes.
"""
def decorator(view_func: ViewFuncT) -> ViewFuncT:
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse:
if test_func(request):
return view_func(request, *args, **kwargs)
path = request.build_absolute_uri()
resolved_login_url = resolve_url(login_url or settings.LOGIN_URL)
# If the login url is the same scheme and net location then just
# use the path as the "next" url.
login_scheme, login_netloc = urllib.parse.urlparse(resolved_login_url)[:2]
current_scheme, current_netloc = urllib.parse.urlparse(path)[:2]
if ((not login_scheme or login_scheme == current_scheme) and
(not login_netloc or login_netloc == current_netloc)):
path = request.get_full_path()
return redirect_to_login(
path, resolved_login_url, redirect_field_name)
return cast(ViewFuncT, _wrapped_view) # https://github.com/python/mypy/issues/1927
return decorator
示例2: login_required
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def login_required(login_url=None):
"""
Decorator for views that checks that the user is authenticated, redirecting
to login_url page if necessary.
"""
def decorator(view_func):
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
is_login, username, is_staff = is_authenticated(request)
if is_login:
kwargs['username'] = username
kwargs['is_staff'] = is_staff
return view_func(request, *args, **kwargs)
resolved_login_url = (login_url or settings.LOGIN_URL)
return HttpResponseRedirect(resolved_login_url)
return _wrapped_view
return decorator
示例3: media
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def media(request):
"""
Add context things that we need
"""
# A/B testing: half of instructors and TAs see a different search box
instr_ta = is_instr_ta(request.user.username)
instr_ta_ab = instr_ta and request.user.is_authenticated and request.user.id % 2 == 0
# GRAD_DATE(TIME?)_FORMAT for the grad/ra/ta apps
return {'GRAD_DATE_FORMAT': settings.GRAD_DATE_FORMAT,
'GRAD_DATETIME_FORMAT': settings.GRAD_DATETIME_FORMAT,
'LOGOUT_URL': settings.LOGOUT_URL,
'LOGIN_URL': settings.LOGIN_URL,
'STATIC_URL': settings.STATIC_URL,
'is_instr_ta': instr_ta,
'instr_ta_ab': instr_ta_ab,
'request_path': request.path,
'CourSys': product_name(request),
'help_email': help_email(request),
}
示例4: redirect_to_login
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def redirect_to_login(next, login_url=None,
redirect_field_name=REDIRECT_FIELD_NAME):
"""
Redirects the user to the login page, passing the given 'next' page
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urlunparse(login_url_parts))
# 4 views for password reset:
# - password_reset sends the mail
# - password_reset_done shows a success message for the above
# - password_reset_confirm checks the link the user clicked and
# prompts for a new password
# - password_reset_complete shows a success message for the above
示例5: is_owner
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def is_owner(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
# assume username is first arg
if request.user.is_authenticated():
if request.user.username == kwargs['username']:
return view_func(request, *args, **kwargs)
protocol = "https" if request.is_secure() else "http"
return HttpResponseRedirect("%s://%s" % (protocol,
request.get_host()))
path = request.build_absolute_uri()
login_url = request.build_absolute_uri(settings.LOGIN_URL)
# If the login url is the same scheme and net location then just
# use the path as the "next" url.
login_scheme, login_netloc = urlparse.urlparse(login_url)[:2]
current_scheme, current_netloc = urlparse.urlparse(path)[:2]
if ((not login_scheme or login_scheme == current_scheme) and
(not login_netloc or login_netloc == current_netloc)):
path = request.get_full_path()
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(path, None, REDIRECT_FIELD_NAME)
return _wrapped_view
示例6: redirect_to_login
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
"""
Redirect the user to the login page, passing the given 'next' page.
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urlunparse(login_url_parts))
# 4 views for password reset:
# - password_reset sends the mail
# - password_reset_done shows a success message for the above
# - password_reset_confirm checks the link the user clicked and
# prompts for a new password
# - password_reset_complete shows a success message for the above
示例7: password_reset_complete
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def password_reset_complete(request,
template_name='registration/password_reset_complete.html',
extra_context=None):
warnings.warn("The password_reset_complete() view is superseded by the "
"class-based PasswordResetCompleteView().",
RemovedInDjango21Warning, stacklevel=2)
context = {
'login_url': resolve_url(settings.LOGIN_URL),
'title': _('Password reset complete'),
}
if extra_context is not None:
context.update(extra_context)
return TemplateResponse(request, template_name, context)
# Class-based password reset views
# - PasswordResetView sends the mail
# - PasswordResetDoneView shows a success message for the above
# - PasswordResetConfirmView checks the link the user clicked and
# prompts for a new password
# - PasswordResetCompleteView shows a success message for the above
示例8: redirect_to_login
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def redirect_to_login(next: str, login_url: Optional[str]=None,
redirect_field_name: str=REDIRECT_FIELD_NAME) -> HttpResponseRedirect:
"""
Redirects the user to the login page, passing the given 'next' page
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urllib.parse.urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
# Don't add ?next=/, to keep our URLs clean
if next != '/':
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urllib.parse.urlunparse(login_url_parts))
# From Django 1.8
示例9: test_copy_sheet_requires_login_for_anonymous_user
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def test_copy_sheet_requires_login_for_anonymous_user(self):
self.sheet.is_public = True
worksheet = Worksheet()
worksheet.a1.value = 'some-cell-content'
self.sheet.jsonify_worksheet(worksheet)
self.sheet.save()
self.request.user = AnonymousUser()
self.request.META['SERVER_NAME'] = 'servername'
self.request.META['SERVER_PORT'] = '80'
self.request.get_full_path = lambda: 'request-path'
response = copy_sheet(self.request, self.user.username, self.sheet.id)
self.assertTrue(isinstance(response, HttpResponseRedirect))
redirect_url = urlparse(response['Location'])
self.assertEquals(redirect_url.path, settings.LOGIN_URL)
redirect_query_params = parse_qs(redirect_url.query)
self.assertEquals(redirect_query_params['next'], ['request-path'])
示例10: redirect_to_login
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
"""
Redirect the user to the login page, passing the given 'next' page.
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urlunparse(login_url_parts))
# Class-based password reset views
# - PasswordResetView sends the mail
# - PasswordResetDoneView shows a success message for the above
# - PasswordResetConfirmView checks the link the user clicked and
# prompts for a new password
# - PasswordResetCompleteView shows a success message for the above
示例11: test_restrict_apps
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def test_restrict_apps(self):
"""
Should restrict the URLs
"""
url_names = [
'spirit:topic:index-active',
'spirit:topic:private:index',
'spirit:category:index']
for url_name in url_names:
url = reverse(url_name)
req = RequestFactory().get(url)
req.user = AnonymousUser()
resp = middleware.PrivateForumMiddleware().process_request(req)
self.assertIsInstance(resp, HttpResponseRedirect)
self.assertEqual(
resp['Location'],
reverse(settings.LOGIN_URL) + '?next=' + url)
示例12: whoami
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def whoami(request):
if settings.HOOVER_AUTHPROXY:
logout_url = '/__auth/logout'
else:
logout_url = reverse('logout') + '?next=/'
urls = {
'login': settings.LOGIN_URL,
'admin': reverse('admin:index'),
'logout': logout_url,
'hypothesis_embed': settings.HOOVER_HYPOTHESIS_EMBED,
}
try:
password_change = reverse('password_change')
except NoReverseMatch:
pass
else:
urls['password_change'] = password_change
return JsonResponse({
'username': request.user.username,
'admin': request.user.is_superuser,
'urls': urls,
'title': settings.HOOVER_TITLE,
})
示例13: process_request
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def process_request(self, request):
WHITELIST = [
r'^/accounts/',
r'^/invitation/',
r'^/static/',
r'^/_ping$',
r'^/_is_staff$',
]
for pattern in WHITELIST:
if re.match(pattern, request.path):
return
user = request.user
if user.is_verified():
return
resolved_login_url = resolve_url(settings.LOGIN_URL)
return redirect_to_login(request.path, resolved_login_url, 'next')
示例14: process_view
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def process_view(self, request, view_func, view_args, view_kwargs):
""" Forwards unauthenticated requests to the admin page to the CAS
login URL, as well as calls to django.contrib.auth.views.login and
logout.
"""
if view_func == login:
return cas_login(request, *view_args, **view_kwargs)
if view_func == logout:
return cas_logout(request, *view_args, **view_kwargs)
# The rest of this method amends the Django admin authorization wich
# will post a username/password dialog to authenticate to django admin.
if not view_func.__module__.startswith('django.contrib.admin.'):
return None
if request.user.is_authenticated():
if request.user.is_staff:
return None
else:
raise PermissionDenied("No staff priviliges")
params = urlencode({auth.REDIRECT_FIELD_NAME: request.get_full_path()})
return HttpResponseRedirect(settings.LOGIN_URL + '?' + params)
示例15: test_authentication
# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOGIN_URL [as 别名]
def test_authentication(self, course_id):
"""
Users must be logged in to view the page.
"""
if self.api_method:
with patch(self.api_method, return_value=self.get_mock_data(course_id)):
# Authenticated users should go to the course page
self.login()
response = self.client.get(self.path(course_id=course_id), follow=self.follow)
self.assertEqual(response.status_code, self.success_status)
# Unauthenticated users should be redirected to the login page
self.client.logout()
response = self.client.get(self.path(course_id=course_id))
self.assertRedirectsNoFollow(response, settings.LOGIN_URL, next=self.path(course_id=course_id))