Merge branch 'develop' of bitbucket.org:jamkazam/jam-cloud into develop
This commit is contained in:
commit
fb3ca2cec1
|
|
@ -39,7 +39,7 @@
|
|||
<td align="left">
|
||||
|
||||
<!-- CALL OUT BOX -->
|
||||
<p style="margin-top:0px"><font size="2" color="#7FACBA" face="Arial, Helvetica, sans-serif">This email was sent to you because you have an account at <a style="color: #ffcc00;" href="http://www.jamkazam.com">JamKazam</a>. Click <a style="color: #ffcc00;" href="http://www.jamkazam.com/client#/account/profile">here to unsubscribe</a> and update your profile settings.
|
||||
<p style="margin-top:0px"><font size="2" color="#7FACBA" face="Arial, Helvetica, sans-serif">This email was sent to you because you have an account at <a style="color: #ffcc00;" href="http://www.jamkazam.com">JamKazam</a>. Click <a style="color: #ffcc00;" href="http://www.jamkazam.com/unsubscribe/#{@user.unsubscribe_token}">here to unsubscribe</a> and update your profile settings.
|
||||
</font></p>
|
||||
</td></tr></table>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<% end %>
|
||||
|
||||
<% unless @suppress_user_has_account_footer == true %>
|
||||
This email was sent to you because you have an account at JamKazam / http://www.jamkazam.com. Visit your profile page to unsubscribe: http://www.jamkazam.com/client#/account/profile.
|
||||
This email was sent to you because you have an account at JamKazam / http://www.jamkazam.com. Visit your profile page to unsubscribe: http://www.jamkazam.com/unsubscribe/<%=@user.unsubscribe_token%>.
|
||||
<% end %>
|
||||
|
||||
Copyright <%= Time.now.year %> JamKazam, Inc. All rights reserved.
|
||||
|
|
|
|||
|
|
@ -1537,6 +1537,28 @@ module JamRuby
|
|||
ShoppingCart.where("user_id=?", self).destroy_all
|
||||
end
|
||||
|
||||
def unsubscribe_token
|
||||
self.class.create_access_token(self)
|
||||
end
|
||||
|
||||
# Verifier based on our application secret
|
||||
def self.verifier
|
||||
ActiveSupport::MessageVerifier.new(APP_CONFIG.secret_token)
|
||||
end
|
||||
|
||||
# Get a user from a token
|
||||
def self.read_access_token(signature)
|
||||
uid = self.verifier.verify(signature)
|
||||
User.find_by_id uid
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
nil
|
||||
end
|
||||
|
||||
# Class method for token generation
|
||||
def self.create_access_token(user)
|
||||
verifier.generate(user.id)
|
||||
end
|
||||
|
||||
private
|
||||
def create_remember_token
|
||||
self.remember_token = SecureRandom.urlsafe_base64
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ describe UserMailer do
|
|||
let(:user) { FactoryGirl.create(:user) }
|
||||
|
||||
before(:each) do
|
||||
stub_const("APP_CONFIG", app_config)
|
||||
UserMailer.deliveries.clear
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,10 @@ def app_config
|
|||
true
|
||||
end
|
||||
|
||||
def secret_token
|
||||
'foobar'
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
|
@ -248,4 +252,4 @@ end
|
|||
def friend(user1, user2)
|
||||
FactoryGirl.create(:friendship, user: user1, friend: user2)
|
||||
FactoryGirl.create(:friendship, user: user2, friend: user1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -413,6 +413,19 @@ JS
|
|||
end
|
||||
end
|
||||
|
||||
def unsubscribe
|
||||
unless @user = User.read_access_token(params[:user_token])
|
||||
redirect_to '/'
|
||||
end if params[:user_token].present?
|
||||
|
||||
if request.get?
|
||||
|
||||
elsif request.post?
|
||||
@user.subscribe_email = false
|
||||
@user.save!
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def is_native_client
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
= provide(:title, 'Unsubscribe')
|
||||
|
||||
- if request.get?
|
||||
%h2 Unsubscribe from all JamKazam email for address #{@user} ?
|
||||
%br
|
||||
= form_tag("") do
|
||||
= submit_tag('Unsubscribe')
|
||||
= hidden_field_tag(:user_token, params[:user_token])
|
||||
- elsif request.post?
|
||||
- if @user && ! @user.subscribe_email
|
||||
%h2 You have been unsubscribed.
|
||||
|
||||
|
|
@ -79,6 +79,8 @@ SampleApp::Application.routes.draw do
|
|||
match '/reset_password_token' => 'users#reset_password_token', :via => :get
|
||||
match '/reset_password_complete' => 'users#reset_password_complete', :via => :post
|
||||
|
||||
match '/unsubscribe/:user_token' => 'users#unsubscribe', via: [:get, :post]
|
||||
|
||||
# email update
|
||||
match '/confirm_email' => 'users#finalize_update_email', :as => 'confirm_email' # NOTE: if you change this, you break outstanding email changes because links in user inboxes are broken
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue