admin 管理员组文章数量: 887021
hue
登录
点击sign in按钮调用
http://192.168.1.102:8000/hue/accounts/login
进行登录
Django登录通过文件
hue-release-4.7.1\desktop\core\ext-py\Django-1.11.29\build\lib\django\contrib\auth\views.py
显示登录表单并处理登录操作
def dispatch(self, request, *args, **kwargs):if self.redirect_authenticated_user and self.request.user.is_authenticated:redirect_to = self.get_success_url()if redirect_to == self.request.path:raise ValueError("Redirection loop for authenticated user detected. Check that ""your LOGIN_REDIRECT_URL doesn't point to a login page.")return HttpResponseRedirect(redirect_to)return super(LoginView, self).dispatch(request, *args, **kwargs)
检测到的经过身份验证的用户的重定向循环。检查LOGIN_REDIRECT_URL是否指向登录页面。
如果成功登录
def get_success_url(self):url = self.get_redirect_url()return url or resolve_url(settings.LOGIN_REDIRECT_URL)
如果安全,返回用户源重定向URL。
def get_redirect_url(self):"""Return the user-originating redirect URL if it's safe."""redirect_to = self.request.POST.get(self.redirect_field_name,self.request.GET.get(self.redirect_field_name, ''))url_is_safe = is_safe_url(url=redirect_to,allowed_hosts=self.get_success_url_allowed_hosts(),require_https=self.request.is_secure(),)return redirect_to if url_is_safe else ''
登出
调用
http://192.168.1.102:8000/accounts/logout
调用类LogoutView‘登出用户并显示“您已登出”消息’
def dispatch(self, request, *args, **kwargs):auth_logout(request)next_page = self.get_next_page()if next_page:# Redirect to this page until the session has been cleared.return HttpResponseRedirect(next_page)return super(LogoutView, self).dispatch(request, *args, **kwargs)
当发起登出请求
调用方法logout()方法
def logout(request):"""从请求中删除经过身份验证的用户的ID并刷新其ID会话数据"""# 在用户注销之前发送信号,这样接收者就有机会找出“谁”注销了user = getattr(request, 'user', None)if hasattr(user, 'is_authenticated') and not user.is_authenticated:user = Noneuser_logged_out.send(sender=user.__class__, request=request, user=user)# 记住语言选择保存到会话language = request.session.get(LANGUAGE_SESSION_KEY)request.session.flush()if language is not None:request.session[LANGUAGE_SESSION_KEY] = languageif hasattr(request, 'user'):from django.contrib.auth.models import AnonymousUserrequest.user = AnonymousUser()
重定向到此页面,直到会话被清除
本文标签: Hue
版权声明:本文标题:hue 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1687833168h146990.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论