people_user_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/people/account.js +2 -0
  5. data/app/assets/javascripts/people/application.js +13 -0
  6. data/app/assets/stylesheets/people/account.css +7 -0
  7. data/app/assets/stylesheets/people/application.css +15 -0
  8. data/app/assets/stylesheets/scaffold.css +56 -0
  9. data/app/controllers/people/account_controller.rb +86 -0
  10. data/app/controllers/people/api/v1/application_controller.rb +5 -0
  11. data/app/controllers/people/api/v1/authentication_controller.rb +140 -0
  12. data/app/controllers/people/api/v1/users_controller.rb +120 -0
  13. data/app/controllers/people/application_controller.rb +4 -0
  14. data/app/helpers/people/account_helper.rb +4 -0
  15. data/app/helpers/people/application_helper.rb +4 -0
  16. data/app/helpers/people/users_helper.rb +4 -0
  17. data/app/mailers/people/account_mailer.rb +68 -0
  18. data/app/models/people/email_hash.rb +44 -0
  19. data/app/models/people/user.rb +9 -0
  20. data/app/models/people/v1/user.rb +54 -0
  21. data/app/serializers/people/v1/user_serializer.rb +61 -0
  22. data/app/views/layouts/people/application.html.erb +14 -0
  23. data/app/views/layouts/people/default/application.html.erb +14 -0
  24. data/app/views/people/account/changed_password.html.erb +3 -0
  25. data/app/views/people/account/email_confirm.html.erb +3 -0
  26. data/app/views/people/account/forgotten_password.html.erb +12 -0
  27. data/app/views/people/account/new_password.html.erb +25 -0
  28. data/app/views/people/account/posted_email_sent.html.erb +3 -0
  29. data/app/views/people/account_mailer/email_confirmation.html.erb +14 -0
  30. data/app/views/people/account_mailer/email_confirmation.text.erb +5 -0
  31. data/app/views/people/account_mailer/forgot_password.html.erb +15 -0
  32. data/app/views/people/account_mailer/forgot_password.text.erb +8 -0
  33. data/app/views/people/account_mailer/password_reset.html.erb +10 -0
  34. data/app/views/people/account_mailer/password_reset.text.erb +3 -0
  35. data/app/views/people/account_mailer/unlock_account.html.erb +14 -0
  36. data/app/views/people/account_mailer/unlock_account.text.erb +7 -0
  37. data/app/views/people/account_mailer/welcome_email.html.erb +15 -0
  38. data/app/views/people/account_mailer/welcome_email.text.erb +6 -0
  39. data/app/views/people/account_mailer/you_confirmed_email.html.erb +10 -0
  40. data/app/views/people/account_mailer/you_confirmed_email.text.erb +3 -0
  41. data/config/routes.rb +29 -0
  42. data/db/migrate/20141021150908_create_people_users.rb +13 -0
  43. data/db/migrate/20141022145945_create_people_email_hashes.rb +11 -0
  44. data/db/migrate/20141022161442_add_confirmed_to_people_users.rb +5 -0
  45. data/db/migrate/20141022161524_add_locked_to_people_users.rb +5 -0
  46. data/db/migrate/20141022161543_add_attempts_to_people_users.rb +5 -0
  47. data/db/migrate/20141023203747_remove_hash_from_people_email_hash.rb +5 -0
  48. data/db/migrate/20141023203806_add_token_to_people_email_hash.rb +5 -0
  49. data/db/migrate/20141024042651_remove_type_from_people_email_hash.rb +5 -0
  50. data/db/migrate/20141024042708_add_email_type_to_people_email_hash.rb +5 -0
  51. data/lib/generators/people/admin/USAGE +8 -0
  52. data/lib/generators/people/admin/admin_generator.rb +17 -0
  53. data/lib/generators/people/admin/templates/active_admin.rb +100 -0
  54. data/lib/generators/people/admin/templates/email_hash.rb +82 -0
  55. data/lib/generators/people/all/USAGE +8 -0
  56. data/lib/generators/people/all/all_generator.rb +18 -0
  57. data/lib/generators/people/authorizations/USAGE +8 -0
  58. data/lib/generators/people/authorizations/authorizations_generator.rb +19 -0
  59. data/lib/generators/people/authorizations/templates/authentication_authorization.rb +25 -0
  60. data/lib/generators/people/authorizations/templates/authorization.rb +106 -0
  61. data/lib/generators/people/tests/USAGE +8 -0
  62. data/lib/generators/people/tests/templates/account_routing.rb +37 -0
  63. data/lib/generators/people/tests/templates/authentication_requests.rb +166 -0
  64. data/lib/generators/people/tests/templates/authentication_routing.rb +37 -0
  65. data/lib/generators/people/tests/templates/email_hash_factory.rb +7 -0
  66. data/lib/generators/people/tests/templates/email_hash_model.rb +14 -0
  67. data/lib/generators/people/tests/templates/email_hash_request.rb +174 -0
  68. data/lib/generators/people/tests/templates/factory.rb +17 -0
  69. data/lib/generators/people/tests/templates/models.rb +61 -0
  70. data/lib/generators/people/tests/templates/requests.rb +180 -0
  71. data/lib/generators/people/tests/templates/routing.rb +47 -0
  72. data/lib/generators/people/tests/tests_generator.rb +25 -0
  73. data/lib/people.rb +4 -0
  74. data/lib/people/engine.rb +5 -0
  75. data/lib/people/version.rb +3 -0
  76. data/lib/tasks/people_tasks.rake +4 -0
  77. data/test/controllers/people/account_controller_test.rb +21 -0
  78. data/test/controllers/people/users_controller_test.rb +51 -0
  79. data/test/dummy/README.rdoc +28 -0
  80. data/test/dummy/Rakefile +6 -0
  81. data/test/dummy/app/assets/javascripts/application.js +13 -0
  82. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  83. data/test/dummy/app/controllers/application_controller.rb +5 -0
  84. data/test/dummy/app/helpers/application_helper.rb +2 -0
  85. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  86. data/test/dummy/bin/bundle +3 -0
  87. data/test/dummy/bin/rails +4 -0
  88. data/test/dummy/bin/rake +4 -0
  89. data/test/dummy/config.ru +4 -0
  90. data/test/dummy/config/application.rb +23 -0
  91. data/test/dummy/config/boot.rb +5 -0
  92. data/test/dummy/config/database.yml +25 -0
  93. data/test/dummy/config/environment.rb +5 -0
  94. data/test/dummy/config/environments/development.rb +29 -0
  95. data/test/dummy/config/environments/production.rb +80 -0
  96. data/test/dummy/config/environments/test.rb +36 -0
  97. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  98. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  99. data/test/dummy/config/initializers/inflections.rb +16 -0
  100. data/test/dummy/config/initializers/mime_types.rb +5 -0
  101. data/test/dummy/config/initializers/secret_token.rb +12 -0
  102. data/test/dummy/config/initializers/session_store.rb +3 -0
  103. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  104. data/test/dummy/config/locales/en.yml +23 -0
  105. data/test/dummy/config/routes.rb +4 -0
  106. data/test/dummy/db/development.sqlite3 +0 -0
  107. data/test/dummy/db/schema.rb +38 -0
  108. data/test/dummy/log/development.log +122 -0
  109. data/test/dummy/public/404.html +58 -0
  110. data/test/dummy/public/422.html +58 -0
  111. data/test/dummy/public/500.html +57 -0
  112. data/test/dummy/public/favicon.ico +0 -0
  113. data/test/fixtures/people/email_hashes.yml +11 -0
  114. data/test/fixtures/people/users.yml +11 -0
  115. data/test/helpers/people/account_helper_test.rb +6 -0
  116. data/test/helpers/people/users_helper_test.rb +6 -0
  117. data/test/integration/navigation_test.rb +10 -0
  118. data/test/mailers/people/account_mailer_test.rb +9 -0
  119. data/test/mailers/previews/people/account_mailer_preview.rb +6 -0
  120. data/test/models/people/email_hash_test.rb +9 -0
  121. data/test/models/people/user_test.rb +9 -0
  122. data/test/people_test.rb +7 -0
  123. data/test/test_helper.rb +15 -0
  124. metadata +353 -0
@@ -0,0 +1,15 @@
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>Welcome!</h1>
8
+ <p>
9
+ You have successfully signed up and your
10
+ your email is: <%= @user.email %>.<br>
11
+ </p>
12
+
13
+ <p>Thanks for joining and have a great day!</p>
14
+ </body>
15
+ </html>
@@ -0,0 +1,6 @@
1
+ Welcome!
2
+
3
+ You have successfully signed up and your
4
+ your email is: <%= @user.email %>
5
+
6
+ Thanks for joining and have a great day!
@@ -0,0 +1,10 @@
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>Email confirmed!</h1><br>
8
+ <p>Your email address is confirmed.</p>
9
+ </body>
10
+ </html>
@@ -0,0 +1,3 @@
1
+ Email confirmed!
2
+
3
+ Your email address is confirmed.
data/config/routes.rb ADDED
@@ -0,0 +1,29 @@
1
+ People::Engine.routes.draw do
2
+
3
+ root to: "users#index"
4
+
5
+ get 'account/email_confirm'
6
+ get 'account/forgotten_password'
7
+ post 'account/posted_email'
8
+ get 'account/new_password'
9
+ post 'account/change_password'
10
+
11
+ scope 'api' do
12
+ scope '1' do
13
+ # /api/1/authentication/register
14
+ post 'authentication/register', to: "api/v1/authentication#register"
15
+ # /api/1/authentication/login
16
+ post 'authentication/login', to: "api/v1/authentication#login"
17
+ # /api/1/authentication/logout
18
+ post 'authentication/logout', to: "api/v1/authentication#logout"
19
+ # /api/1/authentication/logout
20
+ post 'authentication/authenticate', to: "api/v1/authentication#authenticate"
21
+ # /api/1/authentication/login_status
22
+ get 'authentication/login_status', to: "api/v1/authentication#login_status"
23
+ resources :users, except: [:new, :edit, :create], controller: 'api/v1/users'
24
+ # Register handles the creation of users
25
+ post 'users', to: 'api/v1/authentication#register'
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePeopleUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :people_users do |t|
4
+ t.string :username
5
+ t.string :email
6
+ t.string :password_digest
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :people_users, :username, unique: true
11
+ add_index :people_users, :email, unique: true
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class CreatePeopleEmailHashes < ActiveRecord::Migration
2
+ def change
3
+ create_table :people_email_hashes do |t|
4
+ t.integer :user_id
5
+ t.string :hash
6
+ t.integer :type
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class AddConfirmedToPeopleUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :people_users, :confirmed, :boolean
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddLockedToPeopleUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :people_users, :locked, :boolean
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddAttemptsToPeopleUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :people_users, :attempts, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveHashFromPeopleEmailHash < ActiveRecord::Migration
2
+ def change
3
+ remove_column :people_email_hashes, :hash, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddTokenToPeopleEmailHash < ActiveRecord::Migration
2
+ def change
3
+ add_column :people_email_hashes, :token, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveTypeFromPeopleEmailHash < ActiveRecord::Migration
2
+ def change
3
+ remove_column :people_email_hashes, :type, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddEmailTypeToPeopleEmailHash < ActiveRecord::Migration
2
+ def change
3
+ add_column :people_email_hashes, :email_type, :integer
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate admin Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,17 @@
1
+ module People
2
+ class AdminGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def sprint
6
+ make_admin
7
+ end
8
+
9
+ private
10
+
11
+ def make_admin
12
+ template "active_admin.rb", "app/admin/people_user.rb"
13
+ template "email_hash.rb", "app/admin/people_email_hash.rb"
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,100 @@
1
+ ActiveAdmin.register People::User do
2
+
3
+ menu :label => "Users"
4
+ config.per_page = 30
5
+
6
+ =begin
7
+ batch_action :flag do |selection|
8
+ People::User.find(selection).each { |p| p.flag! }
9
+ redirect_to collection_path, :notice => "Users flagged!"
10
+ end
11
+ =end
12
+
13
+ form do |f|
14
+ f.semantic_errors # shows errors on :base
15
+ #f.inputs # builds an input field for every attribute
16
+ f.inputs do
17
+ f.input :id
18
+ f.input :username
19
+ f.input :email
20
+ f.input :password
21
+ f.input :password_confirmation
22
+ f.input :locked
23
+ f.input :confirmed
24
+ f.input :attempts
25
+ f.input :updated_at
26
+ f.input :created_at
27
+ end
28
+ f.actions # adds the 'Submit' and 'Cancel' buttons
29
+ end
30
+
31
+ controller do
32
+ def create
33
+ @user = ::People::V1::User.new(user_params)
34
+ if @user.save
35
+ flash[:notice] = "Created Successfully!"
36
+ redirect_to resource_path @user
37
+ else
38
+ flash[:notice] = "#{@user.errors.full_messages}"
39
+ redirect_to new_resource_path @user
40
+ #super
41
+ #render :new
42
+ end
43
+ end
44
+
45
+ def update
46
+ @user = ::People::V1::User.find(params[:id])
47
+ if @user.update(user_params)
48
+ flash[:notice] = "Updated Successfully!"
49
+ redirect_to resource_path @user
50
+ else
51
+ flash.now[:notice] = "#{@user.errors.full_messages}"
52
+ render :edit
53
+ #super
54
+ end
55
+ end
56
+
57
+ def destroy
58
+ @user = ::People::V1::User.find(params[:id])
59
+ @user.destroy
60
+ flash.now[:notice] = "Deleted Successfully!"
61
+ render :index
62
+ end
63
+
64
+ private
65
+
66
+ def user_params
67
+ params.require(:user).permit(:username,:email,:password,:password_confirmation,:locked,:confirmed,:attempts)
68
+ end
69
+ end
70
+
71
+ index do
72
+ selectable_column
73
+ column :id
74
+ column :username
75
+ column :email
76
+ column :password_digest
77
+ column :locked
78
+ column :confirmed
79
+ column :attempts
80
+ column :updated_at
81
+ column :created_at
82
+ actions
83
+ end
84
+
85
+ show do
86
+ attributes_table do
87
+ row :id
88
+ row :username
89
+ row :email
90
+ row :password_digest
91
+ row :locked
92
+ row :confirmed
93
+ row :attempts
94
+ row :updated_at
95
+ row :created_at
96
+ end
97
+ end
98
+
99
+
100
+ end
@@ -0,0 +1,82 @@
1
+ ActiveAdmin.register People::EmailHash do
2
+
3
+ menu :label => "EmailHashes"
4
+ config.per_page = 30
5
+
6
+ form do |f|
7
+ f.semantic_errors # shows errors on :base
8
+ #f.inputs # builds an input field for every attribute
9
+ f.inputs do
10
+ f.input :id
11
+ f.input :token
12
+ f.input :user_id
13
+ f.input :email_type
14
+ f.input :updated_at
15
+ f.input :created_at
16
+ end
17
+ f.actions # adds the 'Submit' and 'Cancel' buttons
18
+ end
19
+
20
+ controller do
21
+ def create
22
+ @email_hash = ::People::EmailHash.new(email_hash_params)
23
+ if @email_hash.save
24
+ flash[:notice] = "Created Successfully!"
25
+ redirect_to resource_path @email_hash
26
+ else
27
+ flash[:notice] = "#{@email_hash.errors.full_messages}"
28
+ redirect_to new_resource_path @email_hash
29
+ #super
30
+ #render :new
31
+ end
32
+ end
33
+
34
+ def update
35
+ @email_hash = ::People::EmailHash.find(params[:id])
36
+ if @email_hash.update(email_hash_params)
37
+ flash[:notice] = "Updated Successfully!"
38
+ redirect_to resource_path @email_hash
39
+ else
40
+ flash.now[:notice] = "#{@email_hash.errors.full_messages}"
41
+ render :edit
42
+ #super
43
+ end
44
+ end
45
+
46
+ def destroy
47
+ @email_hash = ::People::EmailHash.find(params[:id])
48
+ @email_hash.destroy
49
+ flash.now[:notice] = "Deleted Successfully!"
50
+ render :index
51
+ end
52
+
53
+ private
54
+
55
+ def email_hash_params
56
+ params.require(:email_hash).permit(:token,:user_id,:email_type)
57
+ end
58
+ end
59
+
60
+ index do
61
+ column :id
62
+ column :token
63
+ column :email_type
64
+ column :user_id
65
+ column :updated_at
66
+ column :created_at
67
+ actions
68
+ end
69
+
70
+ show do
71
+ attributes_table do
72
+ row :id
73
+ row :token
74
+ row :email_type
75
+ row :user_id
76
+ row :updated_at
77
+ row :created_at
78
+ end
79
+ end
80
+
81
+
82
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate all Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,18 @@
1
+ module People
2
+ class AllGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def sprint
6
+ run_all_generators
7
+ end
8
+
9
+ private
10
+
11
+ def run_all_generators
12
+ run "rails g people:tests"
13
+ run "rails g people:authorizations"
14
+ run "rails g people:admin"
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate authorizations Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,19 @@
1
+ module People
2
+ class AuthorizationsGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def sprint
6
+ copy_authorization_files_over
7
+ prepend_file 'gems/authorization/lib/authorization.rb', "require \'authorization/people/v1/user\'\n"
8
+ prepend_file 'gems/authorization/lib/authorization.rb', "require \'authorization/people/v1/authentication\'\n"
9
+ end
10
+
11
+ private
12
+
13
+ def copy_authorization_files_over
14
+ template "authorization.rb", "gems/authorization/lib/authorization/people/v1/user.rb"
15
+ template "authentication_authorization.rb", "gems/authorization/lib/authorization/people/v1/authentication.rb"
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Authorization
2
+ module People
3
+ module V1
4
+ module Authentication
5
+
6
+ #Used in the controller
7
+
8
+ def self.register?
9
+ return true
10
+ end
11
+
12
+ def self.login?
13
+ return true
14
+ end
15
+
16
+ def self.logout?(tokenUser)
17
+ return true
18
+ end
19
+
20
+ private
21
+
22
+ end
23
+ end
24
+ end
25
+ end