def wrapper(request, *args, **kwargs): if request.user.is_authenticated: return func(request, *args, **kwargs) else: if request.is_ajax(): return Response.unauth(message="请先登录") else: return redirect('news:index')
def login_view(request): form = LoginForm(request.POST) if form.is_valid(): telephone = form.cleaned_data.get('telephone') password = form.cleaned_data.get('password') remember = form.cleaned_data.get('remember') user = authenticate(request, username=telephone, password=password) if user: if user.is_active: login(request, user) if remember: request.session.set_expiry(None) else: request.session.set_expiry(0) return Response.response() else: return Response.unauth(message="账号被冻结!") else: return Response.params_error(message='手机或者密码错误') else: errors = form.get_errors() return Response.params_error(message=errors)