tennpipes-su 3.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.rdoc +70 -0
  4. data/Rakefile +22 -0
  5. data/lib/tennpipes-su.rb +35 -0
  6. data/lib/tennpipes-su/access_control.rb +191 -0
  7. data/lib/tennpipes-su/bootstrap-less/alerts.less +67 -0
  8. data/lib/tennpipes-su/bootstrap-less/badges.less +55 -0
  9. data/lib/tennpipes-su/bootstrap-less/bootstrap.less +49 -0
  10. data/lib/tennpipes-su/bootstrap-less/breadcrumbs.less +26 -0
  11. data/lib/tennpipes-su/bootstrap-less/button-groups.less +226 -0
  12. data/lib/tennpipes-su/bootstrap-less/buttons.less +155 -0
  13. data/lib/tennpipes-su/bootstrap-less/carousel.less +232 -0
  14. data/lib/tennpipes-su/bootstrap-less/close.less +33 -0
  15. data/lib/tennpipes-su/bootstrap-less/code.less +63 -0
  16. data/lib/tennpipes-su/bootstrap-less/component-animations.less +29 -0
  17. data/lib/tennpipes-su/bootstrap-less/dropdowns.less +213 -0
  18. data/lib/tennpipes-su/bootstrap-less/font-awesome/bordered-pulled.less +16 -0
  19. data/lib/tennpipes-su/bootstrap-less/font-awesome/core.less +12 -0
  20. data/lib/tennpipes-su/bootstrap-less/font-awesome/fixed-width.less +6 -0
  21. data/lib/tennpipes-su/bootstrap-less/font-awesome/font-awesome.less +17 -0
  22. data/lib/tennpipes-su/bootstrap-less/font-awesome/icons.less +412 -0
  23. data/lib/tennpipes-su/bootstrap-less/font-awesome/larger.less +13 -0
  24. data/lib/tennpipes-su/bootstrap-less/font-awesome/list.less +19 -0
  25. data/lib/tennpipes-su/bootstrap-less/font-awesome/mixins.less +20 -0
  26. data/lib/tennpipes-su/bootstrap-less/font-awesome/path.less +14 -0
  27. data/lib/tennpipes-su/bootstrap-less/font-awesome/rotated-flipped.less +9 -0
  28. data/lib/tennpipes-su/bootstrap-less/font-awesome/spinning.less +30 -0
  29. data/lib/tennpipes-su/bootstrap-less/font-awesome/stacked.less +20 -0
  30. data/lib/tennpipes-su/bootstrap-less/font-awesome/variables.less +381 -0
  31. data/lib/tennpipes-su/bootstrap-less/forms.less +419 -0
  32. data/lib/tennpipes-su/bootstrap-less/glyphicons.less +233 -0
  33. data/lib/tennpipes-su/bootstrap-less/grid.less +100 -0
  34. data/lib/tennpipes-su/bootstrap-less/input-groups.less +157 -0
  35. data/lib/tennpipes-su/bootstrap-less/jumbotron.less +44 -0
  36. data/lib/tennpipes-su/bootstrap-less/labels.less +64 -0
  37. data/lib/tennpipes-su/bootstrap-less/list-group.less +110 -0
  38. data/lib/tennpipes-su/bootstrap-less/media.less +56 -0
  39. data/lib/tennpipes-su/bootstrap-less/mixins.less +926 -0
  40. data/lib/tennpipes-su/bootstrap-less/modals.less +138 -0
  41. data/lib/tennpipes-su/bootstrap-less/navbar.less +616 -0
  42. data/lib/tennpipes-su/bootstrap-less/navs.less +242 -0
  43. data/lib/tennpipes-su/bootstrap-less/normalize.less +423 -0
  44. data/lib/tennpipes-su/bootstrap-less/pager.less +55 -0
  45. data/lib/tennpipes-su/bootstrap-less/pagination.less +88 -0
  46. data/lib/tennpipes-su/bootstrap-less/panels.less +230 -0
  47. data/lib/tennpipes-su/bootstrap-less/popovers.less +133 -0
  48. data/lib/tennpipes-su/bootstrap-less/print.less +101 -0
  49. data/lib/tennpipes-su/bootstrap-less/progress-bars.less +80 -0
  50. data/lib/tennpipes-su/bootstrap-less/responsive-utilities.less +93 -0
  51. data/lib/tennpipes-su/bootstrap-less/scaffolding.less +134 -0
  52. data/lib/tennpipes-su/bootstrap-less/tables.less +233 -0
  53. data/lib/tennpipes-su/bootstrap-less/tennpipes-su.less +18 -0
  54. data/lib/tennpipes-su/bootstrap-less/theme.less +247 -0
  55. data/lib/tennpipes-su/bootstrap-less/thumbnails.less +36 -0
  56. data/lib/tennpipes-su/bootstrap-less/tooltip.less +95 -0
  57. data/lib/tennpipes-su/bootstrap-less/type.less +296 -0
  58. data/lib/tennpipes-su/bootstrap-less/utilities.less +56 -0
  59. data/lib/tennpipes-su/bootstrap-less/variables.less +827 -0
  60. data/lib/tennpipes-su/bootstrap-less/wells.less +29 -0
  61. data/lib/tennpipes-su/generators/actions.rb +78 -0
  62. data/lib/tennpipes-su/generators/admin_app.rb +169 -0
  63. data/lib/tennpipes-su/generators/admin_page.rb +68 -0
  64. data/lib/tennpipes-su/generators/orm.rb +172 -0
  65. data/lib/tennpipes-su/generators/templates/account/activerecord.rb.tt +41 -0
  66. data/lib/tennpipes-su/generators/templates/account/couchrest.rb.tt +67 -0
  67. data/lib/tennpipes-su/generators/templates/account/datamapper.rb.tt +56 -0
  68. data/lib/tennpipes-su/generators/templates/account/dynamoid.rb.tt +55 -0
  69. data/lib/tennpipes-su/generators/templates/account/minirecord.rb.tt +44 -0
  70. data/lib/tennpipes-su/generators/templates/account/mongoid.rb.tt +54 -0
  71. data/lib/tennpipes-su/generators/templates/account/mongomapper.rb.tt +47 -0
  72. data/lib/tennpipes-su/generators/templates/account/ohm.rb.tt +70 -0
  73. data/lib/tennpipes-su/generators/templates/account/seeds.rb.tt +29 -0
  74. data/lib/tennpipes-su/generators/templates/account/sequel.rb.tt +53 -0
  75. data/lib/tennpipes-su/generators/templates/app.rb.tt +42 -0
  76. data/lib/tennpipes-su/generators/templates/app/controllers/base.rb.tt +5 -0
  77. data/lib/tennpipes-su/generators/templates/app/controllers/sessions.rb.tt +29 -0
  78. data/lib/tennpipes-su/generators/templates/assets/images/favicon.ico +0 -0
  79. data/lib/tennpipes-su/generators/templates/assets/images/font/FontAwesome.otf +0 -0
  80. data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.eot +0 -0
  81. data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.svg +414 -0
  82. data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.ttf +0 -0
  83. data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.woff +0 -0
  84. data/lib/tennpipes-su/generators/templates/assets/images/logo.png +0 -0
  85. data/lib/tennpipes-su/generators/templates/assets/javascripts/application.js +118 -0
  86. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/affix.js +137 -0
  87. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/alert.js +88 -0
  88. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/bootstrap.min.js +6 -0
  89. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/button.js +107 -0
  90. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/carousel.js +205 -0
  91. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/collapse.js +170 -0
  92. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/dropdown.js +147 -0
  93. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/modal.js +243 -0
  94. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/popover.js +110 -0
  95. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/scrollspy.js +153 -0
  96. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/tab.js +125 -0
  97. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/tooltip.js +399 -0
  98. data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/transition.js +48 -0
  99. data/lib/tennpipes-su/generators/templates/assets/javascripts/jquery-1.11.0.min.js +4 -0
  100. data/lib/tennpipes-su/generators/templates/assets/stylesheets/application.css +353 -0
  101. data/lib/tennpipes-su/generators/templates/assets/stylesheets/bootstrap.css +4 -0
  102. data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/FontAwesome.otf +0 -0
  103. data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.eot +0 -0
  104. data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.svg +414 -0
  105. data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.ttf +0 -0
  106. data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.woff +0 -0
  107. data/lib/tennpipes-su/generators/templates/erb/app/base/index.erb.tt +15 -0
  108. data/lib/tennpipes-su/generators/templates/erb/app/errors/403.erb.tt +3 -0
  109. data/lib/tennpipes-su/generators/templates/erb/app/errors/404.erb.tt +3 -0
  110. data/lib/tennpipes-su/generators/templates/erb/app/errors/500.erb.tt +3 -0
  111. data/lib/tennpipes-su/generators/templates/erb/app/layouts/application.erb.tt +64 -0
  112. data/lib/tennpipes-su/generators/templates/erb/app/layouts/error.erb.tt +23 -0
  113. data/lib/tennpipes-su/generators/templates/erb/app/sessions/new.erb.tt +44 -0
  114. data/lib/tennpipes-su/generators/templates/erb/page/_form.erb.tt +18 -0
  115. data/lib/tennpipes-su/generators/templates/erb/page/edit.erb.tt +10 -0
  116. data/lib/tennpipes-su/generators/templates/erb/page/index.erb.tt +81 -0
  117. data/lib/tennpipes-su/generators/templates/erb/page/new.erb.tt +9 -0
  118. data/lib/tennpipes-su/generators/templates/haml/app/base/index.haml.tt +12 -0
  119. data/lib/tennpipes-su/generators/templates/haml/app/errors/403.haml.tt +3 -0
  120. data/lib/tennpipes-su/generators/templates/haml/app/errors/404.haml.tt +3 -0
  121. data/lib/tennpipes-su/generators/templates/haml/app/errors/500.haml.tt +3 -0
  122. data/lib/tennpipes-su/generators/templates/haml/app/layouts/application.haml.tt +49 -0
  123. data/lib/tennpipes-su/generators/templates/haml/app/layouts/error.haml.tt +18 -0
  124. data/lib/tennpipes-su/generators/templates/haml/app/sessions/new.haml.tt +38 -0
  125. data/lib/tennpipes-su/generators/templates/haml/page/_form.haml.tt +16 -0
  126. data/lib/tennpipes-su/generators/templates/haml/page/edit.haml.tt +8 -0
  127. data/lib/tennpipes-su/generators/templates/haml/page/index.haml.tt +58 -0
  128. data/lib/tennpipes-su/generators/templates/haml/page/new.haml.tt +7 -0
  129. data/lib/tennpipes-su/generators/templates/page/controller.rb.tt +92 -0
  130. data/lib/tennpipes-su/generators/templates/slim/app/base/index.slim.tt +12 -0
  131. data/lib/tennpipes-su/generators/templates/slim/app/errors/403.slim.tt +3 -0
  132. data/lib/tennpipes-su/generators/templates/slim/app/errors/404.slim.tt +3 -0
  133. data/lib/tennpipes-su/generators/templates/slim/app/errors/500.slim.tt +3 -0
  134. data/lib/tennpipes-su/generators/templates/slim/app/layouts/application.slim.tt +48 -0
  135. data/lib/tennpipes-su/generators/templates/slim/app/layouts/error.slim.tt +19 -0
  136. data/lib/tennpipes-su/generators/templates/slim/app/sessions/new.slim.tt +37 -0
  137. data/lib/tennpipes-su/generators/templates/slim/page/_form.slim.tt +16 -0
  138. data/lib/tennpipes-su/generators/templates/slim/page/edit.slim.tt +8 -0
  139. data/lib/tennpipes-su/generators/templates/slim/page/index.slim.tt +56 -0
  140. data/lib/tennpipes-su/generators/templates/slim/page/new.slim.tt +7 -0
  141. data/lib/tennpipes-su/helpers/authentication_helpers.rb +108 -0
  142. data/lib/tennpipes-su/helpers/view_helpers.rb +87 -0
  143. data/lib/tennpipes-su/locale/admin/cs.yml +56 -0
  144. data/lib/tennpipes-su/locale/admin/da.yml +56 -0
  145. data/lib/tennpipes-su/locale/admin/de.yml +56 -0
  146. data/lib/tennpipes-su/locale/admin/en.yml +56 -0
  147. data/lib/tennpipes-su/locale/admin/es.yml +56 -0
  148. data/lib/tennpipes-su/locale/admin/fr.yml +56 -0
  149. data/lib/tennpipes-su/locale/admin/hu.yml +56 -0
  150. data/lib/tennpipes-su/locale/admin/it.yml +56 -0
  151. data/lib/tennpipes-su/locale/admin/ja.yml +57 -0
  152. data/lib/tennpipes-su/locale/admin/lv.yml +56 -0
  153. data/lib/tennpipes-su/locale/admin/nl.yml +56 -0
  154. data/lib/tennpipes-su/locale/admin/no.yml +56 -0
  155. data/lib/tennpipes-su/locale/admin/pl.yml +56 -0
  156. data/lib/tennpipes-su/locale/admin/pt_br.yml +56 -0
  157. data/lib/tennpipes-su/locale/admin/ro.yml +56 -0
  158. data/lib/tennpipes-su/locale/admin/ru.yml +57 -0
  159. data/lib/tennpipes-su/locale/admin/sv.yml +56 -0
  160. data/lib/tennpipes-su/locale/admin/tr.yml +56 -0
  161. data/lib/tennpipes-su/locale/admin/uk.yml +56 -0
  162. data/lib/tennpipes-su/locale/admin/zh_cn.yml +56 -0
  163. data/lib/tennpipes-su/locale/admin/zh_tw.yml +56 -0
  164. data/lib/tennpipes-su/locale/orm/cs.yml +12 -0
  165. data/lib/tennpipes-su/locale/orm/da.yml +12 -0
  166. data/lib/tennpipes-su/locale/orm/de.yml +12 -0
  167. data/lib/tennpipes-su/locale/orm/en.yml +12 -0
  168. data/lib/tennpipes-su/locale/orm/es.yml +12 -0
  169. data/lib/tennpipes-su/locale/orm/fr.yml +12 -0
  170. data/lib/tennpipes-su/locale/orm/hu.yml +12 -0
  171. data/lib/tennpipes-su/locale/orm/it.yml +12 -0
  172. data/lib/tennpipes-su/locale/orm/ja.yml +12 -0
  173. data/lib/tennpipes-su/locale/orm/lv.yml +12 -0
  174. data/lib/tennpipes-su/locale/orm/nl.yml +12 -0
  175. data/lib/tennpipes-su/locale/orm/no.yml +12 -0
  176. data/lib/tennpipes-su/locale/orm/pl.yml +38 -0
  177. data/lib/tennpipes-su/locale/orm/pt_br.yml +12 -0
  178. data/lib/tennpipes-su/locale/orm/ro.yml +12 -0
  179. data/lib/tennpipes-su/locale/orm/ru.yml +12 -0
  180. data/lib/tennpipes-su/locale/orm/sv.yml +12 -0
  181. data/lib/tennpipes-su/locale/orm/tr.yml +12 -0
  182. data/lib/tennpipes-su/locale/orm/uk.yml +12 -0
  183. data/lib/tennpipes-su/locale/orm/zh_cn.yml +12 -0
  184. data/lib/tennpipes-su/locale/orm/zh_tw.yml +12 -0
  185. data/test/fixtures/sequel.rb +72 -0
  186. data/test/generators/test_account_model_generator.rb +108 -0
  187. data/test/generators/test_admin_app_generator.rb +218 -0
  188. data/test/generators/test_admin_page_generator.rb +140 -0
  189. data/test/helper.rb +47 -0
  190. data/test/test_admin_application.rb +271 -0
  191. data/test/test_locale.rb +25 -0
  192. metadata +298 -0
@@ -0,0 +1,41 @@
1
+ class <%= @model_name %> < ActiveRecord::Base
2
+ attr_accessor :password, :password_confirmation
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 :encrypt_password, :if => :password_required
17
+
18
+ ##
19
+ # This method is for authentication purpose.
20
+ #
21
+ def self.authenticate(email, password)
22
+ account = where("lower(email) = lower(?)", email).first if email.present?
23
+ account && account.has_password?(password) ? account : nil
24
+ end
25
+
26
+ def has_password?(password)
27
+ ::BCrypt::Password.new(crypted_password) == password
28
+ end
29
+
30
+ private
31
+
32
+ def encrypt_password
33
+ value = ::BCrypt::Password.create(password)
34
+ value = value.force_encoding(Encoding::UTF_8) if value.encoding == Encoding::ASCII_8BIT
35
+ self.crypted_password = value
36
+ end
37
+
38
+ def password_required
39
+ crypted_password.blank? || password.present?
40
+ end
41
+ end
@@ -0,0 +1,67 @@
1
+ class <%= @model_name %> < CouchRest::Model::Base
2
+ attr_accessor :password, :password_confirmation
3
+
4
+ # Properties
5
+ property :name
6
+ property :surname
7
+ property :email
8
+ property :crypted_password
9
+ property :role
10
+
11
+ view_by :email
12
+
13
+ # Validations
14
+ validates_presence_of :email, :role
15
+ validates_presence_of :password, :if => :password_required
16
+ validates_presence_of :password_confirmation, :if => :password_required
17
+ validates_length_of :password, :within => 4..40, :if => :password_required
18
+ validates_confirmation_of :password, :if => :password_required
19
+ validates_length_of :email, :within => 3..100
20
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
21
+ validates_format_of :role, :with => /[A-Za-z]/
22
+ validate :unique_email_validator
23
+
24
+ # Callbacks
25
+ after_validation :encrypt_password, :if => :password_required
26
+
27
+ ##
28
+ # This method is for authentication purpose.
29
+ #
30
+ def self.authenticate(email, password)
31
+ account = find_by_email(email)
32
+ account if account && account.has_password?(password)
33
+ end
34
+
35
+ def has_password?(password)
36
+ ::BCrypt::Password.new(crypted_password) == password
37
+ end
38
+
39
+ ##
40
+ # This method is used by AuthenticationHelper.
41
+ #
42
+ def self.find_by_id(id)
43
+ get(id)
44
+ end
45
+
46
+ private
47
+
48
+ def encrypt_password
49
+ self.crypted_password = ::BCrypt::Password.create(password)
50
+ end
51
+
52
+ def password_required
53
+ crypted_password.blank? || password.present?
54
+ end
55
+
56
+ def unique_email_validator
57
+ account = self.class.find_by_email(email)
58
+
59
+ # Didn't find email in the database.
60
+ return if account.nil?
61
+
62
+ # Account with same email in database is this account.
63
+ return if has_key?('_id') && self['_id'] == account['_id']
64
+
65
+ errors.add(:email, "is not unique")
66
+ end
67
+ end
@@ -0,0 +1,56 @@
1
+ class <%= @model_name %>
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, :length => 70
12
+ property :role, String
13
+
14
+ # Validations
15
+ validates_presence_of :email, :role
16
+ validates_presence_of :password, :if => :password_required
17
+ validates_presence_of :password_confirmation, :if => :password_required
18
+ validates_length_of :password, :min => 4, :max => 40, :if => :password_required
19
+ validates_confirmation_of :password, :if => :password_required
20
+ validates_length_of :email, :min => 3, :max => 100
21
+ validates_uniqueness_of :email, :case_sensitive => false
22
+ validates_format_of :email, :with => :email_address
23
+ validates_format_of :role, :with => /[A-Za-z]/
24
+
25
+ # Callbacks
26
+ before :save, :encrypt_password
27
+
28
+ ##
29
+ # This method is for authentication purpose.
30
+ #
31
+ def self.authenticate(email, password)
32
+ account = first(:conditions => ["lower(email) = lower(?)", email]) if email.present?
33
+ account && account.has_password?(password) ? account : nil
34
+ end
35
+
36
+ ##
37
+ # This method is used by AuthenticationHelper
38
+ #
39
+ def self.find_by_id(id)
40
+ get(id) rescue nil
41
+ end
42
+
43
+ def has_password?(password)
44
+ ::BCrypt::Password.new(crypted_password) == password
45
+ end
46
+
47
+ private
48
+
49
+ def password_required
50
+ crypted_password.blank? || password.present?
51
+ end
52
+
53
+ def encrypt_password
54
+ self.crypted_password = ::BCrypt::Password.create(password) if password.present?
55
+ end
56
+ end
@@ -0,0 +1,55 @@
1
+ class <%= @model_name %>
2
+ include Dynamoid::Document
3
+ attr_accessor :password, :password_confirmation
4
+
5
+ # Fields
6
+ field :name
7
+ field :surname
8
+ field :email
9
+ field :crypted_password
10
+ field :role
11
+
12
+ # Validations
13
+ validates_presence_of :email, :role
14
+ validates_presence_of :password, :if => :password_required
15
+ validates_presence_of :password_confirmation, :if => :password_required
16
+ validates_length_of :password, :within => 4..40, :if => :password_required
17
+ validates_confirmation_of :password, :if => :password_required
18
+ validates_length_of :email, :within => 3..100
19
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
20
+ validates_format_of :role, :with => /[A-Za-z]/
21
+
22
+ # Callbacks
23
+ before_save :encrypt_password, :if => :password_required
24
+
25
+ ##
26
+ # This method is for authentication purpose.
27
+ #
28
+ def self.authenticate(email, password)
29
+ account = find_by_email(email) if email.present?
30
+ account && account.has_password?(password) ? account : nil
31
+ end
32
+
33
+ ##
34
+ # This method is used by AuthenticationHelper.
35
+ #
36
+ def self.find_by_id(id, options = {})
37
+ id ? super(id, options) : nil
38
+ end
39
+
40
+ def has_password?(password)
41
+ ::BCrypt::Password.new(crypted_password) == password
42
+ end
43
+
44
+ private
45
+
46
+ def encrypt_password
47
+ value = ::BCrypt::Password.create(password)
48
+ value = value.force_encoding(Encoding::UTF_8) if value.encoding == Encoding::ASCII_8BIT
49
+ self.crypted_password = value
50
+ end
51
+
52
+ def password_required
53
+ crypted_password.blank? || password.present?
54
+ end
55
+ end
@@ -0,0 +1,44 @@
1
+ class <%= @model_name %> < ActiveRecord::Base
2
+ attr_accessor :password, :password_confirmation
3
+
4
+ # Fields
5
+ field :name, :surname, :email, :crypted_password, :role
6
+
7
+ # Validations
8
+ validates_presence_of :email, :role
9
+ validates_presence_of :password, :if => :password_required
10
+ validates_presence_of :password_confirmation, :if => :password_required
11
+ validates_length_of :password, :within => 4..40, :if => :password_required
12
+ validates_confirmation_of :password, :if => :password_required
13
+ validates_length_of :email, :within => 3..100
14
+ validates_uniqueness_of :email, :case_sensitive => false
15
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
16
+ validates_format_of :role, :with => /[A-Za-z]/
17
+
18
+ # Callbacks
19
+ before_save :encrypt_password, :if => :password_required
20
+
21
+ ##
22
+ # This method is for authentication purpose.
23
+ #
24
+ def self.authenticate(email, password)
25
+ account = where("lower(email) = lower(?)", email).first if email.present?
26
+ account && account.has_password?(password) ? account : nil
27
+ end
28
+
29
+ def has_password?(password)
30
+ ::BCrypt::Password.new(crypted_password) == password
31
+ end
32
+
33
+ private
34
+
35
+ def encrypt_password
36
+ value = ::BCrypt::Password.create(password)
37
+ value = value.force_encoding(Encoding::UTF_8) if value.encoding == Encoding::ASCII_8BIT
38
+ self.crypted_password = value
39
+ end
40
+
41
+ def password_required
42
+ crypted_password.blank? || password.present?
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ class <%= @model_name %>
2
+ include Mongoid::Document
3
+ attr_accessor :password, :password_confirmation
4
+
5
+ # Fields
6
+ field :name, :type => String
7
+ field :surname, :type => String
8
+ field :email, :type => String
9
+ field :crypted_password, :type => String
10
+ field :role, :type => String
11
+
12
+ # Validations
13
+ validates_presence_of :email, :role
14
+ validates_presence_of :password, :if => :password_required
15
+ validates_presence_of :password_confirmation, :if => :password_required
16
+ validates_length_of :password, :within => 4..40, :if => :password_required
17
+ validates_confirmation_of :password, :if => :password_required
18
+ validates_length_of :email, :within => 3..100
19
+ validates_uniqueness_of :email, :case_sensitive => false
20
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
21
+ validates_format_of :role, :with => /[A-Za-z]/
22
+
23
+ # Callbacks
24
+ before_save :encrypt_password, :if => :password_required
25
+
26
+ ##
27
+ # This method is for authentication purpose.
28
+ #
29
+ def self.authenticate(email, password)
30
+ account = where(:email => /#{Regexp.escape(email)}/i).first if email.present?
31
+ account && account.has_password?(password) ? account : nil
32
+ end
33
+
34
+ ##
35
+ # This method is used by AuthenticationHelper.
36
+ #
37
+ def self.find_by_id(id)
38
+ find(id) rescue nil
39
+ end
40
+
41
+ def has_password?(password)
42
+ ::BCrypt::Password.new(crypted_password) == password
43
+ end
44
+
45
+ private
46
+
47
+ def encrypt_password
48
+ self.crypted_password = ::BCrypt::Password.create(self.password)
49
+ end
50
+
51
+ def password_required
52
+ crypted_password.blank? || self.password.present?
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ class <%= @model_name %>
2
+ include MongoMapper::Document
3
+ attr_accessor :password, :password_confirmation
4
+
5
+ # Keys
6
+ key :name, String
7
+ key :surname, String
8
+ key :email, String
9
+ key :crypted_password, String
10
+ key :role, String
11
+
12
+ # Validations
13
+ validates_presence_of :email, :role
14
+ validates_presence_of :password, :if => :password_required
15
+ validates_presence_of :password_confirmation, :if => :password_required
16
+ validates_length_of :password, :within => 4..40, :if => :password_required
17
+ validates_confirmation_of :password, :if => :password_required
18
+ validates_length_of :email, :within => 3..100
19
+ validates_uniqueness_of :email, :case_sensitive => false
20
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
21
+ validates_format_of :role, :with => /[A-Za-z]/
22
+
23
+ # Callbacks
24
+ before_save :encrypt_password, :if => :password_required
25
+
26
+ ##
27
+ # This method is for authentication purpose.
28
+ #
29
+ def self.authenticate(email, password)
30
+ account = first(:email => /#{Regexp.escape(email)}/i) if email.present?
31
+ account && account.has_password?(password) ? account : nil
32
+ end
33
+
34
+ def has_password?(password)
35
+ ::BCrypt::Password.new(crypted_password) == password
36
+ end
37
+
38
+ private
39
+
40
+ def encrypt_password
41
+ self.crypted_password = ::BCrypt::Password.create(password)
42
+ end
43
+
44
+ def password_required
45
+ crypted_password.blank? || password.present?
46
+ end
47
+ end
@@ -0,0 +1,70 @@
1
+ class Account < Ohm::Model
2
+ attr_accessor :password, :password_confirmation
3
+
4
+ # Keys
5
+ attribute :name
6
+ attribute :surname
7
+ attribute :email
8
+ attribute :crypted_password
9
+ attribute :role
10
+
11
+ index :email
12
+ unique :email
13
+
14
+ # Validations
15
+ def validate
16
+ assert_present :email
17
+ assert_present :role
18
+ if password_required
19
+ assert_present :password
20
+ assert_present :password_confirmation
21
+ assert_length :password, 4..40
22
+ assert self.password == self.password_confirmation, [:password_not_confirmed]
23
+ end
24
+ assert_email :email
25
+ assert_format :role, /[A-Za-z]/
26
+ end
27
+
28
+ # Callbacks
29
+ def save!
30
+ encrypt_password
31
+ super
32
+ end
33
+
34
+ ##
35
+ # This method is for authentication purpose.
36
+ #
37
+ def self.authenticate(email, password)
38
+ account = with(:email, email) if email.present?
39
+ account && account.has_password?(password) ? account : nil
40
+ end
41
+
42
+ ##
43
+ # This method is used by AuthenticationHelper.
44
+ #
45
+ def self.find_by_id(id)
46
+ self[id]
47
+ end
48
+
49
+ ##
50
+ # This method is used by Admin Sessions Controller for login bypass.
51
+ #
52
+ def self.first
53
+ first_id = key[:all].sort(:order => "asc", :limit => [0,1]).first
54
+ self[first_id] if first_id
55
+ end
56
+
57
+ def has_password?(password)
58
+ ::BCrypt::Password.new(crypted_password) == password
59
+ end
60
+
61
+ private
62
+
63
+ def encrypt_password
64
+ self.crypted_password = ::BCrypt::Password.create(password) if password_required
65
+ end
66
+
67
+ def password_required
68
+ crypted_password.blank? || password.present?
69
+ end
70
+ end
@@ -0,0 +1,29 @@
1
+ # Seed add you the ability to populate your db.
2
+ # We provide you a basic shell for interaction with the end user.
3
+ # So try some code like below:
4
+ #
5
+ # name = shell.ask("What's your name?")
6
+ # shell.say name
7
+ #
8
+ email = shell.ask "Which email do you want use for logging into admin?"
9
+ password = shell.ask "Tell me the password to use:"
10
+
11
+ shell.say ""
12
+
13
+ account = <%= @model_name %>.new(:email => email, :name => "Foo", :surname => "Bar", :password => password, :password_confirmation => password, :role => "admin")
14
+
15
+ if account.valid?
16
+ account.save
17
+ shell.say "================================================================="
18
+ shell.say "<%= @model_name %> has been successfully created, now you can login with:"
19
+ shell.say "================================================================="
20
+ shell.say " email: #{email}"
21
+ shell.say " password: #{password}"
22
+ shell.say "================================================================="
23
+ else
24
+ shell.say "Sorry, but something went wrong!"
25
+ shell.say ""
26
+ account.errors.full_messages.each { |m| shell.say " - #{m}" }
27
+ end
28
+
29
+ shell.say ""