在直接访问未经身份验证的pdf文件时设计身份验证

编程入门 行业动态 更新时间:2024-10-11 21:21:10
本文介绍了在直接访问未经身份验证的pdf文件时设计身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我试图看到一个.pdf文件(用PDFKit生成)未经身份验证时,我直接从一个给定的url host /.../ profile.pdf 。如预期的那样,我被要求输入图像中显示的凭据(不在users / sign_in路径中):

I have a problem when trying to see a .pdf file (generated with PDFKit) unauthenticated, just going directly from a given url host/.../profile.pdf. I, as expected, am asked to enter the credentials as shown in the image (Not in the users/sign_in path):

我输入正确的凭据,该框上下移动,并要求凭证再次。看起来用户或密码错误,但是它们不是。控制器的相关代码在这里:

I enter the correct credentials, the box goes up and down and asks for the credentials again. It could seem like the user or password are wrong, but they aren't. The relevant code from the controller is here:

class Entrepreneur::ProfilesController < ApplicationController before_filter :authenticate_user! def show respond_to do |format| format.pdf do html = render_to_string(:layout => false , :action => "show.html.haml") kit = PDFKit.new(html) send_data(kit.to_pdf, :filename => "name.pdf", :type => 'application/pdf') end end end end

没有什么可想象的,你可以看到。我试图从过滤器( before_filter:authenticate_user !,:except => [:show] )中删除显示操作,并自己写一个自定义过滤器,将未经身份验证的用户重定向到new_session_path,但是这样做,我不知道如何注册,将用户重定向到pdf显示。

Nothing fancy as you can see. I tried to remove the show action from the filter (before_filter :authenticate_user!, :except => [:show]) and write myself a custom filter to redirect unauthenticated users to new_session_path, but doing so I don't know how to, once signed up, redirect the user to the pdf show.

简而言之,设计在访问时要求我的凭据一个pdf显示,不接受他们。我如何将用户注册到sign_in页面并重新定位回到pdf一次签名?

In short, devise asks for my credentials when accessing a pdf show and doesn't accept them. How can I get the user to the sign_in page and redirect back to the pdf once signed?

我使用的是Rails 3.0.7,Ruby 1.8.7和Devise 1.1

I'm using Rails 3.0.7, Ruby 1.8.7 and Devise 1.1.5.

谢谢!

推荐答案

首先,确保实际上,Rails服务于PDF,而不是Web前端的Web服务器。 (根据您的配置,可能是请求从来没有得到Rails。)

First, make sure that it's actually Rails serving the PDF and not a web server in front of it. (Depending on your configuration, it could be the request is never getting to Rails in the first place.)

假设是Rails服务文件,那么你应该检查你的devise.rb配置文件。您可能需要:pdf导航格式,允许Devise发出302重定向到您的sign_in页面:

Assuming it is Rails serving the file, then you should check your devise.rb configuration file. You may need to make :pdf a navigational format which will allow Devise to issue a 302 redirect to your sign_in page:

config.navigational_formats = [ :html,:pdf]#你可能有其他格式

另外,你可能需要添加PDF到你的mime_types.rb初始化器,如果它是还没有:

Also, you may need to add PDF to your mime_types.rb initializer if it's not there already:

Mime :: Type.register'application / pdf',:pdf

更多推荐

在直接访问未经身份验证的pdf文件时设计身份验证

本文发布于:2023-11-28 12:21:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642376.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   文件   pdf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!