Merge branch 'develop' of bitbucket.org:jamkazam/jam-cloud into develop

This commit is contained in:
Seth Call 2015-04-13 09:57:24 -05:00
commit fb3ca2cec1
8 changed files with 57 additions and 3 deletions

View File

@ -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>.&nbsp;&nbsp;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>.&nbsp;&nbsp;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>

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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