rails-identity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/assets/javascripts/rails_identity/application.js +13 -0
  5. data/app/assets/javascripts/rails_identity/sessions.js +2 -0
  6. data/app/assets/javascripts/rails_identity/users.js +2 -0
  7. data/app/assets/stylesheets/rails_identity/application.css +15 -0
  8. data/app/assets/stylesheets/rails_identity/sessions.css +4 -0
  9. data/app/assets/stylesheets/rails_identity/users.css +4 -0
  10. data/app/controllers/rails_identity/application_controller.rb +200 -0
  11. data/app/controllers/rails_identity/sessions_controller.rb +108 -0
  12. data/app/controllers/rails_identity/users_controller.rb +168 -0
  13. data/app/helpers/rails_identity/application_helper.rb +19 -0
  14. data/app/helpers/rails_identity/sessions_helper.rb +4 -0
  15. data/app/helpers/rails_identity/users_helper.rb +4 -0
  16. data/app/jobs/rails_identity/sessions_cleanup_job.rb +13 -0
  17. data/app/mailers/application_mailer.rb +4 -0
  18. data/app/mailers/rails_identity/user_mailer.rb +14 -0
  19. data/app/models/rails_identity/session.rb +44 -0
  20. data/app/models/rails_identity/user.rb +48 -0
  21. data/app/views/layouts/mailer.html.erb +5 -0
  22. data/app/views/layouts/mailer.text.erb +1 -0
  23. data/app/views/layouts/rails_identity/application.html.erb +14 -0
  24. data/app/views/rails_identity/user_mailer/email_verification.html.erb +12 -0
  25. data/app/views/rails_identity/user_mailer/email_verification.text.erb +13 -0
  26. data/app/views/rails_identity/user_mailer/password_reset.html.erb +14 -0
  27. data/app/views/rails_identity/user_mailer/password_reset.text.erb +15 -0
  28. data/config/routes.rb +7 -0
  29. data/db/migrate/20160323210013_create_rails_identity_users.rb +13 -0
  30. data/db/migrate/20160323210017_create_rails_identity_sessions.rb +12 -0
  31. data/db/migrate/20160401223433_add_reset_token_to_users.rb +5 -0
  32. data/db/migrate/20160411215917_add_verification_token_to_users.rb +10 -0
  33. data/db/migrate/20160414145851_add_api_key_to_users.rb +5 -0
  34. data/lib/rails_identity/engine.rb +9 -0
  35. data/lib/rails_identity/version.rb +3 -0
  36. data/lib/rails_identity.rb +52 -0
  37. data/lib/tasks/rails_identity_tasks.rake +4 -0
  38. data/test/controllers/rails_identity/sessions_controller_test.rb +192 -0
  39. data/test/controllers/rails_identity/users_controller_test.rb +253 -0
  40. data/test/dummy/README.rdoc +28 -0
  41. data/test/dummy/Rakefile +6 -0
  42. data/test/dummy/app/assets/javascripts/application.js +13 -0
  43. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  44. data/test/dummy/app/controllers/application_controller.rb +5 -0
  45. data/test/dummy/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/test/dummy/bin/bundle +3 -0
  48. data/test/dummy/bin/rails +4 -0
  49. data/test/dummy/bin/rake +4 -0
  50. data/test/dummy/bin/setup +29 -0
  51. data/test/dummy/config/application.rb +26 -0
  52. data/test/dummy/config/boot.rb +5 -0
  53. data/test/dummy/config/database.yml +25 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +41 -0
  56. data/test/dummy/config/environments/production.rb +79 -0
  57. data/test/dummy/config/environments/test.rb +42 -0
  58. data/test/dummy/config/initializers/assets.rb +11 -0
  59. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  61. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/test/dummy/config/initializers/inflections.rb +16 -0
  63. data/test/dummy/config/initializers/mime_types.rb +4 -0
  64. data/test/dummy/config/initializers/session_store.rb +3 -0
  65. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/test/dummy/config/locales/en.yml +23 -0
  67. data/test/dummy/config/routes.rb +4 -0
  68. data/test/dummy/config/secrets.yml +22 -0
  69. data/test/dummy/config.ru +4 -0
  70. data/test/dummy/db/development.sqlite3 +0 -0
  71. data/test/dummy/db/schema.rb +42 -0
  72. data/test/dummy/db/test.sqlite3 +0 -0
  73. data/test/dummy/log/development.log +215 -0
  74. data/test/dummy/log/test.log +280622 -0
  75. data/test/dummy/public/404.html +67 -0
  76. data/test/dummy/public/422.html +67 -0
  77. data/test/dummy/public/500.html +66 -0
  78. data/test/dummy/public/favicon.ico +0 -0
  79. data/test/dummy/tmp/cache/A5C/3F0/rails-identity-0.0.1-session-1 +0 -0
  80. data/test/fixtures/rails_identity/sessions.yml +36 -0
  81. data/test/fixtures/rails_identity/users.yml +24 -0
  82. data/test/integration/navigation_test.rb +10 -0
  83. data/test/jobs/rails_identity/sessions_cleanup_job_test.rb +9 -0
  84. data/test/mailers/previews/rails_identity/user_mailer_preview.rb +6 -0
  85. data/test/mailers/rails_identity/user_mailer_test.rb +9 -0
  86. data/test/models/rails_identity/session_test.rb +26 -0
  87. data/test/models/rails_identity/user_test.rb +54 -0
  88. data/test/rails_identity_test.rb +7 -0
  89. data/test/test_helper.rb +33 -0
  90. metadata +297 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,36 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one:
8
+ uuid: "1"
9
+ user_uuid: "1"
10
+ token: <%= JWT.encode({
11
+ session_uuid: "1",
12
+ user_uuid: "1",
13
+ role: RailsIdentity::Roles::USER,
14
+ exp: (Time.now.to_i + 14 * 3600)
15
+ }, "secret", 'HS256') %>
16
+ secret: secret
17
+ two:
18
+ uuid: "2"
19
+ user_uuid: "2"
20
+ token: <%= JWT.encode({
21
+ session_uuid: "2",
22
+ user_uuid: "2",
23
+ role: RailsIdentity::Roles::USER,
24
+ exp: (Time.now.to_i + 14 * 3600)
25
+ }, "secret", 'HS256') %>
26
+ secret: secret
27
+ admin_one:
28
+ uuid: "session_admin_one"
29
+ user_uuid: "admin_one"
30
+ token: <%= JWT.encode({
31
+ session_uuid: "session_admin_one",
32
+ user_uuid: "admin_one",
33
+ role: RailsIdentity::Roles::ADMIN,
34
+ exp: (Time.now.to_i + 14 * 3600)
35
+ }, "secret", "HS256") %>
36
+ secret: secret
@@ -0,0 +1,24 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one:
8
+ uuid: "1"
9
+ username: one@example.com
10
+ password_digest: <%= BCrypt::Password.create("password") %>
11
+ role: <%= RailsIdentity::Roles::USER %>
12
+ verified: true
13
+ two:
14
+ uuid: "2"
15
+ username: two@example.com
16
+ password_digest: <%= BCrypt::Password.create("password") %>
17
+ role: <%= RailsIdentity::Roles::USER %>
18
+ verified: true
19
+ admin_one:
20
+ uuid: "admin_one"
21
+ username: admin_one@example.com
22
+ password_digest: <%= BCrypt::Password.create("password") %>
23
+ role: <%= RailsIdentity::Roles::ADMIN %>
24
+ verified: true
@@ -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,9 @@
1
+ require 'test_helper'
2
+
3
+ module RailsIdentity
4
+ class SessionsCleanupJobTest < ActiveJob::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module RailsIdentity
2
+ # Preview all emails at http://localhost:3000/rails/mailers/user_mailer
3
+ class UserMailerPreview < ActionMailer::Preview
4
+
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module RailsIdentity
4
+ class UserMailerTest < ActionMailer::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ module RailsIdentity
4
+ class SessionTest < ActiveSupport::TestCase
5
+
6
+ test "session has token and secret when created" do
7
+ session = Session.new(user: rails_identity_users(:one))
8
+ assert_not_nil session.secret
9
+ assert_not_nil session.token
10
+ assert_equal Roles::USER, JWT.decode(session.token, nil, false)[0]["role"]
11
+ end
12
+
13
+ test "save a session" do
14
+ session = Session.new(user: rails_identity_users(:one))
15
+ assert session.save
16
+ end
17
+
18
+ test "cannot save a session without a user" do
19
+ assert_raise do
20
+ # Fails because no user has been passed in.
21
+ Session.new()
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ module RailsIdentity
4
+ class UserTest < ActiveSupport::TestCase
5
+ test "user is not valid without a username" do
6
+ user = User.new(password: "secret")
7
+ assert_not user.save
8
+ end
9
+
10
+ test "user is not valid without a password" do
11
+ user = User.new(username: "foo@example.com")
12
+ assert_not user.save
13
+ end
14
+
15
+ test "user is valid with username and password" do
16
+ user = User.new(username: "foo@example.com", password: "secret")
17
+ assert user.save
18
+ assert_not_nil user.verification_token
19
+ assert_nil user.reset_token
20
+ end
21
+
22
+ test "user can issue a reset token" do
23
+ user = User.new(username: "foo@example.com", password: "secret")
24
+ assert user.save
25
+ assert_nil user.reset_token
26
+ user.issue_token(:reset_token)
27
+ assert_not_nil user.reset_token
28
+ end
29
+
30
+ test "user can issue a verification token" do
31
+ user = User.new(username: "foo@example.com", password: "secret")
32
+ assert user.save
33
+ old = user.verification_token
34
+ user.issue_token(:verification_token)
35
+ assert_not_equal old, user.verification_token
36
+ end
37
+
38
+ test "user is not valid if username is malformatted" do
39
+ user = User.new(username: "example.com", password: "secret")
40
+ assert_not user.save
41
+ end
42
+
43
+ test "user is not valid if username already exists" do
44
+ user = User.new(username: "one@example.com", password: "secret")
45
+ assert_not user.save
46
+ end
47
+
48
+ test "user has a role of 100 by default" do
49
+ user = User.new(username: "new@example.com", password: "secret")
50
+ user.save
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class RailsIdentityTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, RailsIdentity
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ # Coveralls.wear!('rails')
8
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ Coveralls::SimpleCov::Formatter
11
+ ])
12
+ SimpleCov.start do
13
+ add_group "Models", "app/models"
14
+ add_group "Controllers", "app/controllers"
15
+ end
16
+
17
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
18
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
19
+ ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
20
+ require "rails/test_help"
21
+
22
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
23
+ # to be shown.
24
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
25
+
26
+ # Load support files
27
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
28
+
29
+ # Load fixtures from the engine
30
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
31
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
32
+ ActiveSupport::TestCase.fixtures :all
33
+ end