コード例 #1
0
ファイル: views.py プロジェクト: litterbear/initcloud_web
    def post(self, request):
        form = AuthenticationForm(data=request.POST)

        if not form.is_valid():
            return self.response(request, form)

        user = form.get_user()
        auth_login(request, user)

        # Retrieve user to use some methods of UserProxy
        user = UserProxy.objects.get(pk=user.pk)
        if user.is_superuser or user.is_system_user or user.is_audit_user or user.is_safety_user:
            return redirect('management')

        udc_set = UDC.objects.filter(user=user)

        if udc_set.exists():
            request.session["UDC_ID"] = udc_set[0].id
        elif user.is_approver:
            request.session["UDC_ID"] = -1
        else:
            return redirect('no_udc')

        Notification.pull_announcements(user)

        return HttpResponseRedirect(reverse("cloud"))
コード例 #2
0
    def post(self, request):
        form = AuthenticationForm(data=request.POST)

        if not form.is_valid():
            return self.response(request, form)

        user = form.get_user()
        auth_login(request, user)

        # Retrieve user to use some methods of UserProxy
        user = UserProxy.objects.get(pk=user.pk)
        if user.is_superuser or user.is_system_user or user.is_audit_user or user.is_safety_user:
            return redirect('management')

        udc_set = UDC.objects.filter(user=user)

        if udc_set.exists():
            request.session["UDC_ID"] = udc_set[0].id
        elif user.is_approver:
            request.session["UDC_ID"] = -1
        else:
            return redirect('no_udc')

        Notification.pull_announcements(user)

        return HttpResponseRedirect(reverse("cld"))
コード例 #3
0
ファイル: views.py プロジェクト: hpplinux/initcloud_web
def feed_status(request):
    Notification.pull_announcements(request.user)
    num = Feed.living.filter(receiver=request.user, is_read=False).count()
    return Response({"num": num})
コード例 #4
0
def feed_status(request):
    Notification.pull_announcements(request.user)
    num = Feed.living.filter(receiver=request.user, is_read=False).count()
    return Response({"num": num})
コード例 #5
0
    def post(self, request):
        form = AuthenticationForm(data=request.POST)

        login_type = request.POST.get('type') or None
        if not form.is_valid():
            return self.response(request, form)

        user = form.get_user()
        auth_login(request, user)

        # Retrieve user to use some methods of UserProxy
        user = UserProxy.objects.get(pk=user.pk)
        role = ""
        if not user.is_superuser:
            udc_id = 0
            udc_set = UDC.objects.filter(user=user)

            if udc_set.exists():
                request.session["UDC_ID"] = udc_set[0].id
                udc_id = udc_set[0].id
            elif user.is_approver:
                request.session["UDC_ID"] = -1
            else:
                return redirect('no_udc')
            role = user_role_member(request, udc_id)
        if user.is_superuser or role:
            #add session["UDC_ID"] for surperuser

            if UDC.objects.filter(user=user).exists():
                udc_set = UDC.objects.filter(user=user)
                request.session["UDC_ID"] = udc_set[0].id
            try:
                Operation.objects.create(user=user,
                                         udc=udc_set[0],
                                         resource="登录",
                                         resource_id=1,
                                         resource_name="登录",
                                         action="login",
                                         result=0)
            except Exception as e:
                pass
            return redirect('management')

        elif login_type == "vdi_client":

            return HttpResponseRedirect(reverse("cloud"))
        else:
            try:
                Operation.objects.create(user=user,
                                         udc='-1',
                                         resource="普通用户登录web",
                                         resource_id=1,
                                         resource_name="登录",
                                         action="login",
                                         result=0)
            except Exception as e:
                pass
            auth_logout(request)
            return HttpResponseForbidden()

        udc_set = UDC.objects.filter(user=user)

        if udc_set.exists():
            request.session["UDC_ID"] = udc_set[0].id
        elif user.is_approver:
            request.session["UDC_ID"] = -1
        else:
            return redirect('no_udc')

        Notification.pull_announcements(user)

        return HttpResponseRedirect(reverse("cloud"))