keymail 0.1.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +65 -0
  4. data/Rakefile +33 -0
  5. data/app/controllers/keymail/application_controller.rb +4 -0
  6. data/app/mailers/keymail/auth_mailer.rb +16 -0
  7. data/app/models/keymail/auth.rb +44 -0
  8. data/app/models/keymail/token.rb +22 -0
  9. data/app/views/keymail/auth_mailer/log_in.text.erb +5 -0
  10. data/config/routes.rb +3 -0
  11. data/db/migrate/20140414074140_create_keymail_tokens.rb +11 -0
  12. data/lib/keymail.rb +4 -0
  13. data/lib/keymail/engine.rb +9 -0
  14. data/lib/keymail/version.rb +3 -0
  15. data/lib/tasks/keymail_tasks.rake +4 -0
  16. data/test/dummy/README.rdoc +28 -0
  17. data/test/dummy/Rakefile +6 -0
  18. data/test/dummy/app/assets/javascripts/application.js +13 -0
  19. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  20. data/test/dummy/app/controllers/application_controller.rb +5 -0
  21. data/test/dummy/app/helpers/application_helper.rb +2 -0
  22. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  23. data/test/dummy/bin/bundle +3 -0
  24. data/test/dummy/bin/rails +4 -0
  25. data/test/dummy/bin/rake +4 -0
  26. data/test/dummy/config.ru +4 -0
  27. data/test/dummy/config/application.rb +23 -0
  28. data/test/dummy/config/boot.rb +5 -0
  29. data/test/dummy/config/database.yml +25 -0
  30. data/test/dummy/config/environment.rb +5 -0
  31. data/test/dummy/config/environments/development.rb +29 -0
  32. data/test/dummy/config/environments/production.rb +80 -0
  33. data/test/dummy/config/environments/test.rb +36 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  36. data/test/dummy/config/initializers/inflections.rb +16 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +12 -0
  39. data/test/dummy/config/initializers/session_store.rb +3 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +23 -0
  42. data/test/dummy/config/routes.rb +4 -0
  43. data/test/dummy/db/development.sqlite3 +0 -0
  44. data/test/dummy/db/schema.rb +24 -0
  45. data/test/dummy/db/test.sqlite3 +0 -0
  46. data/test/dummy/log/development.log +236 -0
  47. data/test/dummy/log/test.log +25391 -0
  48. data/test/dummy/public/404.html +58 -0
  49. data/test/dummy/public/422.html +58 -0
  50. data/test/dummy/public/500.html +57 -0
  51. data/test/dummy/public/favicon.ico +0 -0
  52. data/test/factories.rb +8 -0
  53. data/test/integration/feature_test.rb +15 -0
  54. data/test/integration/navigation_test.rb +10 -0
  55. data/test/keymail_test.rb +7 -0
  56. data/test/mailers/keymail/auth_mailer_test.rb +28 -0
  57. data/test/models/keymail/auth_test.rb +73 -0
  58. data/test/models/keymail/token_test.rb +25 -0
  59. data/test/test_helper.rb +62 -0
  60. metadata +161 -0
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,8 @@
1
+ # Using Minifacture
2
+ # https://github.com/stephencelis/minifacture
3
+
4
+ Factory.define :token, class: Keymail::Token do |f|
5
+ f.email 'user%d@example.com'
6
+ f.expires_at 10.minutes.since
7
+ end
8
+
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Keymail Integration' do
4
+
5
+ it 'logs in a user when provided an email' do
6
+ # visit log_in_path
7
+ # enter email in field
8
+ # click link in email
9
+ # expect to be logged in
10
+ end
11
+
12
+ it 'logs in a user with an optional passcode' do
13
+
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ class NavigationTest < ActionDispatch::IntegrationTest
4
+ fixtures :all
5
+
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ describe Keymail do
4
+ it 'is a module' do
5
+ Keymail.must_be_kind_of Module
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ require 'minitest/mock'
4
+
5
+ module Keymail
6
+ describe AuthMailer do
7
+
8
+ let(:token) { Factory :token }
9
+ let(:email) { AuthMailer.log_in(token).deliver }
10
+ let(:body) { email.body.raw_source }
11
+
12
+ it 'sends authentication email to the right address' do
13
+ sent_emails.wont_be :empty?
14
+ email.to.must_equal [token.email]
15
+ end
16
+
17
+ it 'has the log in link' do
18
+ # TODO: link_to
19
+ body.must_have_content "http://localhost:3000/keymail/auth/#{token.url_key}"
20
+ end
21
+
22
+ it 'has the expiration date' do
23
+ body.must_have_content "valid until #{token.expires_at}"
24
+ end
25
+ # it 'has the optional passcode'
26
+
27
+ end
28
+ end
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ module Keymail
4
+ describe Auth do
5
+ context '.request' do
6
+
7
+ it 'creates a new token' do
8
+ -> { Auth.request('test@email.com') }.must_change 'Token.count', +1
9
+ end
10
+
11
+ it 'sends an email' do
12
+ -> { Auth.request('test@email.com') }.must_change 'sent_emails.count', +1
13
+ end
14
+ end
15
+
16
+ context '.verify_url' do
17
+ it 'destroys the token' do
18
+ token = Factory :token
19
+ Auth.verify_url_key(token.url_key)
20
+ Token.exists?(token).must_equal false
21
+ end
22
+
23
+ it 'does not delete anything if the token is invalid' do
24
+ -> { Auth.verify_url_key('not_a_valid_key') }.wont_change 'Token.count'
25
+ end
26
+
27
+ context 'authenticated' do
28
+ let(:token) { Factory :token }
29
+ let(:response) { Auth.verify_url_key(token.url_key) }
30
+
31
+ it 'is authenticated' do
32
+ response.must_be :authenticated?
33
+ end
34
+
35
+ it 'has an email' do
36
+ response.email.must_equal token.email
37
+ end
38
+
39
+ it 'is not expired' do
40
+ response.wont_be :expired?
41
+ end
42
+
43
+ # first time, redirect...
44
+ end
45
+
46
+ context 'expired' do
47
+ let(:token) { Factory :token, expires_at: 10.minutes.ago }
48
+ let(:response) { Auth.verify_url_key(token.url_key) }
49
+
50
+ it 'is not authenticated' do
51
+ response.wont_be :authenticated?
52
+ end
53
+
54
+ it 'has an email' do
55
+ response.email.must_equal token.email
56
+ end
57
+
58
+ it 'is expired' do
59
+ response.must_be :expired?
60
+ end
61
+ end
62
+
63
+ context 'invalid' do
64
+ let(:response) { Auth.verify_url_key('invalid_url_key') }
65
+
66
+ it 'is not authenticated' do
67
+ response.wont_be :authenticated?
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ module Keymail
4
+ describe Token do
5
+ it 'generates a url_key when created' do
6
+ token = Factory.create :token
7
+ token.url_key.wont_be_nil
8
+ end
9
+
10
+ it 'must have an email' do
11
+ token = Factory.build :token, email: ''
12
+ token.must_have_invalid :email
13
+ end
14
+
15
+ it 'must have an expiration date' do
16
+ token = Factory.build :token, expires_at: nil
17
+ token.must_have_invalid :expires_at
18
+ end
19
+
20
+ it 'is expired after its expiry date' do
21
+ token = Factory.build :token, expires_at: 10.minutes.ago
22
+ token.must_be :expired?
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start 'rails'
9
+
10
+ # Configure Rails Environment
11
+ ENV["RAILS_ENV"] = "test"
12
+
13
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
14
+ require "rails/test_help"
15
+
16
+ require "factories"
17
+
18
+ Turn.config.natural = true
19
+
20
+ DatabaseCleaner.strategy = :transaction
21
+
22
+ Rails.backtrace_cleaner.remove_silencers!
23
+
24
+ # Load support files
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
26
+
27
+ class Minitest::Spec
28
+ include ActiveSupport::Testing::Assertions # assert_difference etc...
29
+ include ActiveSupport::Testing::SetupAndTeardown # before, after
30
+
31
+ # Support rspec-style context-blocks
32
+ class << self
33
+ alias_method :context, :describe
34
+ end
35
+
36
+ before { DatabaseCleaner.start }
37
+ after { DatabaseCleaner.clean }
38
+ end
39
+
40
+ # A bit more dry validation tests
41
+ # m = Message.create(text: '')
42
+ # m.must_have_invalid :text
43
+ module Minitest::Assertions
44
+ def assert_has_invalid(field, model)
45
+ model.must_be :invalid?
46
+ model.errors[field].must_be :present?
47
+ end
48
+ end
49
+ ActiveRecord::Base.infect_an_assertion :assert_has_invalid, :must_have_invalid
50
+
51
+ class Proc
52
+ infect_an_assertion :assert_difference, :must_change
53
+ infect_an_assertion :assert_no_difference, :wont_change
54
+ end
55
+
56
+ def sent_emails
57
+ ActionMailer::Base.deliveries
58
+ end
59
+
60
+ def last_email
61
+ ActionMailer::Base.deliveries.last
62
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keymail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - alcesleo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.4
27
+ description: Instead of using passwords, keymail sends emails with a link that logs
28
+ in your user automatically.
29
+ email:
30
+ - lagginglion@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - app/controllers/keymail/application_controller.rb
39
+ - app/mailers/keymail/auth_mailer.rb
40
+ - app/models/keymail/auth.rb
41
+ - app/models/keymail/token.rb
42
+ - app/views/keymail/auth_mailer/log_in.text.erb
43
+ - config/routes.rb
44
+ - db/migrate/20140414074140_create_keymail_tokens.rb
45
+ - lib/keymail.rb
46
+ - lib/keymail/engine.rb
47
+ - lib/keymail/version.rb
48
+ - lib/tasks/keymail_tasks.rake
49
+ - test/dummy/README.rdoc
50
+ - test/dummy/Rakefile
51
+ - test/dummy/app/assets/javascripts/application.js
52
+ - test/dummy/app/assets/stylesheets/application.css
53
+ - test/dummy/app/controllers/application_controller.rb
54
+ - test/dummy/app/helpers/application_helper.rb
55
+ - test/dummy/app/views/layouts/application.html.erb
56
+ - test/dummy/bin/bundle
57
+ - test/dummy/bin/rails
58
+ - test/dummy/bin/rake
59
+ - test/dummy/config.ru
60
+ - test/dummy/config/application.rb
61
+ - test/dummy/config/boot.rb
62
+ - test/dummy/config/database.yml
63
+ - test/dummy/config/environment.rb
64
+ - test/dummy/config/environments/development.rb
65
+ - test/dummy/config/environments/production.rb
66
+ - test/dummy/config/environments/test.rb
67
+ - test/dummy/config/initializers/backtrace_silencers.rb
68
+ - test/dummy/config/initializers/filter_parameter_logging.rb
69
+ - test/dummy/config/initializers/inflections.rb
70
+ - test/dummy/config/initializers/mime_types.rb
71
+ - test/dummy/config/initializers/secret_token.rb
72
+ - test/dummy/config/initializers/session_store.rb
73
+ - test/dummy/config/initializers/wrap_parameters.rb
74
+ - test/dummy/config/locales/en.yml
75
+ - test/dummy/config/routes.rb
76
+ - test/dummy/db/development.sqlite3
77
+ - test/dummy/db/schema.rb
78
+ - test/dummy/db/test.sqlite3
79
+ - test/dummy/log/development.log
80
+ - test/dummy/log/test.log
81
+ - test/dummy/public/404.html
82
+ - test/dummy/public/422.html
83
+ - test/dummy/public/500.html
84
+ - test/dummy/public/favicon.ico
85
+ - test/factories.rb
86
+ - test/integration/feature_test.rb
87
+ - test/integration/navigation_test.rb
88
+ - test/keymail_test.rb
89
+ - test/mailers/keymail/auth_mailer_test.rb
90
+ - test/models/keymail/auth_test.rb
91
+ - test/models/keymail/token_test.rb
92
+ - test/test_helper.rb
93
+ homepage: https://github.com/alcesleo/keymail
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">"
108
+ - !ruby/object:Gem::Version
109
+ version: 1.3.1
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Forget passwords, authenticate via email!
116
+ test_files:
117
+ - test/dummy/README.rdoc
118
+ - test/dummy/Rakefile
119
+ - test/dummy/app/assets/javascripts/application.js
120
+ - test/dummy/app/assets/stylesheets/application.css
121
+ - test/dummy/app/controllers/application_controller.rb
122
+ - test/dummy/app/helpers/application_helper.rb
123
+ - test/dummy/app/views/layouts/application.html.erb
124
+ - test/dummy/bin/bundle
125
+ - test/dummy/bin/rails
126
+ - test/dummy/bin/rake
127
+ - test/dummy/config/application.rb
128
+ - test/dummy/config/boot.rb
129
+ - test/dummy/config/database.yml
130
+ - test/dummy/config/environment.rb
131
+ - test/dummy/config/environments/development.rb
132
+ - test/dummy/config/environments/production.rb
133
+ - test/dummy/config/environments/test.rb
134
+ - test/dummy/config/initializers/backtrace_silencers.rb
135
+ - test/dummy/config/initializers/filter_parameter_logging.rb
136
+ - test/dummy/config/initializers/inflections.rb
137
+ - test/dummy/config/initializers/mime_types.rb
138
+ - test/dummy/config/initializers/secret_token.rb
139
+ - test/dummy/config/initializers/session_store.rb
140
+ - test/dummy/config/initializers/wrap_parameters.rb
141
+ - test/dummy/config/locales/en.yml
142
+ - test/dummy/config/routes.rb
143
+ - test/dummy/config.ru
144
+ - test/dummy/db/development.sqlite3
145
+ - test/dummy/db/schema.rb
146
+ - test/dummy/db/test.sqlite3
147
+ - test/dummy/log/development.log
148
+ - test/dummy/log/test.log
149
+ - test/dummy/public/404.html
150
+ - test/dummy/public/422.html
151
+ - test/dummy/public/500.html
152
+ - test/dummy/public/favicon.ico
153
+ - test/factories.rb
154
+ - test/integration/feature_test.rb
155
+ - test/integration/navigation_test.rb
156
+ - test/keymail_test.rb
157
+ - test/mailers/keymail/auth_mailer_test.rb
158
+ - test/models/keymail/auth_test.rb
159
+ - test/models/keymail/token_test.rb
160
+ - test/test_helper.rb
161
+ has_rdoc: