示例#1
0
文件: views.py 项目: fp7-alien/C-BAS
def user_cert_generate(request, user_id):
    """Create a new user certificate after confirmation.
    
    @param request: the request object
    @param user_id: the id of the user whose certificate we are generating.
    """
    
    user = get_object_or_404(User, pk=user_id)
    
    must_have_permission(request.user, user, "can_change_user_cert")
    
    cert_fname = get_user_cert_fname(user)
    key_fname = get_user_key_fname(user)
    urn = get_user_urn(user.username)

    if request.method == "POST":
        create_x509_cert(urn, cert_fname, key_fname)
        DatedMessage.objects.post_message_to_user(
            "GCF Certificate for user %s successfully created." % user.username,
            user=request.user, msg_type=DatedMessage.TYPE_SUCCESS)
        return HttpResponseRedirect(reverse(user_cert_manage, args=[user.id]))
    
    return simple.direct_to_template(
        request,
        template="user_cert_generate.html",
        extra_context={
            "curr_user": user,
        },
    )
示例#2
0
文件: views.py 项目: cargious/ocf
def user_cert_manage(request, user_id):
    """Allow the user to download/regenerate/upload a GCF certificate.
    
    @param request: the request object
    @param user_id: the id of the user whose certificate we are managing.
    """

    user = get_object_or_404(User, pk=user_id)

    must_have_permission(request.user, user, "can_change_user_cert")

    cert_fname = get_user_cert_fname(user)
    if not os.access(cert_fname, os.F_OK):
        cert = None

    else:
        cert = read_cert_from_file(cert_fname)

    return simple.direct_to_template(
        request,
        template=TEMPLATE_PATH + "/user_cert_manage.html",
        extra_context={
            "curr_user": user,
            "cert": cert,
        },
    )
示例#3
0
文件: views.py 项目: cargious/ocf
def user_cert_generate(request, user_id):
    """Create a new user certificate after confirmation.
    
    @param request: the request object
    @param user_id: the id of the user whose certificate we are generating.
    """

    user = get_object_or_404(User, pk=user_id)

    must_have_permission(request.user, user, "can_change_user_cert")

    cert_fname = get_user_cert_fname(user)
    key_fname = get_user_key_fname(user)
    urn = get_user_urn(user.username)

    if request.method == "POST":
        create_x509_cert(urn, cert_fname, key_fname)
        DatedMessage.objects.post_message_to_user(
            "GCF Certificate for user %s successfully created." %
            user.username,
            user=request.user,
            msg_type=DatedMessage.TYPE_SUCCESS)
        return HttpResponseRedirect(reverse(user_cert_manage, args=[user.id]))

    return simple.direct_to_template(
        request,
        template=TEMPLATE_PATH + "/user_cert_generate.html",
        extra_context={
            "curr_user": user,
        },
    )
示例#4
0
文件: views.py 项目: fp7-alien/C-BAS
def user_cert_manage(request, user_id):
    """Allow the user to download/regenerate/upload a GCF certificate.
    
    @param request: the request object
    @param user_id: the id of the user whose certificate we are managing.
    """
    
    user = get_object_or_404(User, pk=user_id)
    
    must_have_permission(request.user, user, "can_change_user_cert")
    
    cert_fname = get_user_cert_fname(user)
    if not os.access(cert_fname, os.F_OK):
        cert = None
        
    else:
        cert = read_cert_from_file(cert_fname)
    
    return simple.direct_to_template(
        request,
        template="user_cert_manage.html",
        extra_context={
            "curr_user": user,
            "cert": cert,
        },
    )
示例#5
0
文件: tests.py 项目: fp7-alien/C-BAS
 def setUp(self):
     self.u = User.objects.create_user(
         "test_user", "*****@*****.**", "password")
     
     self.cert_fname = get_user_cert_fname(self.u)
     self.key_fname = get_user_key_fname(self.u)
     
     try_unlink(self.cert_fname)
     try_unlink(self.key_fname)
示例#6
0
文件: tests.py 项目: cargious/ocf
    def setUp(self):
        self.u = User.objects.create_user("test_user", "*****@*****.**",
                                          "password")

        self.cert_fname = get_user_cert_fname(self.u)
        self.key_fname = get_user_key_fname(self.u)

        try_unlink(self.cert_fname)
        try_unlink(self.key_fname)
示例#7
0
文件: forms.py 项目: cargious/ocf
    def save(self, user):
        """Write the key and cert into files.
        
        @param user: the user to save the cert and key for.
        @type user: C{django.contrib.auth.models.User}
        """

        key_fname = get_user_key_fname(user)
        cert_fname = get_user_cert_fname(user)

        self.key.save_to_file(key_fname)
        self.cert.save_to_file(cert_fname)
示例#8
0
文件: forms.py 项目: fp7-alien/C-BAS
 def save(self, user):
     """Write the key and cert into files.
     
     @param user: the user to save the cert and key for.
     @type user: C{django.contrib.auth.models.User}
     """
     
     key_fname = get_user_key_fname(user)
     cert_fname = get_user_cert_fname(user)
     
     self.key.save_to_file(key_fname)
     self.cert.save_to_file(cert_fname)
示例#9
0
文件: views.py 项目: cargious/ocf
def user_cert_download(request, user_id):
    """Download a GCF certificate."""

    user = get_object_or_404(User, pk=user_id)

    must_have_permission(request.user, user, "can_download_certs")

    cert_fname = get_user_cert_fname(user)

    response = HttpResponse(open(cert_fname, 'r').read(),
                            mimetype='application/force-download')
    response['Content-Disposition'] = 'attachment; filename=%s' % cert_fname
    return response
示例#10
0
文件: views.py 项目: fp7-alien/C-BAS
def user_cert_download(request, user_id):
    """Download a GCF certificate."""
    
    user = get_object_or_404(User, pk=user_id)
    
    must_have_permission(request.user, user, "can_download_certs")
    
    cert_fname = get_user_cert_fname(user)
    
    response = HttpResponse(open(cert_fname,'r').read(),
                            mimetype='application/force-download')
    response['Content-Disposition'] = 'attachment; filename=%s' % cert_fname
    return response
示例#11
0
文件: models.py 项目: fp7-alien/C-BAS
 def get_user_client(self, user):
     """Get a client to talk to the aggregate as the user."""
     return self._get_client(
         get_user_cert_fname(user), get_user_key_fname(user))
示例#12
0
文件: models.py 项目: cargious/ocf
 def get_user_client(self, user):
     """Get a client to talk to the aggregate as the user."""
     return self._get_client(get_user_cert_fname(user),
                             get_user_key_fname(user))