コード例 #1
0
 def post(self, request):
     userkey = UserKey(user=request.user)
     userkey.request = request
     form = self.form_class(request.POST, instance=userkey)
     if form.is_valid():
         form.save()
         default_redirect = reverse(settings.USERKEY_LIST_URL)
         url = request.GET.get('next', default_redirect)
         if not is_safe_url(url=url, allowed_hosts=(request.get_host(), )):
             url = default_redirect
         message = 'SSH public key %s was added.' % userkey.name
         messages.success(request, message, fail_silently=True)
         return HttpResponseRedirect(url)
     return render(request,
                   'sshkey/userkey_detail.html',
                   context={
                       'form': form,
                       'action': 'add'
                   })
コード例 #2
0
def userkey_add(request):
    if request.method == 'POST':
        userkey = UserKey(user=request.user)
        userkey.request = request
        form = UserKeyForm(request.POST, instance=userkey)
        if form.is_valid():
            form.save()
            default_redirect = reverse('simplesshkey:userkey_list')
            url = request.GET.get('next', default_redirect)
            if not is_safe_url(url=url, host=request.get_host()):
                url = default_redirect
            message = 'SSH public key %s was added.' % userkey.name
            messages.success(request, message, fail_silently=True)
            return HttpResponseRedirect(url)
    else:
        form = UserKeyForm()
    return render(request,
                  'sshkey/userkey_detail.html',
                  context={
                      'form': form,
                      'action': 'add'
                  })