simple_user 0.1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +35 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/simple_user/application.js +15 -0
  6. data/app/assets/javascripts/simple_user/facebook_connect.js.erb +33 -0
  7. data/app/assets/stylesheets/simple_user/application.css +13 -0
  8. data/app/controllers/simple_user/admin_users/registrations_controller.rb +7 -0
  9. data/app/controllers/simple_user/admin_users/sessions_controller.rb +20 -0
  10. data/app/controllers/simple_user/admin_users_controller.rb +134 -0
  11. data/app/controllers/simple_user/application_controller.rb +7 -0
  12. data/app/controllers/simple_user/auth_controller.rb +26 -0
  13. data/app/controllers/simple_user/users/registrations_controller.rb +5 -0
  14. data/app/controllers/simple_user/users/sessions_controller.rb +41 -0
  15. data/app/controllers/simple_user/users_controller.rb +88 -0
  16. data/app/helpers/simple_user/application_helper.rb +13 -0
  17. data/app/helpers/simple_user/links_helper.rb +9 -0
  18. data/app/models/ability.rb +25 -0
  19. data/app/models/role.rb +18 -0
  20. data/app/models/simple_user/admin_user.rb +48 -0
  21. data/app/models/simple_user/authentication.rb +9 -0
  22. data/app/models/simple_user/user.rb +92 -0
  23. data/app/views/layouts/simple_user/application.html.erb +28 -0
  24. data/app/views/simple_user/admin_users/_form.html.erb +15 -0
  25. data/app/views/simple_user/admin_users/confirmations/new.html.erb +16 -0
  26. data/app/views/simple_user/admin_users/edit.html.erb +6 -0
  27. data/app/views/simple_user/admin_users/index.html.erb +27 -0
  28. data/app/views/simple_user/admin_users/mailer/confirmation_instructions.html.erb +5 -0
  29. data/app/views/simple_user/admin_users/mailer/reset_password_instructions.html.erb +8 -0
  30. data/app/views/simple_user/admin_users/mailer/unlock_instructions.html.erb +7 -0
  31. data/app/views/simple_user/admin_users/new.html.erb +5 -0
  32. data/app/views/simple_user/admin_users/passwords/edit.html.erb +19 -0
  33. data/app/views/simple_user/admin_users/passwords/new.html.erb +15 -0
  34. data/app/views/simple_user/admin_users/registrations/edit.html.erb +28 -0
  35. data/app/views/simple_user/admin_users/registrations/new.html.erb +18 -0
  36. data/app/views/simple_user/admin_users/sessions/new.html.erb +15 -0
  37. data/app/views/simple_user/admin_users/shared/_links.erb +25 -0
  38. data/app/views/simple_user/admin_users/show.html.erb +15 -0
  39. data/app/views/simple_user/admin_users/unlocks/new.html.erb +16 -0
  40. data/app/views/simple_user/application/_menu_admin_users.html.erb +15 -0
  41. data/app/views/simple_user/application/_menu_users.html.erb +9 -0
  42. data/app/views/simple_user/users/_form.html.erb +14 -0
  43. data/app/views/simple_user/users/confirmations/new.html.erb +16 -0
  44. data/app/views/simple_user/users/edit.html.erb +6 -0
  45. data/app/views/simple_user/users/index.html.erb +31 -0
  46. data/app/views/simple_user/users/mailer/confirmation_instructions.html.erb +5 -0
  47. data/app/views/simple_user/users/mailer/reset_password_instructions.html.erb +8 -0
  48. data/app/views/simple_user/users/mailer/unlock_instructions.html.erb +7 -0
  49. data/app/views/simple_user/users/new.html.erb +5 -0
  50. data/app/views/simple_user/users/passwords/edit.html.erb +19 -0
  51. data/app/views/simple_user/users/passwords/new.html.erb +15 -0
  52. data/app/views/simple_user/users/registrations/edit.html.erb +30 -0
  53. data/app/views/simple_user/users/registrations/new.html.erb +20 -0
  54. data/app/views/simple_user/users/sessions/new.html.erb +15 -0
  55. data/app/views/simple_user/users/shared/_links.erb +25 -0
  56. data/app/views/simple_user/users/show.html.erb +25 -0
  57. data/app/views/simple_user/users/unlocks/new.html.erb +16 -0
  58. data/config/initializers/devise.rb +243 -0
  59. data/config/initializers/omniauth.rb +7 -0
  60. data/config/initializers/rolify.rb +8 -0
  61. data/config/locales/devise.en.yml +59 -0
  62. data/config/routes.rb +39 -0
  63. data/db/migrate/20130312215459_devise_create_simple_user_users.rb +50 -0
  64. data/db/migrate/20130312215519_devise_create_simple_user_admin_users.rb +48 -0
  65. data/db/migrate/20130312215950_create_simple_user_authentications.rb +13 -0
  66. data/db/migrate/20130312226960_rolify_create_roles.rb +19 -0
  67. data/db/seed.rb +9 -0
  68. data/lib/generators/simple_user/generate_views/generate_views_generator.rb +12 -0
  69. data/lib/generators/simple_user/install/install_generator.rb +20 -0
  70. data/lib/generators/simple_user/install/templates/devise_config.yml +1 -0
  71. data/lib/generators/simple_user/install/templates/fb_config.yml +3 -0
  72. data/lib/generators/simple_user/install/templates/simple_user.yml +3 -0
  73. data/lib/simple_user.rb +4 -0
  74. data/lib/simple_user/engine.rb +48 -0
  75. data/lib/simple_user/version.rb +3 -0
  76. data/lib/tasks/simple_user_tasks.rake +16 -0
  77. data/test/dummy/README.rdoc +261 -0
  78. data/test/dummy/Rakefile +7 -0
  79. data/test/dummy/app/assets/javascripts/application.js +16 -0
  80. data/test/dummy/app/assets/javascripts/welcome.js +2 -0
  81. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  82. data/test/dummy/app/assets/stylesheets/welcome.css +4 -0
  83. data/test/dummy/app/controllers/application_controller.rb +31 -0
  84. data/test/dummy/app/controllers/welcome_controller.rb +4 -0
  85. data/test/dummy/app/helpers/application_helper.rb +2 -0
  86. data/test/dummy/app/helpers/welcome_helper.rb +2 -0
  87. data/test/dummy/app/views/admin_users/_form.html.erb +15 -0
  88. data/test/dummy/app/views/admin_users/confirmations/new.html.erb +16 -0
  89. data/test/dummy/app/views/admin_users/edit.html.erb +6 -0
  90. data/test/dummy/app/views/admin_users/index.html.erb +27 -0
  91. data/test/dummy/app/views/admin_users/mailer/confirmation_instructions.html.erb +5 -0
  92. data/test/dummy/app/views/admin_users/mailer/reset_password_instructions.html.erb +8 -0
  93. data/test/dummy/app/views/admin_users/mailer/unlock_instructions.html.erb +7 -0
  94. data/test/dummy/app/views/admin_users/new.html.erb +5 -0
  95. data/test/dummy/app/views/admin_users/passwords/edit.html.erb +19 -0
  96. data/test/dummy/app/views/admin_users/passwords/new.html.erb +15 -0
  97. data/test/dummy/app/views/admin_users/registrations/edit.html.erb +28 -0
  98. data/test/dummy/app/views/admin_users/registrations/new.html.erb +18 -0
  99. data/test/dummy/app/views/admin_users/sessions/new.html.erb +15 -0
  100. data/test/dummy/app/views/admin_users/shared/_links.erb +25 -0
  101. data/test/dummy/app/views/admin_users/show.html.erb +15 -0
  102. data/test/dummy/app/views/admin_users/unlocks/new.html.erb +16 -0
  103. data/test/dummy/app/views/application/_menu_admin_users.html.erb +15 -0
  104. data/test/dummy/app/views/application/_menu_users.html.erb +9 -0
  105. data/test/dummy/app/views/layouts/application.html.erb +28 -0
  106. data/test/dummy/app/views/simple_user/admin_users/_form.html.erb +15 -0
  107. data/test/dummy/app/views/simple_user/admin_users/confirmations/new.html.erb +16 -0
  108. data/test/dummy/app/views/simple_user/admin_users/edit.html.erb +6 -0
  109. data/test/dummy/app/views/simple_user/admin_users/index.html.erb +27 -0
  110. data/test/dummy/app/views/simple_user/admin_users/mailer/confirmation_instructions.html.erb +5 -0
  111. data/test/dummy/app/views/simple_user/admin_users/mailer/reset_password_instructions.html.erb +8 -0
  112. data/test/dummy/app/views/simple_user/admin_users/mailer/unlock_instructions.html.erb +7 -0
  113. data/test/dummy/app/views/simple_user/admin_users/new.html.erb +5 -0
  114. data/test/dummy/app/views/simple_user/admin_users/passwords/edit.html.erb +19 -0
  115. data/test/dummy/app/views/simple_user/admin_users/passwords/new.html.erb +15 -0
  116. data/test/dummy/app/views/simple_user/admin_users/registrations/edit.html.erb +28 -0
  117. data/test/dummy/app/views/simple_user/admin_users/registrations/new.html.erb +18 -0
  118. data/test/dummy/app/views/simple_user/admin_users/sessions/new.html.erb +15 -0
  119. data/test/dummy/app/views/simple_user/admin_users/shared/_links.erb +25 -0
  120. data/test/dummy/app/views/simple_user/admin_users/show.html.erb +15 -0
  121. data/test/dummy/app/views/simple_user/admin_users/unlocks/new.html.erb +16 -0
  122. data/test/dummy/app/views/simple_user/application/_menu_admin_users.html.erb +15 -0
  123. data/test/dummy/app/views/simple_user/application/_menu_users.html.erb +9 -0
  124. data/test/dummy/app/views/simple_user/users/_form.html.erb +14 -0
  125. data/test/dummy/app/views/simple_user/users/confirmations/new.html.erb +16 -0
  126. data/test/dummy/app/views/simple_user/users/edit.html.erb +6 -0
  127. data/test/dummy/app/views/simple_user/users/index.html.erb +31 -0
  128. data/test/dummy/app/views/simple_user/users/mailer/confirmation_instructions.html.erb +5 -0
  129. data/test/dummy/app/views/simple_user/users/mailer/reset_password_instructions.html.erb +8 -0
  130. data/test/dummy/app/views/simple_user/users/mailer/unlock_instructions.html.erb +7 -0
  131. data/test/dummy/app/views/simple_user/users/new.html.erb +5 -0
  132. data/test/dummy/app/views/simple_user/users/passwords/edit.html.erb +19 -0
  133. data/test/dummy/app/views/simple_user/users/passwords/new.html.erb +15 -0
  134. data/test/dummy/app/views/simple_user/users/registrations/edit.html.erb +30 -0
  135. data/test/dummy/app/views/simple_user/users/registrations/new.html.erb +20 -0
  136. data/test/dummy/app/views/simple_user/users/sessions/new.html.erb +15 -0
  137. data/test/dummy/app/views/simple_user/users/shared/_links.erb +25 -0
  138. data/test/dummy/app/views/simple_user/users/show.html.erb +25 -0
  139. data/test/dummy/app/views/simple_user/users/unlocks/new.html.erb +16 -0
  140. data/test/dummy/app/views/welcome/index.html.erb +3 -0
  141. data/test/dummy/config.ru +4 -0
  142. data/test/dummy/config/application.rb +59 -0
  143. data/test/dummy/config/boot.rb +10 -0
  144. data/test/dummy/config/database.yml +25 -0
  145. data/test/dummy/config/devise_config.yml +1 -0
  146. data/test/dummy/config/environment.rb +5 -0
  147. data/test/dummy/config/environments/development.rb +37 -0
  148. data/test/dummy/config/environments/production.rb +67 -0
  149. data/test/dummy/config/environments/test.rb +37 -0
  150. data/test/dummy/config/fb_config.yml +3 -0
  151. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  152. data/test/dummy/config/initializers/inflections.rb +15 -0
  153. data/test/dummy/config/initializers/mime_types.rb +5 -0
  154. data/test/dummy/config/initializers/secret_token.rb +7 -0
  155. data/test/dummy/config/initializers/session_store.rb +8 -0
  156. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  157. data/test/dummy/config/locales/en.yml +5 -0
  158. data/test/dummy/config/routes.rb +7 -0
  159. data/test/dummy/db/development.sqlite3 +0 -0
  160. data/test/dummy/db/migrate/20130314021609_devise_create_simple_user_users.simple_user.rb +51 -0
  161. data/test/dummy/db/migrate/20130314021610_devise_create_simple_user_admin_users.simple_user.rb +49 -0
  162. data/test/dummy/db/migrate/20130314021611_create_simple_user_authentications.simple_user.rb +14 -0
  163. data/test/dummy/db/migrate/20130314021612_rolify_create_simple_user_roles.simple_user.rb +20 -0
  164. data/test/dummy/db/migrate/20130314222446_devise_create_simple_user_users.simple_user.rb +51 -0
  165. data/test/dummy/db/migrate/20130314222447_devise_create_simple_user_admin_users.simple_user.rb +49 -0
  166. data/test/dummy/db/migrate/20130314222448_create_simple_user_authentications.simple_user.rb +14 -0
  167. data/test/dummy/db/migrate/20130314222449_rolify_create_roles.simple_user.rb +20 -0
  168. data/test/dummy/db/schema.rb +87 -0
  169. data/test/dummy/log/development.log +100 -0
  170. data/test/dummy/public/404.html +26 -0
  171. data/test/dummy/public/422.html +26 -0
  172. data/test/dummy/public/500.html +25 -0
  173. data/test/dummy/public/favicon.ico +0 -0
  174. data/test/dummy/script/rails +6 -0
  175. data/test/dummy/test/functional/welcome_controller_test.rb +9 -0
  176. data/test/dummy/test/unit/helpers/welcome_helper_test.rb +4 -0
  177. data/test/dummy/tmp/cache/assets/C43/6A0/sprockets%2F9112a8a5c58f114023075f00ab994366 +0 -0
  178. data/test/dummy/tmp/cache/assets/C7B/190/sprockets%2F37b103f4623089af1456b90830fe941c +0 -0
  179. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  180. data/test/dummy/tmp/cache/assets/D13/C60/sprockets%2F2dedb8177c20286c4259c1d58c5646cc +0 -0
  181. data/test/dummy/tmp/cache/assets/D21/5D0/sprockets%2Fe2c4f946939f2d7d0b42d86383755cae +0 -0
  182. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  183. data/test/dummy/tmp/cache/assets/D3E/F40/sprockets%2F25a167c7563d6fe8ec6b13ec1ac09274 +0 -0
  184. data/test/dummy/tmp/cache/assets/D43/A50/sprockets%2Fa41b368b71464f0a4feb19b6f875e44e +0 -0
  185. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  186. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  187. data/test/dummy/tmp/cache/assets/D92/950/sprockets%2Fcda629d2e4e4583027facd41bf1ea406 +0 -0
  188. data/test/dummy/tmp/cache/assets/DA0/140/sprockets%2F25f485eb0a9f28b68e69ab1c0f57c0da +0 -0
  189. data/test/dummy/tmp/cache/assets/DCF/BD0/sprockets%2Fc8b53c6aae12e5a5be5fe8db5472a793 +0 -0
  190. data/test/dummy/tmp/cache/assets/DD2/810/sprockets%2Fdc8aca3689d6b6e14aa38b7c88a46bc3 +0 -0
  191. data/test/dummy/tmp/cache/assets/DD8/CE0/sprockets%2F5de7f141c1d9dc26ce8af1ad6246d99f +0 -0
  192. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  193. data/test/dummy/tmp/cache/assets/E02/930/sprockets%2Fec83bf6c33e43fb6a5cf38a52df8c60e +0 -0
  194. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  195. data/test/dummy/tmp/cache/assets/E2A/CE0/sprockets%2F17bd5e2fd8a5fd2d834c9dadfd102c2f +0 -0
  196. data/test/fixtures/simple_user/admin_users.yml +11 -0
  197. data/test/fixtures/simple_user/authentications.yml +13 -0
  198. data/test/fixtures/simple_user/users.yml +11 -0
  199. data/test/integration/navigation_test.rb +10 -0
  200. data/test/simple_user_test.rb +7 -0
  201. data/test/test_helper.rb +15 -0
  202. data/test/unit/simple_user/admin_user_test.rb +9 -0
  203. data/test/unit/simple_user/authentication_test.rb +9 -0
  204. data/test/unit/simple_user/user_test.rb +9 -0
  205. metadata +516 -0
@@ -0,0 +1,7 @@
1
+ module SimpleUser
2
+ OmniAuth.config.logger = Rails.logger
3
+
4
+ Rails.application.config.middleware.use OmniAuth::Builder do
5
+ provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], :scope => ENV['FACEBOOK_SCOPE']
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ Rolify.configure do |config|
2
+ # By default ORM adapter is ActiveRecord. uncomment to use mongoid
3
+ # config.use_mongoid
4
+
5
+ # Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
6
+ # Enable this feature _after_ running rake db:migrate as it relies on the roles table
7
+ # config.use_dynamic_shortcuts
8
+ end
@@ -0,0 +1,59 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ devise:
5
+ confirmations:
6
+ confirmed: "Your account was successfully confirmed. You are now signed in."
7
+ send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
8
+ send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
9
+ failure:
10
+ already_authenticated: "You are already signed in."
11
+ inactive: "Your account was not activated yet."
12
+ invalid: "Invalid email or password."
13
+ invalid_token: "Invalid authentication token."
14
+ locked: "Your account is locked."
15
+ not_found_in_database: "Invalid email or password."
16
+ timeout: "Your session expired, please sign in again to continue."
17
+ unauthenticated: "You need to sign in or sign up before continuing."
18
+ unconfirmed: "You have to confirm your account before continuing."
19
+ mailer:
20
+ confirmation_instructions:
21
+ subject: "Confirmation instructions"
22
+ reset_password_instructions:
23
+ subject: "Reset password instructions"
24
+ unlock_instructions:
25
+ subject: "Unlock Instructions"
26
+ omniauth_callbacks:
27
+ failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
28
+ success: "Successfully authenticated from %{kind} account."
29
+ passwords:
30
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
31
+ send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes."
32
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
33
+ updated: "Your password was changed successfully. You are now signed in."
34
+ updated_not_active: "Your password was changed successfully."
35
+ registrations:
36
+ destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
37
+ signed_up: "Welcome! You have signed up successfully."
38
+ signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
39
+ signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
40
+ signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
41
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
42
+ updated: "You updated your account successfully."
43
+ sessions:
44
+ signed_in: "Signed in successfully."
45
+ signed_out: "Signed out successfully."
46
+ unlocks:
47
+ send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
48
+ send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
49
+ unlocked: "Your account has been unlocked successfully. Please sign in to continue."
50
+ errors:
51
+ messages:
52
+ already_confirmed: "was already confirmed, please try signing in"
53
+ confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
54
+ expired: "has expired, please request a new one"
55
+ not_found: "not found"
56
+ not_locked: "was not locked"
57
+ not_saved:
58
+ one: "1 error prohibited this %{resource} from being saved:"
59
+ other: "%{count} errors prohibited this %{resource} from being saved:"
@@ -0,0 +1,39 @@
1
+ SimpleUser::Engine.routes.draw do
2
+
3
+ #Omniauth-Facebook for Users
4
+
5
+ #Opt 2
6
+ devise_for :users, {
7
+ class_name: 'SimpleUser::User',
8
+ path_names: {sign_in: "login", sign_out: "logout"},
9
+ :path => "u",
10
+ :controllers => { :registrations => "simple_user/users/registrations", :sessions => "simple_user/users/sessions" },
11
+ module: :devise
12
+ }
13
+
14
+ #Opt 1
15
+ #scope '/simple_user'
16
+ # devise_for :users, :class_name => "SimpleUser::User", path_names: {sign_in: "login", sign_out: "logout"}, :path => "u", :controllers => { :registrations => "users/registrations", :sessions => "users/sessions" }
17
+ #end
18
+
19
+ #Opt 0
20
+ #devise_for :users, :class_name => "SimpleUser::User", path_names: {sign_in: "login", sign_out: "logout"}, :path => "u", :controllers => { :registrations => "users/registrations", :sessions => "users/sessions" }
21
+ match 'auth/:provider/callback', to: 'auth#create'
22
+ match 'auth/failure', to: redirect('/')
23
+
24
+ #Management of Users
25
+ resources :users
26
+
27
+ #Devise for Admins
28
+ devise_for :admin_users, {
29
+ :class_name => "SimpleUser::AdminUser",
30
+ path_names: {sign_in: "login", sign_out: "logout"},
31
+ :path => "d",
32
+ :controllers => { :registrations => "simple_user/admin_users/registrations", :sessions => "simple_user/admin_users/sessions" },
33
+ module: :devise
34
+ }
35
+
36
+ #Management of Admins
37
+ resources :admin_users
38
+
39
+ end
@@ -0,0 +1,50 @@
1
+ class DeviseCreateSimpleUserUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:simple_user_users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Confirmable
23
+ # t.string :confirmation_token
24
+ # t.datetime :confirmed_at
25
+ # t.datetime :confirmation_sent_at
26
+ # t.string :unconfirmed_email # Only if using reconfirmable
27
+
28
+ ## Lockable
29
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
30
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
31
+ # t.datetime :locked_at
32
+
33
+ ## Token authenticatable
34
+ # t.string :authentication_token
35
+
36
+ t.string :first_name
37
+ t.string :last_name
38
+ t.string :username
39
+ t.boolean :active, :default => true
40
+
41
+ t.timestamps
42
+ end
43
+
44
+ add_index :simple_user_users, :email, :unique => true
45
+ add_index :simple_user_users, :reset_password_token, :unique => true
46
+ # add_index :simple_user_users, :confirmation_token, :unique => true
47
+ # add_index :simple_user_users, :unlock_token, :unique => true
48
+ # add_index :simple_user_users, :authentication_token, :unique => true
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ class DeviseCreateSimpleUserAdminUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:simple_user_admin_users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Confirmable
23
+ # t.string :confirmation_token
24
+ # t.datetime :confirmed_at
25
+ # t.datetime :confirmation_sent_at
26
+ # t.string :unconfirmed_email # Only if using reconfirmable
27
+
28
+ ## Lockable
29
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
30
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
31
+ # t.datetime :locked_at
32
+
33
+ ## Token authenticatable
34
+ # t.string :authentication_token
35
+
36
+ t.string :username
37
+ t.boolean :active, :default => true
38
+
39
+ t.timestamps
40
+ end
41
+
42
+ add_index :simple_user_admin_users, :email, :unique => true
43
+ add_index :simple_user_admin_users, :reset_password_token, :unique => true
44
+ # add_index :simple_user_admin_users, :confirmation_token, :unique => true
45
+ # add_index :simple_user_admin_users, :unlock_token, :unique => true
46
+ # add_index :simple_user_admin_users, :authentication_token, :unique => true
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ class CreateSimpleUserAuthentications < ActiveRecord::Migration
2
+ def change
3
+ create_table :simple_user_authentications do |t|
4
+ t.string :provider
5
+ t.string :token
6
+ t.string :uid
7
+ t.references :user
8
+
9
+ t.timestamps
10
+ end
11
+ add_index :simple_user_authentications, :user_id
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ class RolifyCreateRoles < ActiveRecord::Migration
2
+ def change
3
+ create_table(:roles) do |t|
4
+ t.string :name
5
+ t.references :resource, :polymorphic => true
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ create_table(:users_roles, :id => false) do |t|
11
+ t.references :simple_user_admin_user
12
+ t.references :role
13
+ end
14
+
15
+ add_index(:roles, :name)
16
+ add_index(:roles, [ :name, :resource_type, :resource_id ], :name => "roles_n_rt_rid")
17
+ add_index(:users_roles, [ :simple_user_admin_user_id, :role_id ], :name => "user_role_i_auid_urid")
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ admin_user = SimpleUser::AdminUser.new(
2
+ :username => "admin",
3
+ :email => "admin@example.com",
4
+ :password => "welcome123",
5
+ :password_confirmation => "welcome123"
6
+ )
7
+ admin_user.save
8
+
9
+ admin_user.add_role "admin"
@@ -0,0 +1,12 @@
1
+ module SimpleUser
2
+ module Generators
3
+ class GenerateViewsGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("../../../../../app/views", __FILE__)
5
+ desc "Generate Views of Simple User"
6
+
7
+ def copy_views
8
+ directory "simple_user", "app/views/simple_user"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module SimpleUser
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ desc "Install SimpleUser"
6
+
7
+ def copy_config_file
8
+ copy_file "fb_config.yml", "config/fb_config.yml"
9
+ copy_file "devise_config.yml", "config/devise_config.yml"
10
+ copy_file "simple_user.yml", "config/simple_user.yml"
11
+ end
12
+
13
+ def copy_migrations
14
+ rake "simple_user:install:migrations"
15
+ SimpleUser::Engine.load_seed
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ SU_MAILER_SENDER: "change-me@example.com"
@@ -0,0 +1,3 @@
1
+ FACEBOOK_KEY: your_app_key
2
+ FACEBOOK_SECRET: your_app_secret
3
+ FACEBOOK_SCOPE: 'email, user_birthday'
@@ -0,0 +1,3 @@
1
+ APPLICATION_LAYOUT: 'application'
2
+ ADMIN_LAYOUT: 'application'
3
+ ADMIN_PATH: '/'
@@ -0,0 +1,4 @@
1
+ require "simple_user/engine"
2
+
3
+ module SimpleUser
4
+ end
@@ -0,0 +1,48 @@
1
+ module SimpleUser
2
+
3
+ require 'rubygems'
4
+ require 'devise'
5
+ require 'cancan'
6
+ require 'rolify'
7
+ require 'omniauth'
8
+ require 'omniauth-facebook'
9
+ require 'simple_form'
10
+
11
+ class Engine < ::Rails::Engine
12
+ isolate_namespace SimpleUser
13
+
14
+ config.generators.load_generators
15
+
16
+ config.before_configuration do
17
+ env_file = File.join(Rails.root, 'config', 'fb_config.yml')
18
+ YAML.load(File.open(env_file)).each do |key, value|
19
+ ENV[key.to_s] = value.to_s
20
+ end if File.exists?(env_file)
21
+
22
+ env_file = File.join(Rails.root, 'config', 'devise_config.yml')
23
+ YAML.load(File.open(env_file)).each do |key, value|
24
+ ENV[key.to_s] = value.to_s
25
+ end if File.exists?(env_file)
26
+
27
+ env_file = File.join(Rails.root, 'config', 'simple_user.yml')
28
+ YAML.load(File.open(env_file)).each do |key, value|
29
+ ENV[key.to_s] = value.to_s
30
+ end if File.exists?(env_file)
31
+ end
32
+
33
+ initializer 'simple_user.action_controller' do |app|
34
+ ActiveSupport.on_load :action_controller do
35
+ helper SimpleUser::ApplicationHelper
36
+ end
37
+ end
38
+
39
+ #config.to_prepare do
40
+ # ApplicationController.helper(ApplicationHelper)
41
+ #end
42
+
43
+ middleware.use OmniAuth::Builder do
44
+ provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], :scope => ENV['FACEBOOK_SCOPE']
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleUser
2
+ VERSION = "0.1.3.2"
3
+ end
@@ -0,0 +1,16 @@
1
+ namespace :simple_user do
2
+ Rake::Task['db:seed'].enhance ['simple_user:load_first_admin']
3
+
4
+ desc "Loads first admin into DB"
5
+ task :load_first_admin => :environment do
6
+ admin_user = SimpleUser::AdminUser.new(
7
+ :username => "admin",
8
+ :email => "admin@example.com",
9
+ :password => "welcome123",
10
+ :password_confirmation => "welcome123"
11
+ )
12
+ admin_user.save
13
+
14
+ admin_user.add_role "admin"
15
+ end
16
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | |-- images
161
+ | |-- javascripts
162
+ | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | `-- tasks
177
+ |-- log
178
+ |-- public
179
+ |-- script
180
+ |-- test
181
+ | |-- fixtures
182
+ | |-- functional
183
+ | |-- integration
184
+ | |-- performance
185
+ | `-- unit
186
+ |-- tmp
187
+ | |-- cache
188
+ | |-- pids
189
+ | |-- sessions
190
+ | `-- sockets
191
+ `-- vendor
192
+ |-- assets
193
+ `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.