带有用户身份验证令牌的 Rails webcal 订阅 url;

发布于 2024-12-13 06:55:08 字数 449 浏览 3 评论 0原文

我正在尝试为我的应用程序的用户创建一个链接,用于订阅他们的帐户日历。我有一个在 Rails calendar_publisher_lists_url(:format => :ics, :only_path => false,:protocol => "web cal") 中生成的有效链接 它会生成一个类似 webcal://mywebsite.com/calendar.ics 的链接 但是,这仅在用户登录时才有效。即使用户未登录,我也需要在日历自动更新时使链接正常工作。因此,我需要生成一个如下所示的链接: webcal://[电子邮件受保护]/calendar.ics 其中“123”是用户的身份验证令牌。 我如何生成这个网址?

I am trying to create a link for user of my app to use to subscribe to their account calendars. I have a link that works that I generate in rails calendar_publisher_lists_url(:format => :ics, :only_path => false,:protocol => "web cal")
which generates a link like webcal://mywebsite.com/calendar.ics
However this only works if the user is logged in. I need for the link to work when the calendar is automatically updated, even if the user is not logged in. Thus I need to generate a link that would look like:
webcal://[email protected]/calendar.ics where '123' is the authentication token for the user.
How do I generate this url?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谈场末日恋爱 2024-12-20 06:55:08

将它作为属性放在 URL 上有什么问题吗?

calendar_publisher_lists_url(:format => :ics, :only_path => false,:protocol => "webcal", :authentication_token => current_user.authentication_token)

webcal://mywebsite.com/calendar.ics?authentication_token=123

我的意思是除了安全问题...

What's wrong with putting it onto the URL as attribute?

calendar_publisher_lists_url(:format => :ics, :only_path => false,:protocol => "webcal", :authentication_token => current_user.authentication_token)

webcal://mywebsite.com/calendar.ics?authentication_token=123

I mean apart from the security issue...

深海夜未眠 2024-12-20 06:55:08

如果安全不是问题,您可以更改路由以添加 ID。

match '/calendar/:id/calendar_feed', to: 'calendar#calendar_feed', :as => 'calendar_feed_path'

然后在你的控制器中

def calendar_feed
  @user=User.find(params[:id])
  respond_to do |format|
    format.ics
  end
end

添加一个视图模板,调整以适应你的逻辑需求(此代码来自我的一个项目):

BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//UserCalendar//EN
X-WR-CALNAME:Name Of Website
CALSCALE:GERGORIAN
<% @users.each do |user| %>  #change logic to fit your needs
    <% user.day_offs.each do |day_off| %>
BEGIN:VEVENT
DTSTAMP:<%=Time.now.strftime("%Y%m%dT%H%M%SZ")%>
UID:<%=day_off.id%>
SUMMARY:<%= day_off.user.name.titleize %> | <%= day_off.do_type %>
DTSTART:<%= day_off.start_date.strftime("%Y%m%d") %>
<% end_day=day_off.end_date + 1.day %>
DTEND:<%= end_day.strftime("%Y%m%d") %>
END:VEVENT
<% end %>
<% end %>
END:VCALENDAR

然后提要链接将是

<%= link_to("Subscribe to Calendar", "webcal://www.nameofwebsite.com/calendar_feed/#{current_user.user_id}/calendar_feed.ics" ) %>

If security is not an issue you could change the route to add an id.

match '/calendar/:id/calendar_feed', to: 'calendar#calendar_feed', :as => 'calendar_feed_path'

Then in your controller put

def calendar_feed
  @user=User.find(params[:id])
  respond_to do |format|
    format.ics
  end
end

And then add a view template, adjust to fit your needs with your logic (this code is from one of my projects):

BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//UserCalendar//EN
X-WR-CALNAME:Name Of Website
CALSCALE:GERGORIAN
<% @users.each do |user| %>  #change logic to fit your needs
    <% user.day_offs.each do |day_off| %>
BEGIN:VEVENT
DTSTAMP:<%=Time.now.strftime("%Y%m%dT%H%M%SZ")%>
UID:<%=day_off.id%>
SUMMARY:<%= day_off.user.name.titleize %> | <%= day_off.do_type %>
DTSTART:<%= day_off.start_date.strftime("%Y%m%d") %>
<% end_day=day_off.end_date + 1.day %>
DTEND:<%= end_day.strftime("%Y%m%d") %>
END:VEVENT
<% end %>
<% end %>
END:VCALENDAR

Then the feed link would be

<%= link_to("Subscribe to Calendar", "webcal://www.nameofwebsite.com/calendar_feed/#{current_user.user_id}/calendar_feed.ics" ) %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文