tkh_mailing_list 0.11.3 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef53330b934a0733e06b8093b36dba90c46d7ff7
4
- data.tar.gz: ddcd7052a086932aff05fcdebcf7651f70a60bbf
3
+ metadata.gz: 1a5c287dae7e5a27792104c192cfaf5f893bd742
4
+ data.tar.gz: e3b0ff2b3661e22329b04f033b80f34715d264cf
5
5
  SHA512:
6
- metadata.gz: 86120c651d4089f0a9d0eb9192915d3769b9518b523c3a169f32fdf7a633a96e25a86a9098d9b9291e0e1b7a21245662f74c943be3f8c888879a55b10b23d980
7
- data.tar.gz: 472534e3ed7f315b7c330fe18d7472b30d09cd5b27a0fb2423a12521ce7f653e2c5568a5156a7a8e565ee16c09682fcd714cbe242179bd2122b5cbc00a5307fe
6
+ metadata.gz: 8560d4a060fd027ed48ff898448acc14cdb1a10d26ebcf6b308439b68af4ccd07ca2c1f822a1f77dd1694fc472d56d044d9932959c06863b9d8b8d5a669e247c
7
+ data.tar.gz: a555fdd7856ca06fa3cb63e20b639ff644dad84dd26af325d1755a3cfde401eb9ca5675ac6af04952978cd52b85f13c652070ec302e33044ca697a92b54f1f21
@@ -2,6 +2,13 @@
2
2
 
3
3
 
4
4
 
5
+ ## 0.12
6
+
7
+ * Implemented the newsletter signup routine outside the login process.
8
+ * Added yesterday's activity feed items to the admin daily digest.
9
+ * Added glyphicons to the members index view and paginate to only 30 records
10
+
11
+
5
12
  ## 0.11.3
6
13
 
7
14
  * Fixed the spam detection hidden honeypot measure. It was never working :-(
@@ -6,7 +6,7 @@ class MembersController < ApplicationController
6
6
  before_action :set_member, only: [ :show, :edit, :update, :destroy ]
7
7
 
8
8
  def index
9
- @members = Member.by_recent.paginate(:page => params[:page], :per_page => 50)
9
+ @members = Member.by_recent.paginate(:page => params[:page], :per_page => 30)
10
10
  switch_to_admin_layout
11
11
  end
12
12
 
@@ -0,0 +1,38 @@
1
+ class SignupsController < ApplicationController
2
+
3
+ def email_verification
4
+ unless params[:user][:email].blank?
5
+ @user = User.find_or_initialize_by(email: params[:user][:email])
6
+ set_email_validation_token
7
+ @user.allow_newsletter = true
8
+ @user.allow_daily_digests = true
9
+ @user.save ? @validation_ready=true : @validation_ready=false
10
+ SignupMailer.verification_email(@user).deliver
11
+ Activity.create doer_id: @user.id, message: "signed up for the newsletter. Email: #{@user.email}"
12
+ else
13
+ redirect_to root_path, alert: 'Your email cannot be blank. Please enter your email address and try again'
14
+ end
15
+ end
16
+
17
+ def email_confirmation
18
+ @user = User.where(email_validation_token: params[:token]).first
19
+ if @user && @user.email_validation_token_sent_at >= Time.zone.now - 1.hour
20
+ @user.email_validated = true
21
+ @user.save
22
+ @email_confirmed = true
23
+ elsif @user && @user.email_validation_token_sent_at <= Time.zone.now - 1.hour
24
+ redirect_to root_url, alert: "Your verification token was created over an hour ago. Please restart the process."
25
+ else
26
+ @email_confirmed = false
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def set_email_validation_token
33
+ @user.generate_token(:email_validation_token)
34
+ @user.email_validation_token_sent_at = Time.zone.now
35
+ @user.save
36
+ end
37
+
38
+ end
@@ -3,10 +3,12 @@ class AdministrationMailer < ActionMailer::Base
3
3
 
4
4
  default :from => "#{Setting.first.try(:company_name)} <#{Setting.first.try(:contact_email)}>"
5
5
 
6
- def daily_digest( admin_user, yesterdays_contact_messages, pending_comments )
6
+ # this job is called by the Administration model in this gem
7
+ def daily_digest( admin_user, yesterdays_contact_messages, pending_comments, yesterdays_activities )
7
8
  @recipient = admin_user
8
9
  @contact_messages = yesterdays_contact_messages
9
10
  @pending_comments = pending_comments
11
+ @yesterdays_activities = yesterdays_activities
10
12
  # FIXME - only the email addresses show up. not the names :-(
11
13
  recipient = "#{@recipient.name} <#{@recipient.email}>"
12
14
  reply_to = "#{Setting.first.try(:company_name)} <#{Setting.first.try(:contact_email)}>"
@@ -0,0 +1,8 @@
1
+ class SignupMailer < ActionMailer::Base
2
+ default from: "#{Setting.first.try(:site_name)} <#{Setting.first.contact_email}>"
3
+
4
+ def verification_email(user)
5
+ @user = user
6
+ mail to: @user.email, subject: "Email address validation"
7
+ end
8
+ end
@@ -1,10 +1,12 @@
1
1
  class Administration < ActiveRecord::Base
2
2
 
3
+ # this method is triggered by a rake task in this gem
3
4
  def self.send_daily_digest
4
5
  digest_is_needed = false
5
6
  @yesterdays_contact_messages = Contact.yesterdays.chronologically
6
7
  @pending_comments = Comment.pending.by_created
7
- digest_is_needed = true if @yesterdays_contact_messages.count > 0 || @pending_comments.count > 0
8
+ @yesterdays_activities = Activity.yesterdays.chronologically
9
+ digest_is_needed = true if @yesterdays_contact_messages.count > 0 || @pending_comments.count > 0 || @yesterdays_activities.count > 0
8
10
  if digest_is_needed
9
11
  User.administrators.each do |administrator|
10
12
  send_message_to_admin(administrator)
@@ -17,7 +19,7 @@ class Administration < ActiveRecord::Base
17
19
  def self.send_message_to_admin(recipient)
18
20
  # Actually send the email to the administrator
19
21
  begin
20
- AdministrationMailer.daily_digest( recipient, @yesterdays_contact_messages, @pending_comments ).deliver_now
22
+ AdministrationMailer.daily_digest( recipient, @yesterdays_contact_messages, @pending_comments, @yesterdays_activities ).deliver_now
21
23
  return 'success'
22
24
  rescue Exception => e
23
25
  AdminMailer.rescued_exceptions(e, "Some exception occurred while trying to send to site admin the daily digest.").deliver
@@ -5,6 +5,7 @@ class Contact < ActiveRecord::Base
5
5
  # validates :sender_email, :presence => true, :format => { :with => /\A([\A@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :on => :create }
6
6
  validates_presence_of :body
7
7
 
8
+ # tkh_mailing_list sends daily digest with yesterday's contacts
8
9
  scope :yesterdays, lambda { where('created_at >= ? AND created_at <= ?', 1.day.ago.beginning_of_day, 1.day.ago.end_of_day ) }
9
10
  scope :chronologically, -> { order('created_at') }
10
11
  scope :by_recent, -> { order('created_at desc') }
@@ -22,4 +22,20 @@
22
22
  <p>You can see and manage these messages at: <%= link_to 'contact messages', contacts_url %>.</p>
23
23
  <% end %>
24
24
 
25
+ <% unless @yesterdays_activities.blank? %>
26
+ <h2>Activity feed:</h2>
27
+ <ul>
28
+ <% @yesterdays_activities.each do |activity| %>
29
+ <li>
30
+ <% unless activity.doer.blank? %>
31
+ <%= "#{ link_to activity.doer.spiritual_name, member_url(id: activity.doer.id) } #{activity.message}".html_safe %>
32
+ <% else # user has been deleted %>
33
+ <%= "now deleted user #{activity.message}".html_safe %>
34
+ <% end %>
35
+ </li>
36
+ <% end %>
37
+ </ul>
38
+ <p>You can view <%= link_to 'the whole activity feed', activities_url %>.</p>
39
+ <% end %>
40
+
25
41
  <p>You are receiving this email because you are an administrator of the <%= Setting.first.try(:site_name) %> website.</p>
@@ -19,5 +19,17 @@ List of messages from the contact form:
19
19
 
20
20
  You can see and manage these messages at: <%= contacts_url %>
21
21
  <% end %>
22
+ <% unless @yesterdays_activities.blank? %>
23
+ Activity feed:
22
24
 
25
+ <% @yesterdays_activities.each do |activity| %>
26
+ <% unless activity.doer.blank? %>
27
+ <%= "- #{ link_to activity.doer.spiritual_name, member_url(id: activity.doer.id) } #{activity.message}".html_safe %>
28
+ <% else # user has been deleted %>
29
+ <%= "- now deleted user #{activity.message}".html_safe %>
30
+ <% end %>
31
+ <% end %>
32
+
33
+ You can view the activity feed at: <%= activities_url %>
34
+ <% end %>
23
35
  You are receiving this email because you are an administrator of the <%= Setting.first.try(:site_name) %> website.
@@ -24,7 +24,7 @@
24
24
  <span class="glyphicon glyphicon-ok"></span> <%= link_to t('authentication.disable_admin'), remove_admin_user_path(member), class: 'btn btn-xs btn-primary', method: :post %>
25
25
  <% end -%>
26
26
  </td>
27
- <td><%= link_to t('edit'), edit_member_path(member), :class => 'btn btn-xs btn-default' %><%= link_to t('delete'), member, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-xs btn-danger' %></td>
27
+ <td><%= link_to "<span class='glyphicon glyphicon-pencil'></span> ".html_safe + t('edit'), edit_member_path(member), :class => 'btn btn-xs btn-default' %><%= link_to "<span class='glyphicon glyphicon-trash'></span> ".html_safe + t('delete'), member, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-xs btn-danger' %></td>
28
28
  </tr>
29
29
  <% end %>
30
30
  </tbody>
@@ -32,6 +32,6 @@
32
32
 
33
33
  <%= will_paginate @members, inner_window: 2 %>
34
34
 
35
- <p><%= link_to 'Add a New Member', new_member_path, class: 'btn btn-default' %></p>
35
+ <p><%= link_to "<span class='glyphicon glyphicon-plus'></span> Add a New Member".html_safe, new_member_path, class: 'btn btn-default' %></p>
36
36
 
37
37
  <%= render 'shared/admin_sidebar' %>
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5
+ </head>
6
+ <body>
7
+ <h1>We need to verify your email address</h1>
8
+
9
+ <p>You have just requested our email newsletter. Before we add you to the list we need to verify your email address.</p>
10
+ <p>To protect your privacy, we need you to confirm you are the owner of the <%= @user.email %> address.
11
+ </p>
12
+
13
+ <p>
14
+ Please visit <%= link_to 'this activation link', email_confirmation_url(token: @user.email_validation_token) %>
15
+ </p>
16
+ <p>Thanks for your interest and we look forward to send you the next issue.</p>
17
+ </body>
18
+ </html>
@@ -0,0 +1,9 @@
1
+ Hello,
2
+
3
+ You have just requested our email newsletter. Before we add you to the list we need to verify your email address.
4
+
5
+ To protect your privacy, we need you to confirm you are the owner of the <%= @user.email %> address.
6
+
7
+ Please visit this activation link: <%= email_confirmation_url(token: @user.email_validation_token) %>
8
+
9
+ Thanks for your interest and we look forward to send you the next issue.
@@ -0,0 +1,30 @@
1
+ <% content_for :meta_title, 'Email Confirmation' %>
2
+ <% content_for :meta_description, "Step 3 of the email verification process to subscribing to our email newsletter." %>
3
+
4
+ <% if @email_confirmed %>
5
+
6
+ <h2>Step 3 of 3 - Email Confirmation</h2>
7
+
8
+ <div class="panel panel-success">
9
+
10
+ <div class="progress progress-striped">
11
+ <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
12
+ 100% completed
13
+ </div>
14
+ </div>
15
+
16
+ <div class="panel-body">
17
+ <p>Congratulations! Your email address has been verified and confirmed.</p>
18
+ <p>We will send you the next newsletter issue.</p>
19
+ </div>
20
+
21
+ <% else %>
22
+
23
+ <div class="panel panel-danger">
24
+
25
+ <div class="panel-body">
26
+ <p>There was a problem sending you the verification email. Please try again.</p>
27
+ </div>
28
+ </div>
29
+
30
+ <% end %>
@@ -0,0 +1,32 @@
1
+ <% content_for :meta_title, 'Email Verification' %>
2
+ <% content_for :meta_description, "Step 2 of the email verification process to subscribe to our email newsletter." %>
3
+
4
+ <h2>Step 2 - Email Verification</h2>
5
+
6
+ <% if @validation_ready %>
7
+
8
+ <div class="panel panel-primary">
9
+
10
+ <div class="progress progress-striped">
11
+ <div class="progress-bar progress-bar-primary" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width: 50%">
12
+ 50% to completion
13
+ </div>
14
+ </div>
15
+
16
+ <div class="panel-body">
17
+ <p>We just sent a verification email to <%= @user.email %>. Please click on the activation link. <br /><br />
18
+ You have 1 hour!!!<br />
19
+ You can now go to your email <strong>inbox</strong> or <strong>spam folder</strong>.</p>
20
+ </div>
21
+ </div>
22
+
23
+ <% else %>
24
+
25
+ <div class="panel panel-danger">
26
+
27
+ <div class="panel-body">
28
+ <p>There was a problem sending you the verification email. Please try again.</p>
29
+ </div>
30
+ </div>
31
+
32
+ <% end %>
@@ -1,11 +1,14 @@
1
1
  Rails.application.routes.draw do
2
+
2
3
  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
3
4
 
5
+ # special routes for the signup to basic newsletter
6
+ post '/email_verification' => 'signups#email_verification'
7
+ get '/email_confirmation' => 'signups#email_confirmation'
8
+ # contact forms
4
9
  resources :contacts
5
-
6
10
  # Mailing list records for admin
7
11
  resources :details # deprecated. Should disappear soon.
8
-
9
12
  # for public viewing and admin editing
10
13
  resources :members
11
14
  # for user to edit and view privately
@@ -13,4 +16,5 @@ Rails.application.routes.draw do
13
16
  get 'profile_history' => 'profiles#history'
14
17
 
15
18
  end
19
+
16
20
  end
@@ -11,6 +11,7 @@ namespace :tkh_mailing_list do
11
11
  system 'rails g tkh_mailing_list:create_or_update_locales -f'
12
12
  end
13
13
 
14
+ # this task is invoked my crontab once a day
14
15
  desc "Send to the administrators a email digest of important activities."
15
16
  task :daily_admin_digest => :environment do
16
17
  Administration.send_daily_digest
@@ -1,3 +1,3 @@
1
1
  module TkhMailingList
2
- VERSION = "0.11.3"
2
+ VERSION = "0.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkh_mailing_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swami Atma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2015-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,9 +75,11 @@ files:
75
75
  - app/controllers/details_controller.rb
76
76
  - app/controllers/members_controller.rb
77
77
  - app/controllers/profiles_controller.rb
78
+ - app/controllers/signups_controller.rb
78
79
  - app/helpers/members_helper.rb
79
80
  - app/mailers/administration_mailer.rb
80
81
  - app/mailers/contact_mailer.rb
82
+ - app/mailers/signup_mailer.rb
81
83
  - app/models/administration.rb
82
84
  - app/models/contact.rb
83
85
  - app/models/detail.rb
@@ -112,6 +114,10 @@ files:
112
114
  - app/views/profiles/edit.html.erb
113
115
  - app/views/profiles/history.html.erb
114
116
  - app/views/profiles/show.html.erb
117
+ - app/views/signup_mailer/verification_email.html.erb
118
+ - app/views/signup_mailer/verification_email.text.erb
119
+ - app/views/signups/email_confirmation.html.erb
120
+ - app/views/signups/email_verification.html.erb
115
121
  - config/routes.rb
116
122
  - lib/generators/tkh_mailing_list/create_or_update_locales/create_or_update_locales_generator.rb
117
123
  - lib/generators/tkh_mailing_list/create_or_update_locales/templates/de.yml