tennpipes-su 3.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +70 -0
- data/Rakefile +22 -0
- data/lib/tennpipes-su.rb +35 -0
- data/lib/tennpipes-su/access_control.rb +191 -0
- data/lib/tennpipes-su/bootstrap-less/alerts.less +67 -0
- data/lib/tennpipes-su/bootstrap-less/badges.less +55 -0
- data/lib/tennpipes-su/bootstrap-less/bootstrap.less +49 -0
- data/lib/tennpipes-su/bootstrap-less/breadcrumbs.less +26 -0
- data/lib/tennpipes-su/bootstrap-less/button-groups.less +226 -0
- data/lib/tennpipes-su/bootstrap-less/buttons.less +155 -0
- data/lib/tennpipes-su/bootstrap-less/carousel.less +232 -0
- data/lib/tennpipes-su/bootstrap-less/close.less +33 -0
- data/lib/tennpipes-su/bootstrap-less/code.less +63 -0
- data/lib/tennpipes-su/bootstrap-less/component-animations.less +29 -0
- data/lib/tennpipes-su/bootstrap-less/dropdowns.less +213 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/bordered-pulled.less +16 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/core.less +12 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/fixed-width.less +6 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/font-awesome.less +17 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/icons.less +412 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/larger.less +13 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/list.less +19 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/mixins.less +20 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/path.less +14 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/rotated-flipped.less +9 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/spinning.less +30 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/stacked.less +20 -0
- data/lib/tennpipes-su/bootstrap-less/font-awesome/variables.less +381 -0
- data/lib/tennpipes-su/bootstrap-less/forms.less +419 -0
- data/lib/tennpipes-su/bootstrap-less/glyphicons.less +233 -0
- data/lib/tennpipes-su/bootstrap-less/grid.less +100 -0
- data/lib/tennpipes-su/bootstrap-less/input-groups.less +157 -0
- data/lib/tennpipes-su/bootstrap-less/jumbotron.less +44 -0
- data/lib/tennpipes-su/bootstrap-less/labels.less +64 -0
- data/lib/tennpipes-su/bootstrap-less/list-group.less +110 -0
- data/lib/tennpipes-su/bootstrap-less/media.less +56 -0
- data/lib/tennpipes-su/bootstrap-less/mixins.less +926 -0
- data/lib/tennpipes-su/bootstrap-less/modals.less +138 -0
- data/lib/tennpipes-su/bootstrap-less/navbar.less +616 -0
- data/lib/tennpipes-su/bootstrap-less/navs.less +242 -0
- data/lib/tennpipes-su/bootstrap-less/normalize.less +423 -0
- data/lib/tennpipes-su/bootstrap-less/pager.less +55 -0
- data/lib/tennpipes-su/bootstrap-less/pagination.less +88 -0
- data/lib/tennpipes-su/bootstrap-less/panels.less +230 -0
- data/lib/tennpipes-su/bootstrap-less/popovers.less +133 -0
- data/lib/tennpipes-su/bootstrap-less/print.less +101 -0
- data/lib/tennpipes-su/bootstrap-less/progress-bars.less +80 -0
- data/lib/tennpipes-su/bootstrap-less/responsive-utilities.less +93 -0
- data/lib/tennpipes-su/bootstrap-less/scaffolding.less +134 -0
- data/lib/tennpipes-su/bootstrap-less/tables.less +233 -0
- data/lib/tennpipes-su/bootstrap-less/tennpipes-su.less +18 -0
- data/lib/tennpipes-su/bootstrap-less/theme.less +247 -0
- data/lib/tennpipes-su/bootstrap-less/thumbnails.less +36 -0
- data/lib/tennpipes-su/bootstrap-less/tooltip.less +95 -0
- data/lib/tennpipes-su/bootstrap-less/type.less +296 -0
- data/lib/tennpipes-su/bootstrap-less/utilities.less +56 -0
- data/lib/tennpipes-su/bootstrap-less/variables.less +827 -0
- data/lib/tennpipes-su/bootstrap-less/wells.less +29 -0
- data/lib/tennpipes-su/generators/actions.rb +78 -0
- data/lib/tennpipes-su/generators/admin_app.rb +169 -0
- data/lib/tennpipes-su/generators/admin_page.rb +68 -0
- data/lib/tennpipes-su/generators/orm.rb +172 -0
- data/lib/tennpipes-su/generators/templates/account/activerecord.rb.tt +41 -0
- data/lib/tennpipes-su/generators/templates/account/couchrest.rb.tt +67 -0
- data/lib/tennpipes-su/generators/templates/account/datamapper.rb.tt +56 -0
- data/lib/tennpipes-su/generators/templates/account/dynamoid.rb.tt +55 -0
- data/lib/tennpipes-su/generators/templates/account/minirecord.rb.tt +44 -0
- data/lib/tennpipes-su/generators/templates/account/mongoid.rb.tt +54 -0
- data/lib/tennpipes-su/generators/templates/account/mongomapper.rb.tt +47 -0
- data/lib/tennpipes-su/generators/templates/account/ohm.rb.tt +70 -0
- data/lib/tennpipes-su/generators/templates/account/seeds.rb.tt +29 -0
- data/lib/tennpipes-su/generators/templates/account/sequel.rb.tt +53 -0
- data/lib/tennpipes-su/generators/templates/app.rb.tt +42 -0
- data/lib/tennpipes-su/generators/templates/app/controllers/base.rb.tt +5 -0
- data/lib/tennpipes-su/generators/templates/app/controllers/sessions.rb.tt +29 -0
- data/lib/tennpipes-su/generators/templates/assets/images/favicon.ico +0 -0
- data/lib/tennpipes-su/generators/templates/assets/images/font/FontAwesome.otf +0 -0
- data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.eot +0 -0
- data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.svg +414 -0
- data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.ttf +0 -0
- data/lib/tennpipes-su/generators/templates/assets/images/font/fontawesome-webfont.woff +0 -0
- data/lib/tennpipes-su/generators/templates/assets/images/logo.png +0 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/application.js +118 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/affix.js +137 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/alert.js +88 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/bootstrap.min.js +6 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/button.js +107 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/carousel.js +205 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/collapse.js +170 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/dropdown.js +147 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/modal.js +243 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/popover.js +110 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/scrollspy.js +153 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/tab.js +125 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/tooltip.js +399 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/bootstrap/transition.js +48 -0
- data/lib/tennpipes-su/generators/templates/assets/javascripts/jquery-1.11.0.min.js +4 -0
- data/lib/tennpipes-su/generators/templates/assets/stylesheets/application.css +353 -0
- data/lib/tennpipes-su/generators/templates/assets/stylesheets/bootstrap.css +4 -0
- data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/FontAwesome.otf +0 -0
- data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.eot +0 -0
- data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.svg +414 -0
- data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/tennpipes-su/generators/templates/assets/stylesheets/fonts/fontawesome-webfont.woff +0 -0
- data/lib/tennpipes-su/generators/templates/erb/app/base/index.erb.tt +15 -0
- data/lib/tennpipes-su/generators/templates/erb/app/errors/403.erb.tt +3 -0
- data/lib/tennpipes-su/generators/templates/erb/app/errors/404.erb.tt +3 -0
- data/lib/tennpipes-su/generators/templates/erb/app/errors/500.erb.tt +3 -0
- data/lib/tennpipes-su/generators/templates/erb/app/layouts/application.erb.tt +64 -0
- data/lib/tennpipes-su/generators/templates/erb/app/layouts/error.erb.tt +23 -0
- data/lib/tennpipes-su/generators/templates/erb/app/sessions/new.erb.tt +44 -0
- data/lib/tennpipes-su/generators/templates/erb/page/_form.erb.tt +18 -0
- data/lib/tennpipes-su/generators/templates/erb/page/edit.erb.tt +10 -0
- data/lib/tennpipes-su/generators/templates/erb/page/index.erb.tt +81 -0
- data/lib/tennpipes-su/generators/templates/erb/page/new.erb.tt +9 -0
- data/lib/tennpipes-su/generators/templates/haml/app/base/index.haml.tt +12 -0
- data/lib/tennpipes-su/generators/templates/haml/app/errors/403.haml.tt +3 -0
- data/lib/tennpipes-su/generators/templates/haml/app/errors/404.haml.tt +3 -0
- data/lib/tennpipes-su/generators/templates/haml/app/errors/500.haml.tt +3 -0
- data/lib/tennpipes-su/generators/templates/haml/app/layouts/application.haml.tt +49 -0
- data/lib/tennpipes-su/generators/templates/haml/app/layouts/error.haml.tt +18 -0
- data/lib/tennpipes-su/generators/templates/haml/app/sessions/new.haml.tt +38 -0
- data/lib/tennpipes-su/generators/templates/haml/page/_form.haml.tt +16 -0
- data/lib/tennpipes-su/generators/templates/haml/page/edit.haml.tt +8 -0
- data/lib/tennpipes-su/generators/templates/haml/page/index.haml.tt +58 -0
- data/lib/tennpipes-su/generators/templates/haml/page/new.haml.tt +7 -0
- data/lib/tennpipes-su/generators/templates/page/controller.rb.tt +92 -0
- data/lib/tennpipes-su/generators/templates/slim/app/base/index.slim.tt +12 -0
- data/lib/tennpipes-su/generators/templates/slim/app/errors/403.slim.tt +3 -0
- data/lib/tennpipes-su/generators/templates/slim/app/errors/404.slim.tt +3 -0
- data/lib/tennpipes-su/generators/templates/slim/app/errors/500.slim.tt +3 -0
- data/lib/tennpipes-su/generators/templates/slim/app/layouts/application.slim.tt +48 -0
- data/lib/tennpipes-su/generators/templates/slim/app/layouts/error.slim.tt +19 -0
- data/lib/tennpipes-su/generators/templates/slim/app/sessions/new.slim.tt +37 -0
- data/lib/tennpipes-su/generators/templates/slim/page/_form.slim.tt +16 -0
- data/lib/tennpipes-su/generators/templates/slim/page/edit.slim.tt +8 -0
- data/lib/tennpipes-su/generators/templates/slim/page/index.slim.tt +56 -0
- data/lib/tennpipes-su/generators/templates/slim/page/new.slim.tt +7 -0
- data/lib/tennpipes-su/helpers/authentication_helpers.rb +108 -0
- data/lib/tennpipes-su/helpers/view_helpers.rb +87 -0
- data/lib/tennpipes-su/locale/admin/cs.yml +56 -0
- data/lib/tennpipes-su/locale/admin/da.yml +56 -0
- data/lib/tennpipes-su/locale/admin/de.yml +56 -0
- data/lib/tennpipes-su/locale/admin/en.yml +56 -0
- data/lib/tennpipes-su/locale/admin/es.yml +56 -0
- data/lib/tennpipes-su/locale/admin/fr.yml +56 -0
- data/lib/tennpipes-su/locale/admin/hu.yml +56 -0
- data/lib/tennpipes-su/locale/admin/it.yml +56 -0
- data/lib/tennpipes-su/locale/admin/ja.yml +57 -0
- data/lib/tennpipes-su/locale/admin/lv.yml +56 -0
- data/lib/tennpipes-su/locale/admin/nl.yml +56 -0
- data/lib/tennpipes-su/locale/admin/no.yml +56 -0
- data/lib/tennpipes-su/locale/admin/pl.yml +56 -0
- data/lib/tennpipes-su/locale/admin/pt_br.yml +56 -0
- data/lib/tennpipes-su/locale/admin/ro.yml +56 -0
- data/lib/tennpipes-su/locale/admin/ru.yml +57 -0
- data/lib/tennpipes-su/locale/admin/sv.yml +56 -0
- data/lib/tennpipes-su/locale/admin/tr.yml +56 -0
- data/lib/tennpipes-su/locale/admin/uk.yml +56 -0
- data/lib/tennpipes-su/locale/admin/zh_cn.yml +56 -0
- data/lib/tennpipes-su/locale/admin/zh_tw.yml +56 -0
- data/lib/tennpipes-su/locale/orm/cs.yml +12 -0
- data/lib/tennpipes-su/locale/orm/da.yml +12 -0
- data/lib/tennpipes-su/locale/orm/de.yml +12 -0
- data/lib/tennpipes-su/locale/orm/en.yml +12 -0
- data/lib/tennpipes-su/locale/orm/es.yml +12 -0
- data/lib/tennpipes-su/locale/orm/fr.yml +12 -0
- data/lib/tennpipes-su/locale/orm/hu.yml +12 -0
- data/lib/tennpipes-su/locale/orm/it.yml +12 -0
- data/lib/tennpipes-su/locale/orm/ja.yml +12 -0
- data/lib/tennpipes-su/locale/orm/lv.yml +12 -0
- data/lib/tennpipes-su/locale/orm/nl.yml +12 -0
- data/lib/tennpipes-su/locale/orm/no.yml +12 -0
- data/lib/tennpipes-su/locale/orm/pl.yml +38 -0
- data/lib/tennpipes-su/locale/orm/pt_br.yml +12 -0
- data/lib/tennpipes-su/locale/orm/ro.yml +12 -0
- data/lib/tennpipes-su/locale/orm/ru.yml +12 -0
- data/lib/tennpipes-su/locale/orm/sv.yml +12 -0
- data/lib/tennpipes-su/locale/orm/tr.yml +12 -0
- data/lib/tennpipes-su/locale/orm/uk.yml +12 -0
- data/lib/tennpipes-su/locale/orm/zh_cn.yml +12 -0
- data/lib/tennpipes-su/locale/orm/zh_tw.yml +12 -0
- data/test/fixtures/sequel.rb +72 -0
- data/test/generators/test_account_model_generator.rb +108 -0
- data/test/generators/test_admin_app_generator.rb +218 -0
- data/test/generators/test_admin_page_generator.rb +140 -0
- data/test/helper.rb +47 -0
- data/test/test_admin_application.rb +271 -0
- data/test/test_locale.rb +25 -0
- 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 ""
|