Create "invalid token" page for EmailSubscriptionController (#218)
* Update email-unsubscription expiration to 31 days * Create invalid_token template * Fix lint
This commit is contained in:
parent
c185ff28d5
commit
02ab21726d
7 changed files with 30 additions and 14 deletions
|
|
@ -11,6 +11,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
.unsubscribed--red {
|
||||
background: #ea919a;
|
||||
}
|
||||
|
||||
.unsubscribed__title {
|
||||
font-weight: 600;
|
||||
font-size: 26px;
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
class AdditionalContentBoxesController < ApplicationController
|
||||
|
||||
def index
|
||||
articles_ids = params[:article_id].split(",")
|
||||
@article = Article.find(articles_ids[0])
|
||||
@for_user_article = ClassicArticle.
|
||||
new(current_user || @article, {not_ids: articles_ids}).get
|
||||
new(current_user || @article, not_ids: articles_ids).get
|
||||
if (!user_signed_in? || current_user&.display_sponsors) &&
|
||||
@article.user.permit_adjacent_sponsors &&
|
||||
@article.user.permit_adjacent_sponsors &&
|
||||
rand(2) == 1
|
||||
@boosted_article = BoostedArticle.
|
||||
new(current_user, @article, {not_ids: (articles_ids+[@for_user_article])}).get
|
||||
new(current_user, @article, not_ids: (articles_ids + [@for_user_article])).get
|
||||
end
|
||||
unless @boosted_article
|
||||
@alt_classic = ClassicArticle.
|
||||
new(@article, not_ids: (articles_ids + [@for_user_article])).get
|
||||
end
|
||||
@alt_classic = ClassicArticle.
|
||||
new(@article, {not_ids: (articles_ids+[@for_user_article])}).get unless @boosted_article
|
||||
render "boxes", layout: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class EmailSubscriptionsController < ApplicationController
|
|||
user.update(verified_params[:email_type] => false)
|
||||
@email_type = preferred_email_name(verified_params[:email_type])
|
||||
else
|
||||
not_found
|
||||
render "invalid_token"
|
||||
end
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
not_found
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class BoostedArticle
|
||||
|
||||
attr_accessor :user, :article, :tags, :not_ids
|
||||
def initialize(user, article, options)
|
||||
@user = user
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class ApplicationMailer < ActionMailer::Base
|
|||
Rails.application.message_verifier(:unsubscribe).generate(
|
||||
user_id: id,
|
||||
email_type: email_type.to_sym,
|
||||
expires_at: Time.now + 2.days,
|
||||
expires_at: Time.now + 31.days,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
12
app/views/email_subscriptions/invalid_token.html.erb
Normal file
12
app/views/email_subscriptions/invalid_token.html.erb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<meta name="robots" content="noindex" />
|
||||
<div class="unsubscribed unsubscribed--red">
|
||||
<div class="unsubscribed__title">
|
||||
Token expired or invalid
|
||||
</div>
|
||||
<br/>
|
||||
<div class="unsubscribed__message">
|
||||
Please
|
||||
<a href="https://dev.to/settings/notifications">sign-in</a>
|
||||
to manage your email preferences.
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -7,7 +7,7 @@ RSpec.describe "EmailSubscriptions", type: :request do
|
|||
Rails.application.message_verifier(:unsubscribe).generate(
|
||||
user_id: user_id,
|
||||
email_type: :email_mention_notifications,
|
||||
expires_at: Time.now + 2.days,
|
||||
expires_at: Time.now + 31.days,
|
||||
)
|
||||
end
|
||||
|
||||
|
|
@ -30,9 +30,9 @@ RSpec.describe "EmailSubscriptions", type: :request do
|
|||
|
||||
it "won't work if it's past expireation date" do
|
||||
token = generate_token(user.id)
|
||||
Timecop.freeze(Date.today + 3) do
|
||||
expect { get email_subscriptions_unsubscribe_url(ut: token) }.
|
||||
to raise_error(ActionController::RoutingError)
|
||||
Timecop.freeze(Date.today + 32) do
|
||||
get email_subscriptions_unsubscribe_url(ut: token)
|
||||
expect(response).to render_template("invalid_token")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue