padrino-admin 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (353) hide show
  1. data/README.rdoc +40 -84
  2. data/VERSION +1 -1
  3. data/lib/padrino-admin.rb +3 -20
  4. data/lib/padrino-admin/access_control.rb +78 -326
  5. data/lib/padrino-admin/generators/actions.rb +6 -26
  6. data/lib/padrino-admin/generators/admin_app.rb +40 -11
  7. data/lib/padrino-admin/generators/admin_page.rb +11 -17
  8. data/lib/padrino-admin/generators/orm.rb +85 -0
  9. data/lib/padrino-admin/generators/templates/account/activerecord.rb.tt +43 -0
  10. data/lib/padrino-admin/generators/templates/account/datamapper.rb.tt +54 -0
  11. data/lib/padrino-admin/generators/templates/{page/db → account}/seeds.rb.tt +5 -6
  12. data/lib/padrino-admin/generators/{app/app.rb.tt → templates/app/app.rb} +2 -10
  13. data/lib/padrino-admin/generators/templates/app/controllers/base.rb +7 -0
  14. data/lib/padrino-admin/generators/{app → templates/app}/controllers/sessions.rb +6 -6
  15. data/lib/padrino-admin/generators/templates/assets/stylesheets/base.css +370 -0
  16. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/amro/style.css +364 -0
  17. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/bec-green/style.css +290 -0
  18. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/bec/style.css +301 -0
  19. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/blue/style.css +287 -0
  20. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/default/style.css +373 -0
  21. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/djime-cerulean/style.css +305 -0
  22. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/kathleene/style.css +279 -0
  23. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/olive/style.css +345 -0
  24. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/orange/style.css +269 -0
  25. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/reidb-greenish/style.css +302 -0
  26. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/ruby/style.css +281 -0
  27. data/lib/padrino-admin/generators/templates/assets/stylesheets/themes/warehouse/style.css +391 -0
  28. data/lib/padrino-admin/generators/templates/erb/app/base/_sidebar.erb.tt +13 -0
  29. data/lib/padrino-admin/generators/templates/erb/app/base/index.erb.tt +17 -0
  30. data/lib/padrino-admin/generators/templates/erb/app/layouts/application.erb.tt +44 -0
  31. data/lib/padrino-admin/generators/templates/erb/app/sessions/new.erb.tt +46 -0
  32. data/lib/padrino-admin/generators/templates/erb/page/_form.erb.tt +11 -0
  33. data/lib/padrino-admin/generators/templates/erb/page/edit.erb.tt +18 -0
  34. data/lib/padrino-admin/generators/templates/erb/page/index.erb.tt +36 -0
  35. data/lib/padrino-admin/generators/templates/erb/page/new.erb.tt +17 -0
  36. data/lib/padrino-admin/generators/templates/page/controller.rb.tt +32 -22
  37. data/lib/padrino-admin/helpers/authentication_helpers.rb +8 -9
  38. data/lib/padrino-admin/helpers/view_helpers.rb +20 -338
  39. data/lib/padrino-admin/locale/admin/de.yml +15 -49
  40. data/lib/padrino-admin/locale/admin/en.yml +12 -50
  41. data/lib/padrino-admin/locale/admin/it.yml +15 -50
  42. data/padrino-admin.gemspec +40 -321
  43. data/test/fixtures/data_mapper.rb +56 -7
  44. data/test/generators/test_admin_app_generator.rb +17 -16
  45. data/test/generators/test_admin_page_generator.rb +12 -16
  46. data/test/test_admin_application.rb +193 -12
  47. metadata +33 -314
  48. data/lib/padrino-admin/column_store.rb +0 -156
  49. data/lib/padrino-admin/config.rb +0 -36
  50. data/lib/padrino-admin/generators/admin_uploader.rb +0 -88
  51. data/lib/padrino-admin/generators/app/controllers/accounts.rb +0 -37
  52. data/lib/padrino-admin/generators/app/controllers/base.rb +0 -11
  53. data/lib/padrino-admin/generators/app/controllers/javascripts.rb +0 -10
  54. data/lib/padrino-admin/generators/app/views/accounts/_form.haml +0 -24
  55. data/lib/padrino-admin/generators/app/views/accounts/edit.haml +0 -3
  56. data/lib/padrino-admin/generators/app/views/accounts/grid.js.erb +0 -9
  57. data/lib/padrino-admin/generators/app/views/accounts/new.haml +0 -3
  58. data/lib/padrino-admin/generators/app/views/accounts/store.jml +0 -7
  59. data/lib/padrino-admin/generators/app/views/base/dashboard.haml +0 -3
  60. data/lib/padrino-admin/generators/app/views/base/index.haml +0 -19
  61. data/lib/padrino-admin/generators/app/views/javascripts/admin.js.erb +0 -490
  62. data/lib/padrino-admin/generators/app/views/javascripts/locale.js.erb +0 -135
  63. data/lib/padrino-admin/generators/app/views/sessions/new.haml +0 -26
  64. data/lib/padrino-admin/generators/assets/flash/charts.swf +0 -0
  65. data/lib/padrino-admin/generators/assets/flash/clippy.swf +0 -0
  66. data/lib/padrino-admin/generators/assets/flash/expressinstall.swf +0 -0
  67. data/lib/padrino-admin/generators/assets/flash/swfupload.swf +0 -0
  68. data/lib/padrino-admin/generators/assets/images/admin/back.gif +0 -0
  69. data/lib/padrino-admin/generators/assets/images/admin/background.png +0 -0
  70. data/lib/padrino-admin/generators/assets/images/admin/bg-content.png +0 -0
  71. data/lib/padrino-admin/generators/assets/images/admin/bg-hd-slate.png +0 -0
  72. data/lib/padrino-admin/generators/assets/images/admin/bg-hd.png +0 -0
  73. data/lib/padrino-admin/generators/assets/images/admin/bg-intro.png +0 -0
  74. data/lib/padrino-admin/generators/assets/images/admin/bg-login.png +0 -0
  75. data/lib/padrino-admin/generators/assets/images/admin/bg-menu-slate.png +0 -0
  76. data/lib/padrino-admin/generators/assets/images/admin/bg-menu.png +0 -0
  77. data/lib/padrino-admin/generators/assets/images/admin/bg.png +0 -0
  78. data/lib/padrino-admin/generators/assets/images/admin/btn-login.png +0 -0
  79. data/lib/padrino-admin/generators/assets/images/admin/cancel.gif +0 -0
  80. data/lib/padrino-admin/generators/assets/images/admin/categories.gif +0 -0
  81. data/lib/padrino-admin/generators/assets/images/admin/close.gif +0 -0
  82. data/lib/padrino-admin/generators/assets/images/admin/close.png +0 -0
  83. data/lib/padrino-admin/generators/assets/images/admin/delete.gif +0 -0
  84. data/lib/padrino-admin/generators/assets/images/admin/download.gif +0 -0
  85. data/lib/padrino-admin/generators/assets/images/admin/duplicate.gif +0 -0
  86. data/lib/padrino-admin/generators/assets/images/admin/edit.gif +0 -0
  87. data/lib/padrino-admin/generators/assets/images/admin/export.gif +0 -0
  88. data/lib/padrino-admin/generators/assets/images/admin/hd-bg.gif +0 -0
  89. data/lib/padrino-admin/generators/assets/images/admin/image.gif +0 -0
  90. data/lib/padrino-admin/generators/assets/images/admin/loader.gif +0 -0
  91. data/lib/padrino-admin/generators/assets/images/admin/logo-loader.png +0 -0
  92. data/lib/padrino-admin/generators/assets/images/admin/logo-small.png +0 -0
  93. data/lib/padrino-admin/generators/assets/images/admin/new.gif +0 -0
  94. data/lib/padrino-admin/generators/assets/images/admin/no-image.png +0 -0
  95. data/lib/padrino-admin/generators/assets/images/admin/preview.gif +0 -0
  96. data/lib/padrino-admin/generators/assets/images/admin/print.gif +0 -0
  97. data/lib/padrino-admin/generators/assets/images/admin/save.gif +0 -0
  98. data/lib/padrino-admin/generators/assets/images/admin/support.gif +0 -0
  99. data/lib/padrino-admin/generators/assets/images/admin/up.gif +0 -0
  100. data/lib/padrino-admin/generators/assets/images/ext/default/box/corners-blue.gif +0 -0
  101. data/lib/padrino-admin/generators/assets/images/ext/default/box/corners.gif +0 -0
  102. data/lib/padrino-admin/generators/assets/images/ext/default/box/l-blue.gif +0 -0
  103. data/lib/padrino-admin/generators/assets/images/ext/default/box/l.gif +0 -0
  104. data/lib/padrino-admin/generators/assets/images/ext/default/box/r-blue.gif +0 -0
  105. data/lib/padrino-admin/generators/assets/images/ext/default/box/r.gif +0 -0
  106. data/lib/padrino-admin/generators/assets/images/ext/default/box/tb-blue.gif +0 -0
  107. data/lib/padrino-admin/generators/assets/images/ext/default/box/tb.gif +0 -0
  108. data/lib/padrino-admin/generators/assets/images/ext/default/button/arrow.gif +0 -0
  109. data/lib/padrino-admin/generators/assets/images/ext/default/button/btn.gif +0 -0
  110. data/lib/padrino-admin/generators/assets/images/ext/default/button/group-cs.gif +0 -0
  111. data/lib/padrino-admin/generators/assets/images/ext/default/button/group-lr.gif +0 -0
  112. data/lib/padrino-admin/generators/assets/images/ext/default/button/group-tb.gif +0 -0
  113. data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-b-noline.gif +0 -0
  114. data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-b.gif +0 -0
  115. data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-bo.gif +0 -0
  116. data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-noline.gif +0 -0
  117. data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow-o.gif +0 -0
  118. data/lib/padrino-admin/generators/assets/images/ext/default/button/s-arrow.gif +0 -0
  119. data/lib/padrino-admin/generators/assets/images/ext/default/dd/drop-add.gif +0 -0
  120. data/lib/padrino-admin/generators/assets/images/ext/default/dd/drop-no.gif +0 -0
  121. data/lib/padrino-admin/generators/assets/images/ext/default/dd/drop-yes.gif +0 -0
  122. data/lib/padrino-admin/generators/assets/images/ext/default/editor/tb-sprite.gif +0 -0
  123. data/lib/padrino-admin/generators/assets/images/ext/default/form/checkbox.gif +0 -0
  124. data/lib/padrino-admin/generators/assets/images/ext/default/form/clear-trigger.gif +0 -0
  125. data/lib/padrino-admin/generators/assets/images/ext/default/form/clear-trigger.psd +0 -0
  126. data/lib/padrino-admin/generators/assets/images/ext/default/form/date-trigger.gif +0 -0
  127. data/lib/padrino-admin/generators/assets/images/ext/default/form/date-trigger.psd +0 -0
  128. data/lib/padrino-admin/generators/assets/images/ext/default/form/error-tip-corners.gif +0 -0
  129. data/lib/padrino-admin/generators/assets/images/ext/default/form/exclamation.gif +0 -0
  130. data/lib/padrino-admin/generators/assets/images/ext/default/form/radio.gif +0 -0
  131. data/lib/padrino-admin/generators/assets/images/ext/default/form/search-trigger.gif +0 -0
  132. data/lib/padrino-admin/generators/assets/images/ext/default/form/search-trigger.psd +0 -0
  133. data/lib/padrino-admin/generators/assets/images/ext/default/form/text-bg.gif +0 -0
  134. data/lib/padrino-admin/generators/assets/images/ext/default/form/trigger-tpl.gif +0 -0
  135. data/lib/padrino-admin/generators/assets/images/ext/default/form/trigger.gif +0 -0
  136. data/lib/padrino-admin/generators/assets/images/ext/default/form/trigger.psd +0 -0
  137. data/lib/padrino-admin/generators/assets/images/ext/default/gradient-bg.gif +0 -0
  138. data/lib/padrino-admin/generators/assets/images/ext/default/grid/Thumbs.db +0 -0
  139. data/lib/padrino-admin/generators/assets/images/ext/default/grid/arrow-left-white.gif +0 -0
  140. data/lib/padrino-admin/generators/assets/images/ext/default/grid/arrow-right-white.gif +0 -0
  141. data/lib/padrino-admin/generators/assets/images/ext/default/grid/col-move-bottom.gif +0 -0
  142. data/lib/padrino-admin/generators/assets/images/ext/default/grid/col-move-top.gif +0 -0
  143. data/lib/padrino-admin/generators/assets/images/ext/default/grid/columns.gif +0 -0
  144. data/lib/padrino-admin/generators/assets/images/ext/default/grid/dirty.gif +0 -0
  145. data/lib/padrino-admin/generators/assets/images/ext/default/grid/done.gif +0 -0
  146. data/lib/padrino-admin/generators/assets/images/ext/default/grid/drop-no.gif +0 -0
  147. data/lib/padrino-admin/generators/assets/images/ext/default/grid/drop-yes.gif +0 -0
  148. data/lib/padrino-admin/generators/assets/images/ext/default/grid/footer-bg.gif +0 -0
  149. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-blue-hd.gif +0 -0
  150. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-blue-split.gif +0 -0
  151. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-hrow.gif +0 -0
  152. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-loading.gif +0 -0
  153. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-split.gif +0 -0
  154. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid-vista-hd.gif +0 -0
  155. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-hd-btn.gif +0 -0
  156. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-hrow-over.gif +0 -0
  157. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-hrow.gif +0 -0
  158. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-special-col-bg.gif +0 -0
  159. data/lib/padrino-admin/generators/assets/images/ext/default/grid/grid3-special-col-sel-bg.gif +0 -0
  160. data/lib/padrino-admin/generators/assets/images/ext/default/grid/group-by.gif +0 -0
  161. data/lib/padrino-admin/generators/assets/images/ext/default/grid/group-expand-sprite.gif +0 -0
  162. data/lib/padrino-admin/generators/assets/images/ext/default/grid/hd-pop.gif +0 -0
  163. data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-asc.gif +0 -0
  164. data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-desc.gif +0 -0
  165. data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-lock.gif +0 -0
  166. data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-lock.png +0 -0
  167. data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-unlock.gif +0 -0
  168. data/lib/padrino-admin/generators/assets/images/ext/default/grid/hmenu-unlock.png +0 -0
  169. data/lib/padrino-admin/generators/assets/images/ext/default/grid/invalid_line.gif +0 -0
  170. data/lib/padrino-admin/generators/assets/images/ext/default/grid/loading.gif +0 -0
  171. data/lib/padrino-admin/generators/assets/images/ext/default/grid/mso-hd.gif +0 -0
  172. data/lib/padrino-admin/generators/assets/images/ext/default/grid/nowait.gif +0 -0
  173. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-first-disabled.gif +0 -0
  174. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-first.gif +0 -0
  175. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-last-disabled.gif +0 -0
  176. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-last.gif +0 -0
  177. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-next-disabled.gif +0 -0
  178. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-next.gif +0 -0
  179. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-prev-disabled.gif +0 -0
  180. data/lib/padrino-admin/generators/assets/images/ext/default/grid/page-prev.gif +0 -0
  181. data/lib/padrino-admin/generators/assets/images/ext/default/grid/pick-button.gif +0 -0
  182. data/lib/padrino-admin/generators/assets/images/ext/default/grid/refresh.gif +0 -0
  183. data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-check-sprite.gif +0 -0
  184. data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-expand-sprite.gif +0 -0
  185. data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-over.gif +0 -0
  186. data/lib/padrino-admin/generators/assets/images/ext/default/grid/row-sel.gif +0 -0
  187. data/lib/padrino-admin/generators/assets/images/ext/default/grid/sort-hd.gif +0 -0
  188. data/lib/padrino-admin/generators/assets/images/ext/default/grid/sort_asc.gif +0 -0
  189. data/lib/padrino-admin/generators/assets/images/ext/default/grid/sort_desc.gif +0 -0
  190. data/lib/padrino-admin/generators/assets/images/ext/default/grid/wait.gif +0 -0
  191. data/lib/padrino-admin/generators/assets/images/ext/default/layout/collapse.gif +0 -0
  192. data/lib/padrino-admin/generators/assets/images/ext/default/layout/expand.gif +0 -0
  193. data/lib/padrino-admin/generators/assets/images/ext/default/layout/gradient-bg.gif +0 -0
  194. data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-bottom.gif +0 -0
  195. data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-left.gif +0 -0
  196. data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-right.gif +0 -0
  197. data/lib/padrino-admin/generators/assets/images/ext/default/layout/mini-top.gif +0 -0
  198. data/lib/padrino-admin/generators/assets/images/ext/default/layout/ns-collapse.gif +0 -0
  199. data/lib/padrino-admin/generators/assets/images/ext/default/layout/ns-expand.gif +0 -0
  200. data/lib/padrino-admin/generators/assets/images/ext/default/layout/panel-close.gif +0 -0
  201. data/lib/padrino-admin/generators/assets/images/ext/default/layout/panel-title-bg.gif +0 -0
  202. data/lib/padrino-admin/generators/assets/images/ext/default/layout/panel-title-light-bg.gif +0 -0
  203. data/lib/padrino-admin/generators/assets/images/ext/default/layout/stick.gif +0 -0
  204. data/lib/padrino-admin/generators/assets/images/ext/default/layout/stuck.gif +0 -0
  205. data/lib/padrino-admin/generators/assets/images/ext/default/layout/tab-close-on.gif +0 -0
  206. data/lib/padrino-admin/generators/assets/images/ext/default/layout/tab-close.gif +0 -0
  207. data/lib/padrino-admin/generators/assets/images/ext/default/menu/checked.gif +0 -0
  208. data/lib/padrino-admin/generators/assets/images/ext/default/menu/group-checked.gif +0 -0
  209. data/lib/padrino-admin/generators/assets/images/ext/default/menu/item-over.gif +0 -0
  210. data/lib/padrino-admin/generators/assets/images/ext/default/menu/menu-parent.gif +0 -0
  211. data/lib/padrino-admin/generators/assets/images/ext/default/menu/menu.gif +0 -0
  212. data/lib/padrino-admin/generators/assets/images/ext/default/menu/unchecked.gif +0 -0
  213. data/lib/padrino-admin/generators/assets/images/ext/default/panel/corners-sprite.gif +0 -0
  214. data/lib/padrino-admin/generators/assets/images/ext/default/panel/left-right.gif +0 -0
  215. data/lib/padrino-admin/generators/assets/images/ext/default/panel/light-hd.gif +0 -0
  216. data/lib/padrino-admin/generators/assets/images/ext/default/panel/tool-sprite-tpl.gif +0 -0
  217. data/lib/padrino-admin/generators/assets/images/ext/default/panel/tool-sprites.gif +0 -0
  218. data/lib/padrino-admin/generators/assets/images/ext/default/panel/tools-sprites-trans.gif +0 -0
  219. data/lib/padrino-admin/generators/assets/images/ext/default/panel/top-bottom.gif +0 -0
  220. data/lib/padrino-admin/generators/assets/images/ext/default/panel/top-bottom.png +0 -0
  221. data/lib/padrino-admin/generators/assets/images/ext/default/panel/white-corners-sprite.gif +0 -0
  222. data/lib/padrino-admin/generators/assets/images/ext/default/panel/white-left-right.gif +0 -0
  223. data/lib/padrino-admin/generators/assets/images/ext/default/panel/white-top-bottom.gif +0 -0
  224. data/lib/padrino-admin/generators/assets/images/ext/default/progress/progress-bg.gif +0 -0
  225. data/lib/padrino-admin/generators/assets/images/ext/default/qtip/bg.gif +0 -0
  226. data/lib/padrino-admin/generators/assets/images/ext/default/qtip/close.gif +0 -0
  227. data/lib/padrino-admin/generators/assets/images/ext/default/qtip/tip-anchor-sprite.gif +0 -0
  228. data/lib/padrino-admin/generators/assets/images/ext/default/qtip/tip-sprite.gif +0 -0
  229. data/lib/padrino-admin/generators/assets/images/ext/default/s.gif +0 -0
  230. data/lib/padrino-admin/generators/assets/images/ext/default/shadow-c.png +0 -0
  231. data/lib/padrino-admin/generators/assets/images/ext/default/shadow-lr.png +0 -0
  232. data/lib/padrino-admin/generators/assets/images/ext/default/shadow.png +0 -0
  233. data/lib/padrino-admin/generators/assets/images/ext/default/shared/blue-loading.gif +0 -0
  234. data/lib/padrino-admin/generators/assets/images/ext/default/shared/calendar.gif +0 -0
  235. data/lib/padrino-admin/generators/assets/images/ext/default/shared/glass-bg.gif +0 -0
  236. data/lib/padrino-admin/generators/assets/images/ext/default/shared/hd-sprite.gif +0 -0
  237. data/lib/padrino-admin/generators/assets/images/ext/default/shared/large-loading.gif +0 -0
  238. data/lib/padrino-admin/generators/assets/images/ext/default/shared/left-btn.gif +0 -0
  239. data/lib/padrino-admin/generators/assets/images/ext/default/shared/loading-balls.gif +0 -0
  240. data/lib/padrino-admin/generators/assets/images/ext/default/shared/right-btn.gif +0 -0
  241. data/lib/padrino-admin/generators/assets/images/ext/default/shared/warning.gif +0 -0
  242. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/e-handle-dark.gif +0 -0
  243. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/e-handle.gif +0 -0
  244. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/ne-handle-dark.gif +0 -0
  245. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/ne-handle.gif +0 -0
  246. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/nw-handle-dark.gif +0 -0
  247. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/nw-handle.gif +0 -0
  248. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/s-handle-dark.gif +0 -0
  249. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/s-handle.gif +0 -0
  250. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/se-handle-dark.gif +0 -0
  251. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/se-handle.gif +0 -0
  252. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/square.gif +0 -0
  253. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/sw-handle-dark.gif +0 -0
  254. data/lib/padrino-admin/generators/assets/images/ext/default/sizer/sw-handle.gif +0 -0
  255. data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-bg.png +0 -0
  256. data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-thumb.png +0 -0
  257. data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-v-bg.png +0 -0
  258. data/lib/padrino-admin/generators/assets/images/ext/default/slider/slider-v-thumb.png +0 -0
  259. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/scroll-left.gif +0 -0
  260. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/scroll-right.gif +0 -0
  261. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/scroller-bg.gif +0 -0
  262. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-inactive-left-bg.gif +0 -0
  263. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-inactive-right-bg.gif +0 -0
  264. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-left-bg.gif +0 -0
  265. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-btm-right-bg.gif +0 -0
  266. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-close.gif +0 -0
  267. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-strip-bg.gif +0 -0
  268. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-strip-bg.png +0 -0
  269. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tab-strip-btm-bg.gif +0 -0
  270. data/lib/padrino-admin/generators/assets/images/ext/default/tabs/tabs-sprite.gif +0 -0
  271. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/bg.gif +0 -0
  272. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/btn-arrow-light.gif +0 -0
  273. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/btn-arrow.gif +0 -0
  274. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/btn-over-bg.gif +0 -0
  275. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/gray-bg.gif +0 -0
  276. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/more.gif +0 -0
  277. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-bg.gif +0 -0
  278. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-btn-sprite.gif +0 -0
  279. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-xl-btn-sprite.gif +0 -0
  280. data/lib/padrino-admin/generators/assets/images/ext/default/toolbar/tb-xl-sep.gif +0 -0
  281. data/lib/padrino-admin/generators/assets/images/ext/default/tree/arrows.gif +0 -0
  282. data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-add.gif +0 -0
  283. data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-between.gif +0 -0
  284. data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-no.gif +0 -0
  285. data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-over.gif +0 -0
  286. data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-under.gif +0 -0
  287. data/lib/padrino-admin/generators/assets/images/ext/default/tree/drop-yes.gif +0 -0
  288. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-minus-nl.gif +0 -0
  289. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-minus.gif +0 -0
  290. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-plus-nl.gif +0 -0
  291. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end-plus.gif +0 -0
  292. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-end.gif +0 -0
  293. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-line.gif +0 -0
  294. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-minus-nl.gif +0 -0
  295. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-minus.gif +0 -0
  296. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-plus-nl.gif +0 -0
  297. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow-plus.gif +0 -0
  298. data/lib/padrino-admin/generators/assets/images/ext/default/tree/elbow.gif +0 -0
  299. data/lib/padrino-admin/generators/assets/images/ext/default/tree/folder-open.gif +0 -0
  300. data/lib/padrino-admin/generators/assets/images/ext/default/tree/folder.gif +0 -0
  301. data/lib/padrino-admin/generators/assets/images/ext/default/tree/leaf.gif +0 -0
  302. data/lib/padrino-admin/generators/assets/images/ext/default/tree/loading.gif +0 -0
  303. data/lib/padrino-admin/generators/assets/images/ext/default/tree/s.gif +0 -0
  304. data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-error.gif +0 -0
  305. data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-info.gif +0 -0
  306. data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-question.gif +0 -0
  307. data/lib/padrino-admin/generators/assets/images/ext/default/window/icon-warning.gif +0 -0
  308. data/lib/padrino-admin/generators/assets/images/ext/default/window/left-corners.png +0 -0
  309. data/lib/padrino-admin/generators/assets/images/ext/default/window/left-corners.psd +0 -0
  310. data/lib/padrino-admin/generators/assets/images/ext/default/window/left-right.png +0 -0
  311. data/lib/padrino-admin/generators/assets/images/ext/default/window/left-right.psd +0 -0
  312. data/lib/padrino-admin/generators/assets/images/ext/default/window/right-corners.png +0 -0
  313. data/lib/padrino-admin/generators/assets/images/ext/default/window/right-corners.psd +0 -0
  314. data/lib/padrino-admin/generators/assets/images/ext/default/window/top-bottom.png +0 -0
  315. data/lib/padrino-admin/generators/assets/images/ext/default/window/top-bottom.psd +0 -0
  316. data/lib/padrino-admin/generators/assets/javascripts/controls.js +0 -3
  317. data/lib/padrino-admin/generators/assets/javascripts/dragdrop.js +0 -3
  318. data/lib/padrino-admin/generators/assets/javascripts/effects.js +0 -4
  319. data/lib/padrino-admin/generators/assets/javascripts/ext.js +0 -29
  320. data/lib/padrino-admin/generators/assets/javascripts/prototype.js +0 -14
  321. data/lib/padrino-admin/generators/assets/javascripts/swfupload.js +0 -4
  322. data/lib/padrino-admin/generators/assets/stylesheets/admin.css +0 -60
  323. data/lib/padrino-admin/generators/assets/stylesheets/ext.css +0 -1543
  324. data/lib/padrino-admin/generators/assets/stylesheets/login.css +0 -17
  325. data/lib/padrino-admin/generators/assets/stylesheets/standard.css +0 -62
  326. data/lib/padrino-admin/generators/templates/page/views/_form.haml.tt +0 -9
  327. data/lib/padrino-admin/generators/templates/page/views/edit.haml.tt +0 -3
  328. data/lib/padrino-admin/generators/templates/page/views/grid.js.erb.tt +0 -9
  329. data/lib/padrino-admin/generators/templates/page/views/new.haml.tt +0 -3
  330. data/lib/padrino-admin/generators/templates/page/views/store.jml.tt +0 -6
  331. data/lib/padrino-admin/generators/templates/uploader/controller.rb +0 -24
  332. data/lib/padrino-admin/generators/templates/uploader/lib/uploader.rb +0 -66
  333. data/lib/padrino-admin/generators/templates/uploader/views/grid.js.erb +0 -57
  334. data/lib/padrino-admin/generators/templates/uploader/views/store.jml +0 -10
  335. data/lib/padrino-admin/locale/extjs/de.yml +0 -147
  336. data/lib/padrino-admin/locale/extjs/en.yml +0 -147
  337. data/lib/padrino-admin/locale/extjs/it.yml +0 -147
  338. data/lib/padrino-admin/orm.rb +0 -48
  339. data/lib/padrino-admin/orm/abstract.rb +0 -95
  340. data/lib/padrino-admin/orm/activerecord.rb +0 -144
  341. data/lib/padrino-admin/orm/datamapper.rb +0 -229
  342. data/lib/padrino-admin/orm/mongomapper.rb +0 -65
  343. data/lib/padrino-admin/utils/literal.rb +0 -13
  344. data/test/fixtures/active_record.rb +0 -29
  345. data/test/fixtures/mongo_mapper.rb +0 -12
  346. data/test/fixtures/test_column_store.jml +0 -11
  347. data/test/generators/test_admin_uploader_generator.rb +0 -56
  348. data/test/test_access_control.rb +0 -99
  349. data/test/test_active_record.rb +0 -96
  350. data/test/test_column_store.rb +0 -87
  351. data/test/test_config.rb +0 -13
  352. data/test/test_data_mapper.rb +0 -114
  353. data/test/test_mongo_mapper.rb +0 -30
@@ -8,6 +8,7 @@ module Padrino
8
8
  def orm
9
9
  fetch_component_choice(:orm).to_sym rescue :datamapper
10
10
  end
11
+ alias :adapter :orm
11
12
 
12
13
  ##
13
14
  # Tell us for now wich orm we support
@@ -19,16 +20,9 @@ module Padrino
19
20
  ##
20
21
  # Add access_control permission in our app.rb
21
22
  #
22
- def add_access_control_permission(admin, controller)
23
- permission = indent(6, access_control(controller))
24
- inject_into_file destination_root("#{admin}/app.rb"), permission, :after => "access_control.roles_for :admin do |role, account|\n"
25
- end
26
-
27
- ##
28
- # Add a simple permission (allow/deny) to our app.rb
29
- #
30
- def add_permission(admin, permission)
31
- inject_into_file destination_root("#{admin}/app.rb"), indent(6, "\n#{permission}\n"), :after => "access_control.roles_for :admin do |role, account|\n"
23
+ def add_project_module(controller)
24
+ permission = indent(6, "role.project_module :#{controller}, \"/#{controller}\"\n")
25
+ inject_into_file destination_root("/admin/app.rb"), permission, :after => "access_control.roles_for :admin do |role, account|\n"
32
26
  end
33
27
 
34
28
  ##
@@ -38,21 +32,7 @@ module Padrino
38
32
  indent = ' ' * count
39
33
  content.lines.map { |line| line != "\n" ? indent+line : "\n" }.join
40
34
  end
41
-
42
- private
43
- ##
44
- # For access control permissions
45
- #
46
- def access_control(controller)
47
- (<<-RUBY).gsub(/ {14}/,'')
48
-
49
- role.project_module :#{controller} do |project|
50
- project.menu :list, "/admin/#{controller}.js"
51
- project.menu :new, "/admin/#{controller}/new"
52
- end
53
- RUBY
54
- end
55
- end
56
- end
35
+ end # Actions
36
+ end # Admin
57
37
  end # Generators
58
38
  end # Padrino
@@ -6,9 +6,10 @@ module Padrino
6
6
  # Add this generator to our padrino-gen
7
7
  Padrino::Generators.add_generator(:admin, self)
8
8
 
9
- # Define the source template root
9
+ # Define the source template root and themes
10
10
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
11
11
  def self.banner; "padrino-gen admin"; end
12
+ def self.themes; Dir[File.dirname(__FILE__) + "/templates/assets/stylesheets/themes/*"].map { |t| File.basename(t) }; end
12
13
 
13
14
  # Include related modules
14
15
  include Thor::Actions
@@ -20,6 +21,8 @@ module Padrino
20
21
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
21
22
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
22
23
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
+ class_option :name, :desc => "The app name", :aliases => '-a', :default => "Padrino Admin", :type => :string
25
+ class_option :theme, :desc => "Your admin theme: (#{self.themes.join(", ")})", :default => "default", :type => :string
23
26
 
24
27
  # Copies over the Padrino base admin application
25
28
  def create_admin
@@ -31,18 +34,46 @@ module Padrino
31
34
  raise SystemExit
32
35
  end
33
36
 
37
+ unless self.class.themes.include?(options[:theme])
38
+ say "<= You need to choose a theme from: #{self.class.themes.join(", ")}"
39
+ raise SystemExit
40
+ end
41
+
34
42
  self.behavior = :revoke if options[:destroy]
35
- directory("app/", destination_root("admin"))
36
- directory("assets/", destination_root("public", "admin"))
43
+
44
+ directory "templates/app", destination_root("admin")
45
+ directory "templates/assets", destination_root("public", "admin")
37
46
 
38
47
  Padrino::Generators::Model.dup.start([
39
48
  "account", "name:string", "surname:string", "email:string", "crypted_password:string", "salt:string", "role:string",
40
49
  "-r=#{options[:root]}", "-s=#{options[:skip_migration]}", "-d=#{options[:destroy]}"
41
50
  ])
42
51
 
43
- insert_into_gemfile("haml")
44
- template "templates/page/db/seeds.rb.tt", destination_root("/db/seeds.rb")
52
+ column = Struct.new(:name, :type)
53
+ columns = [:id, :name, :surname, :email].map { |col| column.new(col) }
54
+ column_fields = [
55
+ { :name => :name, :field_type => :text_field },
56
+ { :name => :surname, :field_type => :text_field },
57
+ { :name => :email, :field_type => :text_field },
58
+ { :name => :password, :field_type => :text_field },
59
+ { :name => :password_confirmation, :field_type => :text_field },
60
+ { :name => :role, :field_type => :text_field }
61
+ ]
62
+
63
+ admin_app = Padrino::Generators::AdminPage.new(["account"], :root => options[:root])
64
+ admin_app.orm = Padrino::Admin::Generators::Orm.new(:account, orm, columns, column_fields)
65
+ admin_app.invoke
66
+
67
+ template "templates/account/#{orm}.rb.tt", destination_root("app", "models", "account.rb"), :force => true
68
+ template "templates/account/seeds.rb.tt", destination_root("db/seeds.rb")
69
+ template "templates/erb/app/base/_sidebar.erb.tt", destination_root("admin/views/base/_sidebar.erb")
70
+ template "templates/erb/app/base/index.erb.tt", destination_root("admin/views/base/index.erb")
71
+ template "templates/erb/app/layouts/application.erb.tt", destination_root("admin/views/layouts/application.erb")
72
+ template "templates/erb/app/sessions/new.erb.tt", destination_root("admin/views/sessions/new.erb")
73
+
74
+ add_project_module :accounts
45
75
  append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"Admin\").to(\"/admin\")"
76
+ gsub_file destination_root("admin/views/accounts/_form.erb"), "f.text_field :role, :class => :text_field", "f.select :role, :options => access_control.roles"
46
77
 
47
78
  return if self.behavior == :revoke
48
79
  say (<<-TEXT).gsub(/ {10}/,'')
@@ -51,7 +82,7 @@ module Padrino
51
82
  Admin has been successfully installed, now follow this steps:
52
83
  =================================================================
53
84
  1) Run migrations
54
- 2) That's all!!
85
+ 2) Run padrino rake seed
55
86
  =================================================================
56
87
 
57
88
  TEXT
@@ -59,8 +90,6 @@ module Padrino
59
90
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and exit unless in_app_root?
60
91
  end
61
92
  end
62
-
63
- end
64
-
65
- end
66
- end
93
+ end # AdminApp
94
+ end # Generators
95
+ end # Padrino
@@ -2,6 +2,7 @@ module Padrino
2
2
  module Generators
3
3
 
4
4
  class AdminPage < Thor::Group
5
+ attr_accessor :orm
5
6
 
6
7
  # Add this generator to our padrino-gen
7
8
  Padrino::Generators.add_generator(:admin_page, self)
@@ -28,23 +29,16 @@ module Padrino
28
29
  def create_controller
29
30
  self.destination_root = options[:root]
30
31
  if in_app_root?
31
- @model_name = model.classify
32
- @model_klass = model.classify.constantize
33
- @model_plural = model.underscore.pluralize
34
- @model_singular = model.underscore
35
- self.behavior = :revoke if options[:destroy]
36
-
37
- template "templates/page/controller.rb.tt", destination_root("/admin/controllers/#{@model_plural}.rb")
38
- template "templates/page/views/_form.haml.tt", destination_root("/admin/views/#{@model_plural}/_form.haml")
39
- template "templates/page/views/edit.haml.tt", destination_root("/admin/views/#{@model_plural}/edit.haml")
40
- template "templates/page/views/grid.js.erb.tt", destination_root("/admin/views/#{@model_plural}/grid.js.erb")
41
- template "templates/page/views/new.haml.tt", destination_root("/admin/views/#{@model_plural}/new.haml")
42
- template "templates/page/views/store.jml.tt", destination_root("/admin/views/#{@model_plural}/store.jml")
43
-
44
- add_access_control_permission("/admin", @model_plural)
45
- # TODO: figure how to manage tests for sub apps.
46
- # include_component_module_for(:test) if test?
47
- # generate_controller_test(model.downcase.pluralize)
32
+ @orm ||= Padrino::Admin::Generators::Orm.new(model, adapter)
33
+ self.behavior = :revoke if options[:destroy]
34
+
35
+ template "templates/page/controller.rb.tt", destination_root("/admin/controllers/#{@orm.name_plural}.rb")
36
+ template "templates/erb/page/_form.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/_form.erb")
37
+ template "templates/erb/page/edit.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/edit.erb")
38
+ template "templates/erb/page/index.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/index.erb")
39
+ template "templates/erb/page/new.erb.tt", destination_root("/admin/views/#{@orm.name_plural}/new.erb")
40
+
41
+ add_project_module(@orm.name_plural)
48
42
  else
49
43
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
50
44
  end
@@ -0,0 +1,85 @@
1
+ module Padrino
2
+ module Admin
3
+ module Generators
4
+ class OrmError < StandardError; end
5
+ class Orm
6
+ attr_reader :klass_name, :klass, :name_plural, :name_singular, :orm
7
+
8
+ def initialize(name, orm, columns=nil, column_fields=nil)
9
+ name = name.to_s
10
+ @klass_name = name.classify
11
+ @klass = name.classify.constantize rescue nil
12
+ @name_plural = name.underscore.pluralize
13
+ @name_singular = name.underscore
14
+ @orm = orm.to_sym
15
+ @columns = columns
16
+ @column_fields = column_fields
17
+ raise OrmError, "Model #{name} not found!" if @columns.nil? && @klass.nil?
18
+ end
19
+
20
+ def field_type(type)
21
+ case type
22
+ when :integer, :float, :decimal then :text_field
23
+ when :string then :text_field
24
+ when :text then :text_area
25
+ when :boolean then :check_box
26
+ else :text_field
27
+ end
28
+ end
29
+
30
+ def columns
31
+ @columns ||= case orm
32
+ when :activerecord then @klass.columns
33
+ when :datamapper then @klass.properties
34
+ else raise OrmError, "Adapter #{orm} not yet supported!"
35
+ end
36
+ end
37
+
38
+ def column_fields
39
+ excluded_columns = %w[id created_at updated_at]
40
+ column_fields = columns.dup
41
+ column_fields.reject! { |column| excluded_columns.include?(column.name.to_s) }
42
+ @column_fields ||= column_fields.map do |column|
43
+ { :name => column.name, :field_type => field_type(column.type) }
44
+ end
45
+ end
46
+
47
+ def all
48
+ "#{klass_name}.all"
49
+ end
50
+
51
+ def find(params=nil)
52
+ case orm
53
+ when :activerecord then "#{klass_name}.find(#{params})"
54
+ when :datamapper then "#{klass_name}.get(#{params})"
55
+ else raise OrmError, "Adapter #{orm} not yet supported!"
56
+ end
57
+ end
58
+
59
+ def build(params=nil)
60
+ if params
61
+ "#{klass_name}.new(#{params})"
62
+ else
63
+ "#{klass_name}.new"
64
+ end
65
+ end
66
+
67
+ def save
68
+ "#{name_singular}.save"
69
+ end
70
+
71
+ def update_attributes(params=nil)
72
+ case orm
73
+ when :activerecord then "#{name_singular}.update_attributes(#{params})"
74
+ when :datamapper then "#{name_singular}.update(#{params})"
75
+ else raise OrmError, "Adapter #{orm} not yet supported!"
76
+ end
77
+ end
78
+
79
+ def destroy
80
+ "#{name_singular}.destroy"
81
+ end
82
+ end # Orm
83
+ end # Generators
84
+ end # Admin
85
+ end # Padrino
@@ -0,0 +1,43 @@
1
+ class Account < ActiveRecord::Base
2
+ attr_accessor :password
3
+
4
+ # Validations
5
+ validates_presence_of :email, :role
6
+ validates_presence_of :password, :if => :password_required
7
+ validates_presence_of :password_confirmation, :if => :password_required
8
+ validates_length_of :password, :within => 4..40, :if => :password_required
9
+ validates_confirmation_of :password, :if => :password_required
10
+ validates_length_of :email, :within => 3..100
11
+ validates_uniqueness_of :email, :case_sensitive => false
12
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
13
+ validates_format_of :role, :with => /[A-Za-z]/
14
+
15
+ # Callbacks
16
+ before_save :generate_password
17
+
18
+ ##
19
+ # This method it's for authentication purpose
20
+ #
21
+ def self.authenticate(email, password)
22
+ account = first(:conditions => { :email => email }) if email.present?
23
+ account && account.password_clean == password ? account : nil
24
+ end
25
+
26
+ ##
27
+ # This method it's used for retrive the original password.
28
+ #
29
+ def password_clean
30
+ crypted_password.decrypt(salt)
31
+ end
32
+
33
+ private
34
+ def generate_password
35
+ return if password.blank?
36
+ self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new_record?
37
+ self.crypted_password = password.encrypt(self.salt)
38
+ end
39
+
40
+ def password_required
41
+ crypted_password.blank? || !password.blank?
42
+ end
43
+ end
@@ -0,0 +1,54 @@
1
+ class Account
2
+ include DataMapper::Resource
3
+ include DataMapper::Validate
4
+ attr_accessor :password, :password_confirmation
5
+
6
+ # Properties
7
+ property :id, Serial
8
+ property :name, String
9
+ property :surname, String
10
+ property :email, String
11
+ property :crypted_password, String
12
+ property :salt, String
13
+ property :role, String
14
+
15
+ # Validations
16
+ validates_present :email, :role
17
+ validates_present :password, :if => :password_required
18
+ validates_present :password_confirmation, :if => :password_required
19
+ validates_length :password, :min => 4, :max => 40, :if => :password_required
20
+ validates_is_confirmed :password, :if => :password_required
21
+ validates_length :email, :min => 3, :max => 100
22
+ validates_is_unique :email, :case_sensitive => false
23
+ validates_format :email, :with => :email_address
24
+ validates_format :role, :with => /[A-Za-z]/
25
+
26
+ # Callbacks
27
+ before :save, :generate_password
28
+
29
+ ##
30
+ # This method it's for authentication purpose
31
+ #
32
+ def self.authenticate(email, password)
33
+ account = first(:conditions => { :email => email }) if email.present?
34
+ account && account.password_clean == password ? account : nil
35
+ end
36
+
37
+ ##
38
+ # This method it's used for retrive the original password.
39
+ #
40
+ def password_clean
41
+ crypted_password.decrypt(salt)
42
+ end
43
+
44
+ private
45
+ def generate_password
46
+ return if password.blank?
47
+ self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{email}--") if new?
48
+ self.crypted_password = password.encrypt(self.salt)
49
+ end
50
+
51
+ def password_required
52
+ crypted_password.blank? || !password.blank?
53
+ end
54
+ end
@@ -10,16 +10,15 @@ password = shell.ask "Tell me the password to use:"
10
10
 
11
11
  shell.say ""
12
12
 
13
- account = Account.create(:email => email, :password => password, :password_confirmation => password, :role => "admin")
13
+ account = Account.create(:email => email, :name => "Foo", :surname => "Bar", :password => password, :password_confirmation => password, :role => "admin")
14
14
 
15
15
  if account.valid?
16
- shell.say "Perfect! Your account was created."
17
- shell.say ""
18
- shell.say "Now you can start your server with padrino start and then login into /admin with:"
16
+ shell.say "================================================================="
17
+ shell.say "Account has been successfully created, now you can login with:"
18
+ shell.say "================================================================="
19
19
  shell.say " email: #{email}"
20
20
  shell.say " password: #{password}"
21
- shell.say ""
22
- shell.say "That's all!"
21
+ shell.say "================================================================="
23
22
  else
24
23
  shell.say "Sorry but some thing went worng!"
25
24
  shell.say ""
@@ -9,30 +9,22 @@ class Admin < Padrino::Application
9
9
  # set :reload, false # Reload application files (default in development)
10
10
  # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
11
11
  # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
12
- # enable :auto_locale # Auto Set locale if url match /:locale/foo/bar (disabled by default)
13
12
  # disable :padrino_helpers # Disables padrino markup helpers (enabled by default if present)
14
13
  # disable :padrino_mailer # Disables padrino mailer (enabled by default if present)
15
14
  # disable :flash # Disables rack-flash (enabled by default)
16
15
  # enable :authentication # Enable padrino-admin authentication (disabled by default)
17
- # layout :foo # Layout can be in views/layouts/foo.ext or views/foo.ext (:application is default)
16
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
18
17
  #
19
- layout false
20
18
  enable :authentication
21
19
  disable :store_location
22
20
  set :login_page, "/admin/sessions/new"
23
21
 
24
22
  access_control.roles_for :any do |role|
23
+ role.protect "/"
25
24
  role.allow "/sessions"
26
25
  end
27
26
 
28
27
  access_control.roles_for :admin do |role, account|
29
-
30
- role.allow "/"
31
-
32
- role.project_module :accounts do |project|
33
- project.menu :list, "/admin/accounts.js"
34
- project.menu :new, "/admin/accounts/new"
35
- end
36
28
  end
37
29
 
38
30
  end
@@ -0,0 +1,7 @@
1
+ Admin.controllers :base do
2
+
3
+ get :index, :map => "(/)" do
4
+ render "base/index"
5
+ end
6
+
7
+ end
@@ -1,21 +1,21 @@
1
1
  Admin.controllers :sessions do
2
-
2
+
3
3
  get :new do
4
- render "/sessions/new"
4
+ render "/sessions/new", nil, :layout => false
5
5
  end
6
6
 
7
7
  post :create do
8
8
  if account = Account.authenticate(params[:email], params[:password])
9
9
  set_current_account(account)
10
- redirect url_for(:index)
10
+ redirect url(:base, :index)
11
11
  else
12
- flash[:notice] = "Login or password wrong."
13
- redirect url_for(:sessions_new)
12
+ flash[:warning] = "Login or password wrong."
13
+ redirect url(:sessions, :new)
14
14
  end
15
15
  end
16
16
 
17
17
  get :destroy do
18
18
  set_current_account(nil)
19
- render "/sessions/new"
19
+ redirect url(:sessions, :new)
20
20
  end
21
21
  end