the_subscribers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 51ddb322b59f15f64371005ea5c7756fe8cfd356
4
+ data.tar.gz: ae9feebcd47f8cb956101bbdb17e833fb03aa586
5
+ SHA512:
6
+ metadata.gz: 00888266d620ad4c8b870b1fd09f9fbf92f5e2be9e2d70f325ea11d3a766ec9a9d68fe432dab7a45f32d7d7c16cfa43d48e756bb0bf1da413f52e71505fe7f33
7
+ data.tar.gz: 937904453b46266c9197a6524e203914af15089717e42060c579bf8c817b2d18cb6612266d7e510093061937720e693138ae1646625cfad35b5b701e79789f01
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_subscribers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ilya N. Zykin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # TheSubscribers
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'the_subscribers'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install the_subscribers
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/the_subscribers/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,110 @@
1
+ class SubscribersController < ApplicationController
2
+ layout 'bootstrap_default'
3
+
4
+ include SubscribersCrypt
5
+
6
+ before_action :set_subscriber, only: %w[ show edit update destroy ]
7
+ before_action :user_require, except: %w[ create confirm unsubscribe ]
8
+ before_action :role_required, except: %w[ create confirm unsubscribe ]
9
+
10
+ def create
11
+ @subscriber = Subscriber.new(new_subscriber_params)
12
+
13
+ message = if @subscriber.save
14
+ @subscriber.send_confirm_email!
15
+ { flash: { notice: t('.token_sended') } }
16
+ else
17
+ { flash: { errors: @subscriber.errors.to_a } }
18
+ end
19
+
20
+ redirect_to root_path, message
21
+ end
22
+
23
+ # get "subscribers/:token/confirm"
24
+ def confirm
25
+ @subscriber = Subscriber.find_by_confirmation_token params[:id]
26
+
27
+ unless @subscriber
28
+ return redirect_to root_path, { flash: { alert: "Запись о подписке для активации не найдена" } }
29
+ end
30
+
31
+ message = if @subscriber.active?
32
+ "Подписка уже активирована"
33
+ elsif @subscriber.unconfirmed?
34
+ @subscriber.activate!
35
+ "Подписка успешно активирована"
36
+ else
37
+ "Подписка приостановлена"
38
+ end
39
+
40
+ redirect_to root_path, { flash: { notice: message } }
41
+ end
42
+
43
+ def unsubscribe
44
+ email = decrypt params[:email]
45
+ @subscriber = Subscriber.find_by_email(email)
46
+
47
+ message = if @subscriber
48
+ @subscriber.to_unactive
49
+ { flash: { notice: t('.unsubscribed') } }
50
+ else
51
+ { flash: { error: t('.bad_link') } }
52
+ end
53
+
54
+ redirect_to root_path, message
55
+ end
56
+
57
+ # MODERATOR INTERFACE
58
+
59
+ def index
60
+ @subscribers = Subscriber.recent.pagination params
61
+ end
62
+
63
+ def new
64
+ @subscriber = Subscriber.new
65
+ end
66
+
67
+ def show; end
68
+ def edit; end
69
+
70
+ def update
71
+ @subscriber.assign_attributes(subscriber_params)
72
+
73
+ if @subscriber.send("to_#{ @state }")
74
+ redirect_to subscribers_path, notice: t('.updated')
75
+ else
76
+ render action: :edit
77
+ end
78
+ end
79
+
80
+ def destroy
81
+ @subscriber.destroy
82
+ redirect_to subscribers_url
83
+ end
84
+
85
+ def update
86
+ @subscriber.update(subscriber_params)
87
+
88
+ if @subscriber.user_send_state
89
+ flash.now.notice = t('.switching_on')
90
+ else
91
+ flash.now.alert = t('.switching_off')
92
+ end
93
+
94
+ render action: :edit
95
+ end
96
+
97
+ private
98
+
99
+ def set_subscriber
100
+ @subscriber = Subscriber.find params[:id]
101
+ end
102
+
103
+ def new_subscriber_params
104
+ params.require(:subscriber).permit(:email)
105
+ end
106
+
107
+ def subscriber_params
108
+ params.require(:subscriber).permit(:email, :user_send_state)
109
+ end
110
+ end
@@ -0,0 +1,21 @@
1
+ module SubscribeStates
2
+ extend ActiveSupport::Concern
3
+
4
+ # unactive | active | unconfirmed
5
+ included do
6
+ state_machine :initial => :unactive do
7
+ event :to_active do
8
+ # regenerate key
9
+ transition any => :active
10
+ end
11
+
12
+ event :to_unactive do
13
+ transition any => :unactive
14
+ end
15
+
16
+ event :to_unconfirmed do
17
+ transition any => :unconfirmed
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module SubscribersCrypt
2
+ extend ActiveSupport::Concern
3
+
4
+ def crypt data
5
+ data.encrypt!
6
+ Base64.urlsafe_encode64(data)
7
+ end
8
+
9
+ def decrypt data
10
+ data = Base64.urlsafe_decode64(data)
11
+ data.decrypt
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ class Subscriber < ActiveRecord::Base
2
+ include BaseSorts
3
+ include SubscribeStates
4
+ include PaginationConcern
5
+
6
+ validates_presence_of :email
7
+ validates_uniqueness_of :email, case_sensitive: false
8
+ before_validation :generate_token, on: :create
9
+ # validates_format_of :email, with: /\A.+@.+\..{2,5}\Z/
10
+
11
+ def activate!
12
+ to_active
13
+ generate_token
14
+ save
15
+ end
16
+
17
+ def send_confirm_email!
18
+ SubscribeMailer.confirm(self).deliver
19
+ end
20
+
21
+ private
22
+
23
+ def generate_token
24
+ self.confirmation_token = SecureRandom.urlsafe_base64(10)
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ %p
2
+ Здравствуйте, #{ @subscriber.email }!
3
+ %p Вы можете подтвердить вашу подписку по ссылке:
4
+ %p= link_to 'Подтвердить', confirm_subscriber_url(@subscriber.confirmation_token)
5
+ %p ArtElectronics
@@ -0,0 +1,6 @@
1
+ - content_for :express_nav do
2
+ %p= link_to t('subscribers.show.title'), subscriber_path
3
+ %p= link_to t('subscribers.index.title'), subscribers_path
4
+
5
+ %h1= t('.title')
6
+ = render 'form'
@@ -0,0 +1,18 @@
1
+ = form_for @subscriber do |f|
2
+ = render partial: 'the_notification/form', locals: { object: @subscriber }
3
+
4
+ .form-group
5
+ = f.label :email, t('.email')
6
+ = f.text_field :email, class: 'form-control'
7
+
8
+ - if @subscriber.persisted?
9
+ .form-group.red_font
10
+ = t '.unconfirmed_state' if @subscriber.confirmation_token
11
+ .form-group
12
+ - options = options_for_select(subscriber_states, get_subscriber_state( @subscriber ) )
13
+ = f.label :state, t('.state')
14
+ %br
15
+ = f.select :state, options, class: 'form-control'
16
+
17
+ .form-group
18
+ = f.submit t('.save'), class: 'btn btn-info'
@@ -0,0 +1,6 @@
1
+ .subscribe_form
2
+ = form_tag subscribers_path do
3
+ .form-group
4
+ = text_field_tag 'subscriber[email]', nil, placeholder: t('subscribers.form_placeholder'), class: 'form-control input-lg'
5
+ .form-group
6
+ = submit_tag "Получать Дайджест AE", class: 'btn btn-default'
@@ -0,0 +1,26 @@
1
+ - content_for :express_nav do
2
+ %p= link_to t('app.cabinet'), cabinet_path
3
+
4
+ = render partial: 'the_notification/flash'
5
+
6
+ %h1= t('.title')
7
+
8
+ - if @subscriber.nil? || @subscriber.unactive?
9
+ = t('.not_subscribed')
10
+
11
+ - else
12
+ = form_for @subscriber, :url => subscribe_manage_path, method: :post, class: 'form-inline' do |f|
13
+ .form-group
14
+ = f.label :email, t('.email')
15
+ = f.text_field :email, class: 'form-control', disabled: :true
16
+
17
+ .form-group.red_font
18
+ = t('.not_confirmed_yet') if @subscriber.confirmation_token
19
+
20
+ .form-group
21
+ = f.label :user_send_state, :class => "checkbox" do
22
+ = t('.manage')
23
+ = f.check_box :user_send_state
24
+
25
+ .form-group
26
+ = f.submit t('.save'), class: 'btn btn-info'
@@ -0,0 +1,36 @@
1
+ %h1= t('.title')
2
+ %li= link_to t('.link_new'), new_subscriber_path
3
+
4
+ - content_for :full_width do
5
+ = paginate @subscribers
6
+
7
+ %table.table.table-condensed.table-hover
8
+ %thead
9
+ %tr
10
+ %th= t('.email')
11
+ %th= t('.unsubscribe_link')
12
+ %th= t('.created_at')
13
+ %th= t('.updated_at')
14
+ %th= t('.manage')
15
+ %tbody
16
+ - @subscribers.each.with_index do |subscriber, i|
17
+ %tr{ class: state_color( subscriber.state_name ) }
18
+ %td
19
+ %p{ title: t(".#{ subscriber.state }") }= subscriber.email
20
+
21
+ %td= content_tag :button, "Link", type: 'submit', class: 'unsubscribe_button', 'data-title' => t('.unsubscribe_button.title'), 'data-text' => unsubscribe_url(crypt(subscriber.email))
22
+
23
+ %td= subscriber.created_at.strftime('%d.%m.%Y')
24
+ %td= subscriber.updated_at.strftime('%d.%m.%Y')
25
+
26
+ %td
27
+ .dropdown
28
+ %button.btn.btn-default.dropdown-toggle(type='button' data-toggle="dropdown")
29
+ %span.caret
30
+
31
+ %ul.dropdown-menu(role="menu")
32
+ %li= link_to 'Show', subscriber_path(subscriber)
33
+ %li= link_to 'Edit', edit_subscriber_path(subscriber)
34
+ %li= link_to 'Destroy', subscriber_path(subscriber), method: :delete, data: { confirm: 'Are you sure?' }
35
+
36
+ = paginate @subscribers
@@ -0,0 +1,5 @@
1
+ - content_for :express_nav do
2
+ %p= link_to t('subscribers.index.title'), subscribers_path
3
+
4
+ %h1= t('.title')
5
+ = render 'form'
@@ -0,0 +1,18 @@
1
+ - content_for :express_nav do
2
+ %p= link_to t('.link_edit'), edit_subscriber_path(@subscriber)
3
+ %p= link_to t('subscribers.index.title'), subscribers_path
4
+
5
+ %h1= t('.title')
6
+
7
+ %table.table
8
+ %tbody
9
+ %tr
10
+ %td
11
+ %strong= t('subscribers.form.email')
12
+ %td
13
+ = @subscriber.email
14
+ %tr
15
+ %td
16
+ %strong= t('subscribers.form.state')
17
+ %td
18
+ = t "subscribers.index.#{ @subscriber.state }"
@@ -0,0 +1,78 @@
1
+ ru:
2
+ subscribers:
3
+ form_title: Подписка на рассылку
4
+ form_placeholder: E-mail
5
+ form_submit: Отправить
6
+
7
+ edit:
8
+ title: Подписка
9
+ email: "Подписанный E-mail"
10
+ manage: "Вкл/Выкл"
11
+ save: Сохранить
12
+ not_subscribed: Вы пока не подписаны на рассылку. Но это можно сделать на главной странице.
13
+ not_confirmed_yet: Email еще не подтвержден. Проверьте почту.
14
+ update:
15
+ switching_on: Подписка включена
16
+ switching_off: Подписка выключена
17
+ create:
18
+ token_sended: Вам отправлен код подтверждения подписки
19
+ already_subscribed: Этот E-mail уже есть в базе подписчиков
20
+
21
+ confirm:
22
+ token_matched: Подписка успешно подтверждена
23
+ mismatch_token: Подписка не подтверждена. Неверный токен
24
+ already_confirmed_email: Этот e-mail уже был подтвержден
25
+
26
+ unsubscribe:
27
+ unsubscribed: Подписка отключена
28
+ bad_link: Неверная ссылка на отключение подписки. Подписка не отключена
29
+
30
+ index:
31
+ title: Подписчики
32
+
33
+ show: Просмотр подписчика
34
+ edit: Редактировать подписчика
35
+ destroy: Удалить подписчика
36
+
37
+ link_new: Новый подписчик
38
+
39
+ email: E-mail
40
+ unsubscribe_link: Отписаться
41
+ created_at: Создан
42
+ updated_at: Обновлен
43
+ manage: "Управлять:"
44
+
45
+ active: Активная
46
+ unactive: Неактивная
47
+ unconfirmed: Не подтверждена
48
+
49
+ unsubscribe_button:
50
+ title: 'Copy to clipboard: Ctrl+C, Enter'
51
+
52
+ create:
53
+ created: Подписчик успешно создан. Ему отправлен код для подтверждения подписки
54
+
55
+ new:
56
+ title: Новый подписчик
57
+
58
+ show:
59
+ title: Просмотр
60
+ link_edit: Редактировать
61
+
62
+ edit:
63
+ title: Редактировать подписчика
64
+
65
+ update:
66
+ updated: Подписчик успешно обновлен.
67
+
68
+ form:
69
+ email: E-mail
70
+ state: Состояние
71
+ save: Сохранить
72
+ unconfirmed_state: 'E-mail еще не подтвержден пользователем'
73
+
74
+ select_states:
75
+ enable: Активна
76
+ disable: Неактивна
77
+
78
+
data/config/routes.rb ADDED
@@ -0,0 +1,15 @@
1
+ module TheSubscribers
2
+ class Routes
3
+ def self.mixin mapper
4
+ mapper.get "unsubscribe/:email" => 'subscribers#unsubscribe', as: 'unsubscribe'
5
+ mapper.get "subscribe/manage" => 'subscribers#edit'
6
+ mapper.post "subscribe/manage" => 'subscribers#update'
7
+
8
+ mapper.resources :subscribers do
9
+ mapper.member do
10
+ mapper.get :confirm
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
data/gem_version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module TheSubscribers
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ _root_ = File.expand_path('../../', __FILE__)
2
+ require "the_subscribers/version"
3
+
4
+ require 'state_machine'
5
+ require 'encryptor'
6
+ require 'haml'
7
+
8
+ module TheSubscribers
9
+ class Engine < Rails::Engine; end
10
+ end
11
+
12
+ # Loading of concerns
13
+ require "#{_root_}/config/routes.rb"
@@ -0,0 +1 @@
1
+ require_relative '../../gem_version'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "the_subscribers/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "the_subscribers"
8
+ spec.version = TheSubscribers::VERSION
9
+ spec.authors = ["Ilya N. Zykin"]
10
+ spec.email = ["zykin-ilya@ya.ru"]
11
+ spec.summary = %q{TheSubscribers - collect and manage of Subscribers}
12
+ spec.description = %q{Collect and manage of Subscribers}
13
+ spec.homepage = "http://github.com/the-teacher/the_subscribers"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'state_machine'
22
+ spec.add_dependency 'encryptor'
23
+ spec.add_dependency 'haml'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_subscribers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ilya N. Zykin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: state_machine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: encryptor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: haml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Collect and manage of Subscribers
84
+ email:
85
+ - zykin-ilya@ya.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - app/controllers/subscribers_controller.rb
96
+ - app/models/concerns/subscribe_states.rb
97
+ - app/models/concerns/subscribers_crypt.rb
98
+ - app/models/subscriber.rb
99
+ - app/views/subscribe_mailer/confirm.html.haml
100
+ - app/views/subscribers/_edit.html.haml
101
+ - app/views/subscribers/_form.html.haml
102
+ - app/views/subscribers/_subscribe_form.html.haml
103
+ - app/views/subscribers/edit.html.haml
104
+ - app/views/subscribers/index.html.haml
105
+ - app/views/subscribers/new.html.haml
106
+ - app/views/subscribers/show.html.haml
107
+ - config/locales/ru.yml
108
+ - config/routes.rb
109
+ - gem_version.rb
110
+ - lib/the_subscribers.rb
111
+ - lib/the_subscribers/version.rb
112
+ - the_subscribers.gemspec
113
+ homepage: http://github.com/the-teacher/the_subscribers
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.2.2
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: TheSubscribers - collect and manage of Subscribers
137
+ test_files: []