genkan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +94 -0
  4. data/Rakefile +26 -0
  5. data/app/controllers/concerns/genkan/authenticatable.rb +29 -0
  6. data/app/controllers/concerns/genkan/helper.rb +18 -0
  7. data/app/controllers/genkan/application_controller.rb +7 -0
  8. data/app/controllers/genkan/sessions_controller.rb +50 -0
  9. data/app/models/concerns/genkan/auth.rb +78 -0
  10. data/app/models/genkan/application_record.rb +5 -0
  11. data/config/locales/en.yml +11 -0
  12. data/config/locales/ja.yml +11 -0
  13. data/config/routes.rb +6 -0
  14. data/lib/generators/genkan/USAGE +9 -0
  15. data/lib/generators/genkan/helper.rb +57 -0
  16. data/lib/generators/genkan/install_generator.rb +45 -0
  17. data/lib/generators/genkan/templates/initializer.erb +21 -0
  18. data/lib/generators/genkan/templates/migration.erb +17 -0
  19. data/lib/generators/genkan/templates/model.erb +3 -0
  20. data/lib/generators/genkan/templates/view.erb +3 -0
  21. data/lib/genkan/config.rb +22 -0
  22. data/lib/genkan/engine.rb +13 -0
  23. data/lib/genkan/version.rb +3 -0
  24. data/lib/genkan.rb +12 -0
  25. data/lib/tasks/genkan_tasks.rake +4 -0
  26. data/spec/controllers/genkan/sessions_controller_spec.rb +74 -0
  27. data/spec/controllers/welcome_controller_spec.rb +26 -0
  28. data/spec/dummy/Rakefile +6 -0
  29. data/spec/dummy/app/assets/config/manifest.js +4 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  31. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  32. data/spec/dummy/app/assets/javascripts/welcome.js +2 -0
  33. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  34. data/spec/dummy/app/assets/stylesheets/welcome.css +4 -0
  35. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  36. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  37. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  38. data/spec/dummy/app/controllers/welcome_controller.rb +4 -0
  39. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  40. data/spec/dummy/app/helpers/welcome_helper.rb +2 -0
  41. data/spec/dummy/app/jobs/application_job.rb +2 -0
  42. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  43. data/spec/dummy/app/models/application_record.rb +3 -0
  44. data/spec/dummy/app/models/user.rb +3 -0
  45. data/spec/dummy/app/views/genkan/sessions/new.html.erb +3 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +21 -0
  47. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  48. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  49. data/spec/dummy/app/views/welcome/index.html.erb +2 -0
  50. data/spec/dummy/bin/bundle +3 -0
  51. data/spec/dummy/bin/rails +4 -0
  52. data/spec/dummy/bin/rake +4 -0
  53. data/spec/dummy/bin/setup +38 -0
  54. data/spec/dummy/bin/update +29 -0
  55. data/spec/dummy/bin/yarn +11 -0
  56. data/spec/dummy/config/application.rb +18 -0
  57. data/spec/dummy/config/boot.rb +5 -0
  58. data/spec/dummy/config/cable.yml +10 -0
  59. data/spec/dummy/config/database.yml +25 -0
  60. data/spec/dummy/config/environment.rb +5 -0
  61. data/spec/dummy/config/environments/development.rb +54 -0
  62. data/spec/dummy/config/environments/production.rb +91 -0
  63. data/spec/dummy/config/environments/test.rb +42 -0
  64. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  65. data/spec/dummy/config/initializers/assets.rb +14 -0
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  67. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  69. data/spec/dummy/config/initializers/genkan.rb +16 -0
  70. data/spec/dummy/config/initializers/inflections.rb +16 -0
  71. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  72. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  73. data/spec/dummy/config/locales/en.yml +33 -0
  74. data/spec/dummy/config/puma.rb +56 -0
  75. data/spec/dummy/config/routes.rb +6 -0
  76. data/spec/dummy/config/secrets.yml +32 -0
  77. data/spec/dummy/config/spring.rb +6 -0
  78. data/spec/dummy/config.ru +5 -0
  79. data/spec/dummy/db/development.sqlite3 +0 -0
  80. data/spec/dummy/db/migrate/20170705145634_create_users.rb +17 -0
  81. data/spec/dummy/db/schema.rb +26 -0
  82. data/spec/dummy/db/test.sqlite3 +0 -0
  83. data/spec/dummy/log/development.log +106 -0
  84. data/spec/dummy/log/test.log +21007 -0
  85. data/spec/dummy/package.json +5 -0
  86. data/spec/dummy/public/404.html +67 -0
  87. data/spec/dummy/public/422.html +67 -0
  88. data/spec/dummy/public/500.html +66 -0
  89. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  90. data/spec/dummy/public/apple-touch-icon.png +0 -0
  91. data/spec/dummy/public/favicon.ico +0 -0
  92. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-a/-anb1le1UfL1rAsfL6vauFV9hAwJ5gMXKUu3xL08kUk.cache +1 -0
  93. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-z/-zggpD8P_aYMr6NLbWRYgnYvBbziQZBeEx1PktCGEXI.cache +2 -0
  94. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0g/0g2prc3JF5Bmp09lvpxf98IkTOH2vTxfSTcGrRF7tDY.cache +2 -0
  95. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0j/0j0It68B_34E2bHwElTlWS0Y6kgaf45ST90payRW4Jo.cache +1 -0
  96. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2S/2SUXxOYN50uS4DQcyysYjnfZtLXl9Hlk0t2N9SgLB0Q.cache +0 -0
  97. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/3a/3azp7y1RT8w2JtT4ezvBIXEk5T85Hn6MyEi8d0vG8y4.cache +2 -0
  98. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4p/4pPp889DYAQDA_jytD7lOck7mxgU0Yd6fnfZHXLdoCc.cache +0 -0
  99. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5J/5JNEPK3X_MzDSfrmiIhbHj9YsSU_eVLAbgBHdiTrNi8.cache +0 -0
  100. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5L/5LHD8D4FTU8esjUNnebxaJfBYlkScZM7mfUgifmcKXs.cache +2 -0
  101. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/5k/5k0_mK4ah0LyKz_V0L5ewQW69uKcg4AXcfFYl11LkkU.cache +2 -0
  102. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/60/60UFBuw-joBLVwC7c_zp0kSHY1eFbRwZ_6dtpqrfqgE.cache +1 -0
  103. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6L/6LWZEU7dfxLMlAZC0dbWyFfAjZ4osHIEWZa3S944n3s.cache +0 -0
  104. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6O/6OiuoEFcjfdg_T6P3vVSAbv8GEikjkFbJzAPqcjjIBQ.cache +2 -0
  105. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6y/6yYtw9nBy5BQSaqXmBCmbMKZ2W9i-xXzDUipnQmPyBg.cache +1 -0
  106. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/79/79x651YgKUXaujQCdJ-pAEC5dZg_pn2dunb0jchMaDQ.cache +1 -0
  107. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/7D/7DA7NcBgtuGkw874ZnGGog86dav0rfRpwsOqr5NZn8w.cache +0 -0
  108. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/7G/7GfbUJUiFTReNmQLPaoNQb6zwaAn8V2F6TSbb6gHUe0.cache +1 -0
  109. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/7H/7Hl6K8gEbb3P74YnUpKFaNJpP7D2xYYgOMGojcOa-ag.cache +1 -0
  110. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8M/8MjSjTnG8bT0MHX2mtSwts_g41nf5tdQGu72StLOCH8.cache +2 -0
  111. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8S/8SvabF4ymQg1Bvye9LUpj_kgUYvtEyrC_IFy21I9QkQ.cache +1 -0
  112. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8V/8Vuze0yfvn-ZGnSPhHfFylf_THj3OYxZ43MgYYietX8.cache +2 -0
  113. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/8a/8ayEXSXjdhDv7nFgvX2HZLPF4zorczNuMB12acBi5Tg.cache +1 -0
  114. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9K/9KVq9HdUeF1QpFrSVJNkFVYSVnf6eBvjNOj1ScdcDBk.cache +1 -0
  115. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9X/9XpG6MU2DaMe_As-AVmJLHdetFNNVe6tuSzG3wdBFgw.cache +1 -0
  116. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9b/9bxqdiQYs5dr4yZ7AZfQuus70vM93F4H45nnz56elaM.cache +1 -0
  117. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/AQ/AQwVruFOIEFAa6aCfUPI4NMLs5DcA7F9jJHINlokjdM.cache +0 -0
  118. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Aj/Aj4xA0Ms8-0zqpxEQL_wIoWFvtW6vqdbN03k7x-Zn_w.cache +1 -0
  119. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Br/BrptdQg6UEupRauAlmc_iY-9bgz-lRY7XFQJWh1Cj-I.cache +0 -0
  120. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/C9/C9e7-Bx6ORaFLsjSigwMjM9wgB2SOEBIh9F7Nyuizi0.cache +0 -0
  121. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/CC/CCNBz0pRBBaXl9LPDXUwcU5GwnMhyMZ3hN9k8F_-y1k.cache +1 -0
  122. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ch/ChbwGMU9eLsrC2zaGtMQmlI_cyC4LA1DM0edywF834E.cache +1 -0
  123. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ck/CkC2Zx2KIvKFX2W5bsqxi-ykghbhqFnfPxba8Ox49hk.cache +1 -0
  124. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Cq/CqS8f-adc43tZVUYwbeYNlaAp68VAND9gSz75EJ_qIk.cache +0 -0
  125. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dh/DhvRJbXpx9vsnErI2VDpKjXz-hndz7cH_DPgu8PL6uo.cache +0 -0
  126. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dm/DmswZczHVjLH0N3U2GKkfL0rhDuMg5Q7FCoT8GxCaks.cache +2 -0
  127. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/E1/E1DkSt3mnv_bJAuFVZ3AtOltVU6UNdTgKDBtGytXTW0.cache +1 -0
  128. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ED/EDJquckajF45p6W06qS_rw70poqK8SPCaVQ7SYdZaaI.cache +0 -0
  129. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/EE/EEplIoXGshtrgJgFxcH1B6LgetWrS_RuhCYsTuqiO6s.cache +0 -0
  130. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/EH/EHIpjGxqjcpjWgDJnv5qyQoHj61Grtz_nBtM0MrfrpY.cache +1 -0
  131. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/EM/EM7lC_qW1a9LhesPkDChUijCpMMGIQ9anREMaOxeim0.cache +1 -0
  132. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ej/Ej3tOd_jldb5OqbeKuZTgniWmNEhB8SqUDrAf1AY2R8.cache +2 -0
  133. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Es/EsAu2JEirIm31MKweNKHRZGJy0biOeEt5cQNLfnAURA.cache +1 -0
  134. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/F6/F6xGHKoJgwoM4vZWx9Tj5PdU-eQ1-7Bhnh-zagjLQDA.cache +1 -0
  135. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Fi/FixyVGg9bu3eRk3ddmMXWy7M33tm03pAi1P7UVxXCYs.cache +0 -0
  136. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/G6/G6LBIUOF6NiEmJOb7yUEYKKwAEeqicAJ3W6n8UfEXOg.cache +1 -0
  137. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/GH/GHvnaT_97475zA0bbnVWENv13-dhtQlnj1Unf-tsl6U.cache +1 -0
  138. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Gr/GrA-ejqbqUhgmuDXEav8TmwzP4fKgUcKhkZPhJDFW-s.cache +1 -0
  139. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Gr/GrKBj_NUfuWBJQ-WIrEqu9R9SQR6cX9I8hb6Qw2F7hg.cache +0 -0
  140. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/H6/H64c-4CUUS2AfwaiQFio18rIyst_XRDM4GWgWYw8-Rc.cache +1 -0
  141. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/HC/HCDOUd7-S45aJ_PjVAC_Vmjyud3i1aQv4cE3t9_Z3Dw.cache +0 -0
  142. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KC/KCNxu9eZUWPxk72xh5pBqHgL9Mq1eQBX_hIxN3UffPk.cache +0 -0
  143. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KT/KThrNT1MjSFnwiZQ7_nlQr0ItXkzDuhIq_kXzam40mI.cache +0 -0
  144. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LT/LTXJhfDnAx8fXhGMgZ2e53Ek7uImLI32AUqTv3MIafw.cache +1 -0
  145. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LU/LUfEmeqDaa3HaK6f3vZMSQEUKJ4VONMmCwT8YN0QgqE.cache +1 -0
  146. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lo/Lo5ezKyD81tLPXc-tjc8epiltXcknaWbyurke6mkQ1I.cache +0 -0
  147. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/M3/M3220HcICdTz9arsognbp2l_1RDG78Z56bTv_KlWPL4.cache +0 -0
  148. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ma/Madl7SA4t7JZLahxu6Ke9R30VOZBBD8vVoRSzIjOnJY.cache +1 -0
  149. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Oi/Oi2ZmEFBbtuD00cZCMuBTvEexWeTZkvHsPJmkcInYjE.cache +0 -0
  150. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Ok/Oks6stFiBciNz80-Nk2OxzjcJhXFyZR9B3pDm1Lq8Us.cache +0 -0
  151. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/P8/P84t1Do34k5QzzfUpukZqwnzEn-Vge8zRU8ebYqXUYI.cache +1 -0
  152. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/PM/PMCnZAAKIrllZ_Jgp_Ur6WoxIU9kyM_E1EjHp-ci9iI.cache +0 -0
  153. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Qb/QbgPEai63zAhH5BGyBVFWenWEKvlKHXHy_aZu3VQQpk.cache +2 -0
  154. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Qj/QjSVnMprIdvgTEGBVBnh-AKjeEsiGANemX5AY7Y8mCw.cache +0 -0
  155. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/RR/RRaseJ4GmYu1ezbdAWsQBtYS1BjZQvnLuQoav8QxW4A.cache +2 -0
  156. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/RS/RS-ZXk-Y-ySoIbDQmoby7Bgj7N3evbVYh6NY9-qXamM.cache +1 -0
  157. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Rg/RgSAb6QWYSpBwgCAvMUi1HocmrZwUgG3-JQ2F1p5jwg.cache +1 -0
  158. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Rt/RtUdV-4geEzAWpHpkNyJKPdEB_NbyUudKWgJ6RFD_QM.cache +1 -0
  159. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/SB/SBCC3yocqP5GfrbWOlGUKkdQbLCJoirLZFdFIvwCSog.cache +1 -0
  160. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/SU/SUTF9Cbkbi747jwRIsVQpfN3-OJb7f2GomctHX9uLXo.cache +2 -0
  161. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/SU/SUUXheDD95mUwPAvpXV7TZr0J7rrRSoGrawyr0ZvpHs.cache +0 -0
  162. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/S_/S_Pcb0mGOL8qoG746qUkzjEgfDWafYwWmBKFg_oVILs.cache +2 -0
  163. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Sf/SfDlB2o4tLK2rgB9-jEDtcfGNRPY_Nzde-2msr9_cv4.cache +1 -0
  164. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Sx/Sx5fQ5H_ttg0Jg8OMZkvVVPOXFoRK7rxRQZ-Xglb0Wg.cache +1 -0
  165. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Tv/TvM2B-OCKO7_mMMJ5e9vWXzQvSJnk-CSc8Y6v80I_A4.cache +1 -0
  166. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Vg/VgksnxhDAqGJx05xz9F070c5O377BL58YZ22sDHt-eM.cache +0 -0
  167. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Vk/Vk8iyUuxBx5oHqTJEBws7ePqD0IvCQW7V0hcde1ocso.cache +0 -0
  168. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wo/WoLIUbAjm95qIXELkwfMhb-6f6Bxe-VVQfj8Gbxmf9k.cache +1 -0
  169. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wo/wO-HGAbFrXwx_FjrEAzCpBqQLHnbpTqtDZsc_ku4V-Y.cache +1 -0
  170. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wx/WxX55vFARl0L-n4U2bhoT95AiCKlc1rnpXws-1MJ61M.cache +1 -0
  171. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/X2/X2YYhxXfSMeWK-PEIsEKVn7WHuTZZoVr3-TJw8PZ2qI.cache +0 -0
  172. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/XZ/XZbqz8CgU6sBTJ3C6FzSB2WZbvPjftngO7rSqFy5Oe0.cache +0 -0
  173. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/YP/YP9lbyR4I4Y2H56XD8xB_lG5JZ3cEhpla6Z1KWITau0.cache +0 -0
  174. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Yv/YvhG84OATIN1hzcxIm1dUdAFzDHrXQv0tq2XWOgZ9Bg.cache +1 -0
  175. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ZX/ZXX9zCAbm4kDXzvtHkDG04KXhtHv5eLFQGJ8C0ZnwTE.cache +1 -0
  176. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_3/_365sloRfW0to4KL2d0zrfRsUChA29CQ9xTbiXfY8y4.cache +1 -0
  177. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/_5/_52n2WLJfIOWeCBtjZ2Murh6pKib-IpuR0EktBYqKpg.cache +1 -0
  178. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ac/Acp3i9aB6aj3TgUf8XbdfNdl1LHrnCbqjZJKY04jv-M.cache +2 -0
  179. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ac/acwwbKOCVUQx43GRtU33pvyIqUhvbIsJEqtjUYJ4Y7I.cache +2 -0
  180. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ac/acxzeNJnCGIvMIiRx5uHanox2nphcqymTTHXDUDQyjM.cache +0 -0
  181. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/am/amQnyYc9WanAOKWZ6-lGMYKgK9SaStZ0GidmAquDeNQ.cache +1 -0
  182. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bO/bO32hG_YBKRnvEUnc6WVkRoKXgRX_P6I6HvQBrfrcqg.cache +1 -0
  183. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/b_/b_Itlk9QZZd7Rvf8kcA4yLP1R5Acu7jB-m1xQiSU0qE.cache +2 -0
  184. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/dQ/dQRyP5ear4CnYAvUi3utlj-ArD8Mpm1tu_YrKo3sYqM.cache +2 -0
  185. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/eI/eIdCi9pdESg8mBSixNWcP0ggpHkdGhBz4gCmXu-1T-Q.cache +1 -0
  186. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ek/ektXM_dhs-Yt3Rcr9qqcunWR9Qeiy49omvRIsePDrgY.cache +1 -0
  187. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/et/etvkegz3h_RG3JuPFHQ5vlcF-ZBc2AQCS8K1uTz4MsE.cache +0 -0
  188. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/fy/fyosVngyRNzyNGWgLC3fqIYBF1trPoEj5-YGUucZqv8.cache +1 -0
  189. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gT/gTcO28g7KBHGNWEbIrvu4lKACr-oi8jrtfPpJK-alGw.cache +1 -0
  190. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ga/gauwzOQ2YQbofsKqaMHHIRc36QjCKVsJU-PBd0_sxdo.cache +1 -0
  191. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gv/gvenMj3wS4MU8luvX4B9yoWLDsu4aEjPHu6HqmqRmVM.cache +2 -0
  192. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hE/hEo_QU7FPYjtX-4RWTE3CDhpbTnrssn_eidJPTT9jus.cache +1 -0
  193. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hU/hUnVNKA_obB93f9QaBacYahJlxmSsqMPb0caf7TgYHA.cache +1 -0
  194. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iI/iI5ECMKY_c5Jh5EUcyEm268wH1-WXkPACA4Eokv5oG4.cache +1 -0
  195. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/kK/kKX2bv1FYx1ivrRttxcoKhFrJbTPmfOqhNhA_PHvL20.cache +1 -0
  196. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lQ/lQx4QOVnycSCCGdKdkf68q--9oxPGtL-SkzKrsXP0OE.cache +1 -0
  197. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lk/lkDKpnutXrq58TmSi1a_3CpPW0bua3P2qM1pfkdeiNM.cache +1 -0
  198. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mX/mX1nlsL_SWOB4y22W5FheRX0YEONKyOY7xUeIvRiHco.cache +0 -0
  199. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mj/mj7IPPrG3Iu6yNF_Rt8X7uLmXnX9Xus9-w8pzw33qKI.cache +0 -0
  200. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mk/mK3anqtvwJApYR3xceuQcefcjhVib0s2Oq7FN1p2ZLI.cache +1 -0
  201. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/mk/mkAYMbgT7m9l0b-cZitIKvywgCGfXZ3pzQnyC1zF5pk.cache +1 -0
  202. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/n_/n_xYqQYhwEMQknb3jFQnjlxxBE9TzMNHCdJ-bEyZFIw.cache +0 -0
  203. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/nx/nxTv3sKVUQZADJyM3dPaVmUA78MIsMLD_K279yN_GsI.cache +0 -0
  204. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oD/oDib09gdE8WkzxXJjQsQ0mOCVGkbIIkaQ-JZlozEvoo.cache +1 -0
  205. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oR/oRbeNQfk--2vMaiBNK-IPZuWtL8-Zjpj4wdKYwpWT-Y.cache +0 -0
  206. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oS/oSwxAumjvW64xQ1Lc0jZ5ZUupKl39p9NW1fRMHGN2D8.cache +1 -0
  207. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oz/ozK4IPJj2CBcsem3fLJx3wqcOl6mI6B91PkN0wVfkyk.cache +2 -0
  208. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/p7/p75ImfMSO7wEgU1utN18Pq01BL5fr5j3xQj6eRYFE4o.cache +2 -0
  209. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pp/pp9vUiXJLyGHZCkMCl70DkL_xiv4XWz9ztTiMarEfNY.cache +1 -0
  210. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pt/ptHawc95ZK08GgV9kHAAAa89jpZVYPhqqpPPVWi71Do.cache +1 -0
  211. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/q0/q074YUa9rnMSU4RVfvIYMAnW_TmVXrT1hlJO41-OBbU.cache +1 -0
  212. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/qA/qAXCQxgc8uN7nSfqrtsa8DD_UWBUox9OcwfdrJtzb6A.cache +1 -0
  213. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/qP/qPmv5snMrDw830S6hSICDcnIy7kVEWoFKXhGKT38lG4.cache +2 -0
  214. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/qZ/qZqBOuyk1j0lKHz7Onk5w-W6zpsJwXCI_oAV6Jft7fM.cache +0 -0
  215. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/ql/qleugiSP8m-MGCnPwKRGi97ngKjTxzFCgiFaCo42B1k.cache +1 -0
  216. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/s8/s8SZLe11poSYC83ACEC77enudBY-sGq2cIvp_url9wQ.cache +0 -0
  217. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sn/sn4QRxxVjF0Ci_0wXT2_r3juzRsTYpdr3oIZOPuMDRY.cache +1 -0
  218. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/tR/tR-01mKfGTeWGUVCkmD0FSf0n1ls5mjSBbZmDBQRxdE.cache +0 -0
  219. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/tR/tROEyESrcH-klIdGYfWPZ70uL93VzoncYdd6EBP_fck.cache +0 -0
  220. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/tf/tfaDK6L3U-9ZYIbuxubkyB691dNwMLwNxr54XI0_H7Q.cache +2 -0
  221. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/uh/uhHJ7XB-kBAusYJqgB2h0IJ9trO3-jD8Lq9aDNSxZGc.cache +1 -0
  222. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/vH/vH0I-a20tX_6BHX9WyF-EGLn4QfpGfa2BvRUNEdzP0I.cache +0 -0
  223. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/vL/vL3g9boowrqsF7Dol4tVdRb-2KVAvMx02XlYyU7NYOU.cache +1 -0
  224. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/vj/vjJiNWLGxIRFCyH6-2SDfyWDBm0zK1czKmpH2BzMDlQ.cache +1 -0
  225. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wb/wbt51tMiDSdeDVRHR8wCjuvZ2y_hzC2yretlmGGMgYU.cache +1 -0
  226. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wg/wgIeHcawFV0WGNd4pKlXfAV7TEDj1UNwO4b7oYaBpW0.cache +1 -0
  227. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/wy/wyVoJ3SJ2UwQEUAMb0JVmXmqR6OvjkGK7N06SWNtAcw.cache +0 -0
  228. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xs/xsj35WA8E1f9NhikKGOGSP1bdaGqxlLSs2D06MWhhDk.cache +2 -0
  229. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/y_/y_3kGB4SKGsTCgcO9GE43TC33LT1A75f2qkzXF4066I.cache +1 -0
  230. data/spec/factories/users.rb +26 -0
  231. data/spec/features/authentication_spec.rb +47 -0
  232. data/spec/lib/genkan/config_spec.rb +60 -0
  233. data/spec/lib/genkan_spec.rb +23 -0
  234. data/spec/models/user_spec.rb +186 -0
  235. data/spec/rails_helper.rb +49 -0
  236. data/spec/spec_helper.rb +15 -0
  237. metadata +504 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d80a811e2eee19c521d2ec48d4ef6ba036c693cc
4
+ data.tar.gz: be34267225708d4a0d809e9441bec4a994c85551
5
+ SHA512:
6
+ metadata.gz: 336627fca3b0d252fae0661f09a0aedf6c8d592b052c3e1c0e35380a5ab1dbc8df3347dcc5aa140133247b5938a16de93cc6e5097c0c1263ed92d4c11be60d08
7
+ data.tar.gz: 51d2fac3b7f743b2b5ff59ff6d881348c9517b1e49f53f5b663e84e316286f4b7c10766b8182af7c8689d094d45894f347acc580cc14a714ab9c900f06002e46
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Yoshiyuki Hirano
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ <img width="350" src="https://user-images.githubusercontent.com/15371677/27876034-6f54c860-61f0-11e7-8ebb-0623227ee491.png">
2
+
3
+ Genkan is authentication engine for Rails
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'genkan'
9
+
10
+ # Add any omniauth provider
11
+ gem 'omniauth-google-oauth2'
12
+ gem 'omniauth-facebook'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ $ bundle
19
+ ```
20
+
21
+ ## Getting started
22
+
23
+ ```bash
24
+ $ bin/rails g genkan:install --model User
25
+ create config/initializers/genkan.rb
26
+ create db/migrate/20170705074103_create_users.rb
27
+ create app/models/user.rb
28
+ insert app/controllers/application_controller.rb
29
+ route mount Genkan::Engine, at: '/'
30
+ create app/views/genkan/sessions/new.html.erb
31
+
32
+ $ bin/rails db:migrate
33
+ ```
34
+
35
+ Some setup you must do manually if you haven't yet:
36
+
37
+ 1. Ensure you have edited config/initializers/genkan.rb.
38
+ For example:
39
+
40
+ ```ruby
41
+ Genkan.configure do |config|
42
+ config.user_class_name = 'User'
43
+ config.auto_acceptance = false
44
+ end
45
+
46
+ Genkan::Engine.configure do |config|
47
+ config.middleware.use OmniAuth::Builder do
48
+ # Add omniauth-google-oauth2 to Gemfile:
49
+ # gem 'omniauth-google-oauth2'
50
+ provider(
51
+ :google_oauth2,
52
+ ENV['GOOGLE_OAUTH_CLIENT_ID'],
53
+ ENV['GOOGLE_OAUTH_CLIENT_SECRET'],
54
+ {
55
+ name: 'google',
56
+ scope: 'email',
57
+ hd: 'host-domain.com'
58
+ }
59
+ )
60
+ end
61
+ end
62
+ ```
63
+
64
+ 2. Ensure you have defined root_url to *something* in your config/routes.rb.
65
+ For example:
66
+
67
+ ```ruby
68
+ root to: "home#index"
69
+ ```
70
+
71
+ 3. Ensure you have flash messages in app/views/layouts/application.html.erb.
72
+ For example:
73
+
74
+ ```ruby
75
+ <p class="notice"><%= notice %></p>
76
+ <p class="alert"><%= alert %></p>
77
+ ```
78
+
79
+ ## Debugging
80
+
81
+ You can check on dummy server:
82
+
83
+ ```bash
84
+ $ bundle
85
+ $ bin/rails db:setup
86
+ $ GOOGLE_OAUTH_CLIENT_ID=YOUR_ID GOOGLE_OAUTH_CLIENT_SECRET=YOUR_SECRET bin/rails s
87
+ ```
88
+
89
+ How to create google client id and secret:
90
+
91
+ - [Creating a Google API Console project and client ID  |  Google Sign-In for Websites  |  Google Developers](https://developers.google.com/identity/sign-in/web/devconsole-project).
92
+
93
+ ## License
94
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Genkan'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+ require "rspec/core/rake_task"
24
+ RSpec::Core::RakeTask.new(:spec)
25
+
26
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ module Genkan
2
+ module Authenticatable
3
+ include Genkan::Helper
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_action :authenticate
8
+ helper_method current_user_method_name, :logged_in?
9
+ end
10
+
11
+ private
12
+
13
+ def authenticate
14
+ unless logged_in?
15
+ session[:referer] = request.fullpath
16
+ redirect_to genkan.login_path, notice: t('genkan.sessions.required')
17
+ end
18
+ end
19
+
20
+ define_method(current_user_method_name) do
21
+ instance_variable_get(:"@#{current_user_method_name}") || \
22
+ instance_variable_set(:"@#{current_user_method_name}", user_class.active.find_by(remember_token: session[:remember_token]))
23
+ end
24
+
25
+ def logged_in?
26
+ send(current_user_method_name).present?
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ module Genkan
2
+ module Helper
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ private
7
+ delegate :user_class, :current_user_method_name, to: :class
8
+ end
9
+
10
+ class_methods do
11
+ delegate :user_class, :current_user_method_name, to: :genkan_config
12
+
13
+ def genkan_config
14
+ Genkan.config
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module Genkan
2
+ class ApplicationController < ActionController::Base
3
+ include ::Genkan::Authenticatable
4
+ protect_from_forgery with: :exception
5
+ layout "layouts/application"
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ require_dependency "genkan/application_controller"
2
+
3
+ module Genkan
4
+ class SessionsController < ApplicationController
5
+ rescue_from ActiveRecord::RecordInvalid do |_e|
6
+ redirect_to genkan.login_path, alert: user.errors.full_messages.to_sentence
7
+ end
8
+
9
+ skip_before_action :authenticate, only: %i(new create failure)
10
+
11
+ def new; end
12
+
13
+ def create
14
+ user.login!
15
+ create_session
16
+ redirect_to referer_or_root_path, notice: t('genkan.sessions.logged_in')
17
+ end
18
+
19
+ def failure
20
+ redirect_to genkan.login_path, alert: t('genkan.sessions.failure')
21
+ end
22
+
23
+ def destroy
24
+ destroy_session
25
+ redirect_to genkan.login_path, notice: t('genkan.sessions.logged_out')
26
+ end
27
+
28
+ private
29
+
30
+ def user
31
+ @user ||= user_class.find_or_create_by(email: auth.dig(:info, :email))
32
+ end
33
+
34
+ def auth
35
+ request.env['omniauth.auth']
36
+ end
37
+
38
+ def create_session
39
+ session[:remember_token] = user.remember_token
40
+ end
41
+
42
+ def destroy_session
43
+ session[:remember_token] = nil
44
+ end
45
+
46
+ def referer_or_root_path
47
+ session.delete(:referer) || main_app.root_path
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,78 @@
1
+ module Genkan
2
+ module Auth
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ scope :accepted, -> { where.not(accepted_at: nil) }
7
+ scope :not_banned, -> { where(banned_at: nil) }
8
+ scope :active, -> { accepted.not_banned }
9
+
10
+ validates :email, presence: true, uniqueness: true
11
+
12
+ with_options on: :login do
13
+ validate :ensure_record_has_accepted
14
+ validate :ensure_record_has_not_banned
15
+ end
16
+
17
+ before_create do
18
+ self.remember_token = SecureRandom.hex(20)
19
+ end
20
+ end
21
+
22
+ def login
23
+ store_last_logged_in_at
24
+ increment_logged_in_count
25
+ accept if Genkan.config.auto_acceptance?
26
+ end
27
+
28
+ def login!
29
+ login
30
+ save!(context: :login)
31
+ end
32
+
33
+ def accepted?
34
+ accepted_at.present?
35
+ end
36
+
37
+ def accept
38
+ self.accepted_at = Time.current
39
+ end
40
+
41
+ def accept!
42
+ accept
43
+ save!
44
+ end
45
+
46
+ def banned?
47
+ self.banned_at.present?
48
+ end
49
+
50
+ def ban
51
+ self.banned_at = Time.current
52
+ end
53
+
54
+ def ban!
55
+ ban
56
+ save!
57
+ end
58
+
59
+ private
60
+
61
+ def store_last_logged_in_at
62
+ self.last_logged_in_at = Time.current
63
+ end
64
+
65
+ def increment_logged_in_count
66
+ self.logged_in_count ||= 0
67
+ self.logged_in_count += 1
68
+ end
69
+
70
+ def ensure_record_has_accepted
71
+ errors.add(:base, :not_accepted) unless accepted?
72
+ end
73
+
74
+ def ensure_record_has_not_banned
75
+ errors.add(:base, :banned) if banned?
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module Genkan
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ en:
2
+ genkan:
3
+ sessions:
4
+ failure: Could not authenticated
5
+ required: You need to login
6
+ logged_in: Logged in successfully
7
+ logged_out: Logged out successfully
8
+ errors:
9
+ messages:
10
+ not_accepted: Your account is not accepted yet.
11
+ banned: Your account is locked.
@@ -0,0 +1,11 @@
1
+ ja:
2
+ genkan:
3
+ sessions:
4
+ failure: 認証できません
5
+ required: ログインが必要です
6
+ logged_in: ログインしました
7
+ logged_out: ログアウトしました
8
+ errors:
9
+ messages:
10
+ not_accepted: 利用が許可されていません
11
+ banned: 指定したアカウントでは、ご利用いただけません
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Genkan::Engine.routes.draw do
2
+ get "/login", to: "sessions#new"
3
+ get "/logout", to: "sessions#destroy"
4
+ get "/auth/:provider/callback", to: "sessions#create"
5
+ post "/auth/:provider/callback", to: "sessions#create"
6
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates the necessary files to get you up and running with Genkan gem
3
+
4
+ Examples:
5
+ rails generate genkan:install
6
+
7
+ This will generate the core migration file, the initializer file and the 'User' model class.
8
+
9
+ rails generate genkan:install --model AdminUser
@@ -0,0 +1,57 @@
1
+ module Genkan
2
+ module Generators
3
+ module Helper
4
+ extend ActiveSupport::Concern
5
+
6
+ private
7
+
8
+ def model_class_name
9
+ options.key?(:model) ? options[:model].classify : "User"
10
+ end
11
+
12
+ def model_file_path
13
+ model_name.underscore
14
+ end
15
+
16
+ def model_path
17
+ @model_path ||= File.join("app", "models", "#{model_file_path}.rb")
18
+ end
19
+
20
+ def namespace
21
+ Rails::Generators.namespace if Rails::Generators.respond_to?(:namespace)
22
+ end
23
+
24
+ def namespaced?
25
+ !!namespace
26
+ end
27
+
28
+ def model_name
29
+ if namespaced?
30
+ [namespace.to_s] + [model_class_name]
31
+ else
32
+ [model_class_name]
33
+ end.join("::")
34
+ end
35
+
36
+ def migration_class_name
37
+ if Rails::VERSION::MAJOR >= 5
38
+ "ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
39
+ else
40
+ "ActiveRecord::Migration"
41
+ end
42
+ end
43
+
44
+ class_methods do
45
+ # Define the next_migration_number method (necessary for the migration_template method to work)
46
+ def next_migration_number(dirname)
47
+ if ActiveRecord::Base.timestamped_migrations
48
+ sleep 1 # make sure each time we get a different timestamp
49
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
50
+ else
51
+ format("%.3d", (current_migration_number(dirname) + 1))
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,45 @@
1
+ require "rails/generators/migration"
2
+ require "generators/genkan/helper"
3
+
4
+ module Genkan
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ include Genkan::Generators::Helper
9
+
10
+ source_root File.expand_path("../templates", __FILE__)
11
+
12
+ class_option :model, optional: true,
13
+ type: :string,
14
+ banner: "model",
15
+ desc: "Specify the model class name if you will use anything other than `User`",
16
+ default: "User"
17
+
18
+ def prepare_initializer
19
+ template "initializer.erb", "config/initializers/genkan.rb"
20
+ end
21
+
22
+ def prepare_migration
23
+ migration_template "migration.erb", "db/migrate/create_#{model_class_name.tableize}.rb", migration_class_name: migration_class_name
24
+ end
25
+
26
+ def prepare_model
27
+ template "model.erb", "app/models/#{model_file_path}.rb"
28
+ end
29
+
30
+ def prepare_controller
31
+ inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
32
+ " include Genkan::Authenticatable\n"
33
+ end
34
+ end
35
+
36
+ def prepare_routes
37
+ route "mount Genkan::Engine, at: '/'"
38
+ end
39
+
40
+ def prepare_view
41
+ template "view.erb", "app/views/genkan/sessions/new.html.erb"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ Genkan.configure do |config|
2
+ config.user_class_name = '<%= model_class_name %>'
3
+ config.auto_acceptance = false
4
+ end
5
+
6
+ Genkan::Engine.configure do |config|
7
+ # config.middleware.use OmniAuth::Builder do
8
+ # # Add omniauth-google-oauth2 to Gemfile:
9
+ # # gem 'omniauth-google-oauth2'
10
+ # provider(
11
+ # :google_oauth2,
12
+ # ENV['GOOGLE_OAUTH_CLIENT_ID'],
13
+ # ENV['GOOGLE_OAUTH_CLIENT_SECRET'],
14
+ # {
15
+ # name: 'google',
16
+ # scope: 'email',
17
+ # hd: 'host-domain.com'
18
+ # }
19
+ # )
20
+ # end
21
+ end
@@ -0,0 +1,17 @@
1
+ class Create<%= model_class_name.tableize.camelize %> < <%= migration_class_name %>
2
+ def change
3
+ create_table :<%= model_class_name.tableize %> do |t|
4
+ t.string :email, null: false
5
+ t.string :remember_token, null: false
6
+ t.integer :logged_in_count, null: false, default: 0
7
+ t.datetime :last_logged_in_at
8
+ t.datetime :accepted_at
9
+ t.datetime :banned_at
10
+
11
+ t.timestamp
12
+
13
+ t.index :email, unique: true
14
+ t.index :remember_token, unique: true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ class <%= model_class_name %> < ApplicationRecord
2
+ include Genkan::Auth
3
+ end
@@ -0,0 +1,3 @@
1
+ <h1>Genkan::SessionsController#new</h1>
2
+
3
+ <%%= link_to "login", "/auth/google" %>
@@ -0,0 +1,22 @@
1
+ module Genkan
2
+ class Config
3
+ attr_accessor :user_class_name, :auto_acceptance
4
+
5
+ def initialize
6
+ @user_class_name = "User"
7
+ @auto_acceptance = false
8
+ end
9
+
10
+ def user_class
11
+ @user_class ||= user_class_name.safe_constantize
12
+ end
13
+
14
+ def current_user_method_name
15
+ @current_user_method_name ||= "current_#{user_class_name.underscore.gsub(/\//, '_')}".freeze
16
+ end
17
+
18
+ def auto_acceptance?
19
+ !!auto_acceptance
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module Genkan
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Genkan
4
+
5
+ config.generators do |g|
6
+ g.stylesheets false
7
+ g.javascripts false
8
+ g.helper false
9
+ g.test_framework :rspec, fixture: true
10
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Genkan
2
+ VERSION = '0.1.0'
3
+ end
data/lib/genkan.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "genkan/config"
2
+ require "genkan/engine"
3
+
4
+ module Genkan
5
+ def self.configure
6
+ yield config
7
+ end
8
+
9
+ def self.config
10
+ @_config ||= Config.new
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :genkan do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,74 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Genkan::SessionsController do
4
+ routes { Genkan::Engine.routes }
5
+
6
+ before do
7
+ stub_omniauth
8
+ request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:google]
9
+ end
10
+
11
+ describe 'GET #new' do
12
+ before { get :new }
13
+ it { expect(response).to have_http_status(200) }
14
+ end
15
+
16
+ describe 'POST #create' do
17
+ subject(:execution) { post :create, params: { provider: :google } }
18
+
19
+ context 'when auto_acceptance is true' do
20
+ before { allow_any_instance_of(Genkan::Config).to receive(:auto_acceptance).and_return(true) }
21
+
22
+ it 'creates a user' do
23
+ expect { execution }.to change { User.count }.by(1)
24
+ end
25
+
26
+ it 'creates a session' do
27
+ expect(session[:remember_token]).to be_nil
28
+ execution
29
+ expect(session[:remember_token]).to be_present
30
+ end
31
+
32
+ it 'redirects root_path' do
33
+ execution
34
+ expect(response).to have_http_status(302)
35
+ expect(response).to redirect_to(Dummy::Application.routes.url_helpers.root_path)
36
+ end
37
+ end
38
+
39
+ context 'when auto_acceptance is false' do
40
+ before { allow_any_instance_of(Genkan::Config).to receive(:auto_acceptance).and_return(false) }
41
+
42
+ it 'creates a user' do
43
+ expect { execution }.to change { User.count }.by(1)
44
+ end
45
+
46
+ it 'redirects login_path' do
47
+ execution
48
+ expect(response).to have_http_status(302)
49
+ expect(response).to redirect_to(login_path)
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'GET #destroy' do
55
+ before do
56
+ allow_any_instance_of(Genkan::Config).to receive(:auto_acceptance).and_return(true)
57
+ post :create, params: { provider: :google }
58
+ end
59
+
60
+ subject(:execution) { get :destroy }
61
+
62
+ it 'destroys a session' do
63
+ expect(session[:remember_token]).to be_present
64
+ execution
65
+ expect(session[:remember_token]).to be_nil
66
+ end
67
+
68
+ it 'redirects login_path' do
69
+ execution
70
+ expect(response).to have_http_status(302)
71
+ expect(response).to redirect_to(login_path)
72
+ end
73
+ end
74
+ end