pbw 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +8 -8
  2. data/app/controllers/pbw/application_controller.rb +3 -16
  3. data/app/controllers/pbw/base_models_controller.rb +10 -32
  4. data/app/controllers/pbw/passwords_controller.rb +14 -0
  5. data/app/controllers/pbw/registrations_controller.rb +9 -6
  6. data/app/controllers/pbw/sessions_controller.rb +9 -4
  7. data/app/mailers/pbw/user_mailer.rb +16 -0
  8. data/app/models/pbw/area.rb +5 -5
  9. data/app/models/pbw/attached_process.rb +3 -3
  10. data/app/models/pbw/capability.rb +1 -1
  11. data/app/models/pbw/command.rb +2 -2
  12. data/app/models/pbw/constraint.rb +2 -2
  13. data/app/models/pbw/item.rb +2 -2
  14. data/app/models/pbw/item_container.rb +4 -4
  15. data/app/models/pbw/item_conversion.rb +1 -1
  16. data/app/models/pbw/process.rb +2 -2
  17. data/app/models/pbw/token.rb +7 -7
  18. data/app/models/pbw/trigger.rb +3 -3
  19. data/app/models/pbw/user.rb +30 -8
  20. data/config/initializers/devise.rb +1 -66
  21. data/config/locales/pbw.en.yml +7 -0
  22. data/config/routes.rb +2 -4
  23. data/lib/generators/pbw/install/install_generator.rb +22 -3
  24. data/lib/generators/pbw/model_generator.rb +6 -0
  25. data/lib/generators/pbw/resource_helpers.rb +16 -0
  26. data/lib/generators/pbw/rules/capability/capability_generator.rb +4 -2
  27. data/lib/generators/pbw/rules/constraint/constraint_generator.rb +4 -2
  28. data/lib/generators/pbw/rules/process/process_generator.rb +4 -2
  29. data/lib/generators/pbw/rules/trigger/trigger_generator.rb +4 -2
  30. data/lib/generators/pbw/scaffold_generator.rb +0 -12
  31. data/lib/generators/pbw/templates/app.coffee +5 -3
  32. data/lib/generators/pbw/templates/application.erb +24 -0
  33. data/lib/generators/pbw/templates/lifecycle.rb +1 -0
  34. data/lib/generators/pbw/templates/pbw.coffee +21 -0
  35. data/lib/generators/pbw/templates/router.coffee +15 -0
  36. data/lib/generators/pbw/templates/templates/home.jst +10 -1
  37. data/lib/generators/pbw/templates/templates/login.jst +25 -0
  38. data/lib/generators/pbw/templates/templates/recover_password.jst +17 -0
  39. data/lib/generators/pbw/templates/templates/signup.jst +29 -0
  40. data/lib/generators/pbw/templates/user_recovery.coffee +6 -0
  41. data/lib/generators/pbw/templates/user_registration.coffee +9 -0
  42. data/lib/generators/pbw/templates/user_session.coffee +8 -0
  43. data/lib/generators/pbw/templates/views/edit_view.coffee +15 -8
  44. data/lib/generators/pbw/templates/views/login_view.coffee +39 -0
  45. data/lib/generators/pbw/templates/views/new_view.coffee +5 -9
  46. data/lib/generators/pbw/templates/views/recovery_view.coffee +38 -0
  47. data/lib/generators/pbw/templates/views/signup_view.coffee +39 -0
  48. data/lib/pbw/engine.rb +5 -9
  49. data/lib/pbw/version.rb +1 -1
  50. data/lib/pbw.rb +15 -2
  51. data/vendor/assets/javascripts/backbone_datalink.js +21 -0
  52. metadata +16 -44
  53. data/app/controllers/pbw/capabilities_controller.rb +0 -7
  54. data/app/controllers/pbw/constraints_controller.rb +0 -7
  55. data/app/controllers/pbw/processes_controller.rb +0 -7
  56. data/app/controllers/pbw/triggers_controller.rb +0 -7
  57. data/public/Foundation-MIT-LICENSE.txt +0 -20
  58. data/public/config.rb +0 -26
  59. data/public/javascripts/foundation/foundation.alerts.js +0 -52
  60. data/public/javascripts/foundation/foundation.clearing.js +0 -516
  61. data/public/javascripts/foundation/foundation.cookie.js +0 -74
  62. data/public/javascripts/foundation/foundation.dropdown.js +0 -178
  63. data/public/javascripts/foundation/foundation.forms.js +0 -525
  64. data/public/javascripts/foundation/foundation.interchange.js +0 -271
  65. data/public/javascripts/foundation/foundation.joyride.js +0 -844
  66. data/public/javascripts/foundation/foundation.js +0 -447
  67. data/public/javascripts/foundation/foundation.magellan.js +0 -134
  68. data/public/javascripts/foundation/foundation.orbit.js +0 -390
  69. data/public/javascripts/foundation/foundation.placeholder.js +0 -179
  70. data/public/javascripts/foundation/foundation.reveal.js +0 -330
  71. data/public/javascripts/foundation/foundation.section.js +0 -422
  72. data/public/javascripts/foundation/foundation.tooltips.js +0 -208
  73. data/public/javascripts/foundation/foundation.topbar.js +0 -303
  74. data/public/javascripts/vendor/custom.modernizr.js +0 -4
  75. data/public/javascripts/vendor/jquery.js +0 -9807
  76. data/public/javascripts/vendor/zepto.js +0 -2000
  77. data/public/sass/_normalize.scss +0 -402
  78. data/public/sass/_settings.scss +0 -1271
  79. data/public/sass/app.scss +0 -48
  80. data/public/stylesheets/app.css +0 -6686
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2Y3MjQ0ODBkMzVkZmM3Y2MxYTdlZDhmNDYzY2NjMDY4YjRmOWE0YQ==
4
+ YzAxY2I2YmFlYWQ4Y2FjNWU4ZGRiMGNlOGVmYTQ2Nzk3MDA3OWIxZQ==
5
5
  data.tar.gz: !binary |-
6
- OGNhMWJkMDEzMTEwNzQ5ZmU4YWE4MzcxY2Y4MjgyN2E0YjU1ZjJhMA==
6
+ OWJjODBhYTY5NWJmMGY1Y2FlOThjNjdlZDY3YjE0ZTA4M2MwMWVhMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OWQ0ZDQ2MmJjNGRhYjc3ODIyNWJlNjkxM2U3NTU5OWFlMTQ1OTE1ZjI0ZDMz
10
- MDQ0ZjdiOTA2NDY4OTNhZmEzZTUyMTg3ZTMyM2RhNmI3Y2FhOWFlNTM3OWQz
11
- NjE2ZTQxZjQxYmJkN2YxOTY5MjkxN2FlN2Y2MThjMDRkNDZmMjY=
9
+ YWFkNjg4NjIwMzM2ZTRkMjllYTgyNjBmMThhZDVjNjkyOWEzMWQwMjNmMTc1
10
+ ZTRkMTZiMjc5NzE4NmQ4ZTVlMjQxOTU5ZTliZDY5ZjJkNGQ1Njk1NjMxOGMw
11
+ Mjg2OTc5ODVkZjYwZGI1ZjBlMTA3MThlYzZmOTI1ODAzNjM2ZjM=
12
12
  data.tar.gz: !binary |-
13
- YjFlNmJiNjlkZTM5YjVlYmNjZmFkNDExYTMxZDM1NjY4NTA2ZmVjYmIwYWMy
14
- MTk1MzZkNGJkOTE4MDZhZGVkMDJjOTQwYTE0NDdmZWY2MDViMzMyZWM3Mjll
15
- YmRiYzJjOTI0YjQzYjk2NzgxNmJlM2Y4YzM5NDgxODdkZGY5Yzk=
13
+ M2Y5ZWNhZjZlZDEwODVjZDAxYjc3NTUwYTc4MzJkNTIwNDNiNjM4YTAxYmJm
14
+ MGRiMDRmMTJkMGY2ZGY3ODgxY2U5ZDFiOWUzNmRiZDRjZjk2ZmU5Zjg3YzEz
15
+ NzdhZjIyMDEwYTRiMmE4ODdiOWQzMjBkNDQ0ZTRkMDljZjFhODU=
@@ -1,32 +1,19 @@
1
1
  module Pbw
2
2
  class ApplicationController < ActionController::Base
3
+ respond_to :json
3
4
 
4
5
  rescue_from ::CanCan::AccessDenied do |exception|
5
- respond_to do |format|
6
- format.json {render json: {:error => exception.message}, status: 401}
7
- format.html {redirect_to root_path, :error => exception.message}
8
- end
6
+ render json: {:error => exception.message}, status: 401
9
7
  end
10
8
 
11
9
  rescue_from Mongoid::Errors::DocumentNotFound do |exception|
12
- respond_to do |format|
13
- format.html {redirect_to root_url, :error => exception.message}
14
- format.json {render json: {:error => exception.message}, status: 404}
15
- end
10
+ render json: {:error => exception.message}, status: 404
16
11
  end
17
12
 
18
13
  protected
19
14
 
20
- def self.permission
21
- return name = self.name.gsub('Controller','').singularize.split('::').last.constantize.name rescue nil
22
- end
23
-
24
15
  def current_ability
25
16
  @current_ability ||= Ability.new(current_user)
26
17
  end
27
-
28
- def load_permissions
29
- @current_permissions = current_user.role.permissions.collect{|i| [i.subject_class, i.action]}
30
- end
31
18
  end
32
19
  end
@@ -1,7 +1,5 @@
1
1
  module Pbw
2
2
  class BaseModelsController < ApplicationController
3
- respond_to :json
4
-
5
3
  attr_accessor :model_class
6
4
 
7
5
  before_filter :authenticate_user!
@@ -25,62 +23,42 @@ module Pbw
25
23
 
26
24
  def index
27
25
  session[:referrer] = request.url
28
- respond_with(@models) do |format|
29
- format.json { render json: @models }
30
- end
26
+ render json: @models
31
27
  end
32
28
 
33
29
  def show
34
- respond_with(@model) do |format|
35
- format.json { render json: @model }
36
- end
30
+ render json: @model.to_json
37
31
  end
38
32
 
39
33
  def edit
40
- respond_with(@model) do |format|
41
- format.json { render json: @model }
42
- end
34
+ render json: @model.to_json
43
35
  end
44
36
 
45
37
  def new
46
- respond_with(@model) do |format|
47
- format.json { render json: @model }
48
- end
38
+ render json: @model.to_json
49
39
  end
50
40
 
51
41
  def create
52
42
  if @model.save
53
- respond_with(@model) do |format|
54
- format.json { render json: @model }
55
- end
43
+ render json: @model.to_json
56
44
  else
57
- respond_with(@model) do |format|
58
- format.json { render json: @model.errors.full_messages, status: :unprocessable_entity}
59
- end
45
+ render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
60
46
  end
61
47
  end
62
48
 
63
49
  def update
64
50
  if @model.update_attributes(params[model_param])
65
- respond_with(@model) do |format|
66
- format.json { render json: @model }
67
- end
51
+ render json: @model.to_json
68
52
  else
69
- respond_with(@model) do |format|
70
- format.json { render json: @model.errors.full_messages, status: :unprocessable_entity}
71
- end
53
+ render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
72
54
  end
73
55
  end
74
56
 
75
57
  def destroy
76
58
  if @model.destroy
77
- respond_with(@model) do |format|
78
- format.json { head :no_content }
79
- end
59
+ head :no_content
80
60
  else
81
- respond_with(@model) do |format|
82
- format.json { render json: @model.errors.full_messages, status: :unprocessable_entity}
83
- end
61
+ render json: @model.errors.full_messages.to_json, status: :unprocessable_entity
84
62
  end
85
63
  end
86
64
 
@@ -0,0 +1,14 @@
1
+ module Pbw
2
+ class PasswordsController < Devise::PasswordsController
3
+ respond_to :json
4
+
5
+ def create
6
+ self.resource = resource_class.where(resource_params).first
7
+ if resource && resource.reset_password!
8
+ head :no_content
9
+ else
10
+ render status: :unprocessable_entity
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,12 +1,15 @@
1
1
  module Pbw
2
2
  class RegistrationsController < Devise::RegistrationsController
3
- after_filter :add_user, :only => [:create]
3
+ respond_to :json
4
4
 
5
- protected
6
-
7
- def add_user
8
- if resource.persisted?
9
- Pbw::Engine.user_lifecycle_class.after_signup(resource)
5
+ def create
6
+ self.resource = User.new(params[:user])
7
+ logger.error "Password confirmed? #{params[:user][:password] == params[:user][:password_confirmation]}"
8
+ if resource.save && resource.send_registration_email
9
+ Pbw.user_lifecycle_class.after_signup(resource)
10
+ render json: resource
11
+ else
12
+ render json: resource.errors.full_messages.to_json, status: :unprocessable_entity
10
13
  end
11
14
  end
12
15
  end
@@ -1,11 +1,16 @@
1
1
  module Pbw
2
2
  class SessionsController < Devise::SessionsController
3
- after_filter :login_user, :only => [:create]
3
+ respond_to :json
4
4
 
5
- protected
5
+ def create
6
+ self.resource = warden.authenticate!(auth_options)
7
+ sign_in(resource_name, resource)
8
+ Pbw.user_lifecycle_class.after_login(current_user)
9
+ render json: current_user.to_json, status: :ok
10
+ end
6
11
 
7
- def login_user
8
- Pbw::Engine.user_lifecycle_class.after_signup(current_user)
12
+ def after_sign_out_path_for(resource_name)
13
+ "/"
9
14
  end
10
15
  end
11
16
  end
@@ -0,0 +1,16 @@
1
+ module Pbw
2
+ class UserMailer < ActionMailer::Base
3
+ default :from => Pbw.email_from_address
4
+
5
+ def registration(user_id)
6
+ @user = User.find(user_id)
7
+ mail(:to => @user.email, :subject => I18n.t('pbw.users.registration.subject'))
8
+ end
9
+
10
+ def password_reset(user_id, password)
11
+ @user = User.find(user_id)
12
+ @password = password
13
+ mail(:to => @user.email, :subject => I18n.t('pbw.users.password_reset.subject'))
14
+ end
15
+ end
16
+ end
@@ -6,11 +6,11 @@ module Pbw
6
6
  validates_presence_of :name
7
7
  validates_uniqueness_of :name
8
8
 
9
- has_many :tokens
10
- has_many :item_containers
11
- has_many :attached_processes
12
- has_and_belongs_to_many :constraints
13
- has_and_belongs_to_many :triggers
9
+ has_many :tokens, :class_name => 'Pbw::Token'
10
+ has_many :item_containers, :class_name => 'Pbw::ItemContainer'
11
+ has_many :attached_processes, :class_name => 'Pbw::AttachedProcess'
12
+ has_and_belongs_to_many :constraints, :class_name => 'Pbw::Constraint'
13
+ has_and_belongs_to_many :triggers, :class_name => 'Pbw::Trigger'
14
14
 
15
15
  attr_accessible :name
16
16
 
@@ -1,8 +1,8 @@
1
1
  module Pbw
2
2
  class AttachedProcess
3
- belongs_to :token
4
- belongs_to :area
5
- belongs_to :process
3
+ belongs_to :token, :class_name => 'Pbw::Token'
4
+ belongs_to :area, :class_name => 'Pbw::Area'
5
+ belongs_to :process, :class_name => 'Pbw::Process'
6
6
 
7
7
  field :tickable, :type => Boolean, :default => false
8
8
  field :updatable, :type => Boolean, :default => false
@@ -1,6 +1,6 @@
1
1
  module Pbw
2
2
  class Capability < Rule
3
- has_and_belongs_to_many :tokens
3
+ has_and_belongs_to_many :tokens, :class_name => 'Pbw::Token'
4
4
 
5
5
  def self.viewable_by?(user, subject)
6
6
  return true if user.admin?
@@ -1,7 +1,7 @@
1
1
  module Pbw
2
2
  class Command < Rule
3
- belongs_to :token
4
- belongs_to :user
3
+ belongs_to :token, :class_name => 'Pbw::Token'
4
+ belongs_to :user, :class_name => 'Pbw::User'
5
5
 
6
6
  before_validation :validate_token_and_user
7
7
 
@@ -1,7 +1,7 @@
1
1
  module Pbw
2
2
  class Constraint < Rule
3
- has_and_belongs_to_many :tokens
4
- has_and_belongs_to_many :areas
3
+ has_and_belongs_to_many :tokens, :class_name => 'Pbw::Token'
4
+ has_and_belongs_to_many :areas, :class_name => 'Pbw::Area'
5
5
 
6
6
  def self.viewable_by?(user, subject)
7
7
  return true if user.admin?
@@ -6,8 +6,8 @@ module Pbw
6
6
  validates_presence_of :name
7
7
  validates_uniqueness_of :name
8
8
 
9
- has_many :item_containers
10
- has_many :item_conversions
9
+ has_many :item_containers, :class_name => 'Pbw::ItemContainer'
10
+ has_many :item_conversions, :class_name => 'Pbw::ItemConversion'
11
11
 
12
12
  attr_accessible :name
13
13
 
@@ -2,13 +2,13 @@ module Pbw
2
2
  class ItemContainer
3
3
  include ::Mongoid::Document
4
4
  include ::Mongoid::Timestamps
5
- belongs_to :item
5
+ belongs_to :item, :class_name => 'Pbw::Item'
6
6
  field :quantity, :type => Float, :default => 0
7
7
  validates_numericality_of :quantity, :greater_than_or_equal_to => 0
8
8
 
9
- belongs_to :token
10
- belongs_to :area
11
- belongs_to :user
9
+ belongs_to :token, :class_name => 'Pbw::Token'
10
+ belongs_to :area, :class_name => 'Pbw::Area'
11
+ belongs_to :user, :class_name => 'Pbw::User'
12
12
 
13
13
  attr_accessible :item, :token, :area, :user, :quantity
14
14
 
@@ -2,7 +2,7 @@ module Pbw
2
2
  class ItemConversion
3
3
  include ::Mongoid::Document
4
4
  include ::Mongoid::Timestamps
5
- belongs_to :item
5
+ belongs_to :item, :class_name => 'Pbw::Item'
6
6
  field :from, :type => Hash
7
7
 
8
8
  def self.viewable_by?(user, subject)
@@ -1,7 +1,7 @@
1
1
  module Pbw
2
2
  class Process < Rule
3
- has_many :triggers
4
- has_many :attached_processes
3
+ has_many :triggers, :class_name => 'Pbw::Trigger'
4
+ has_many :attached_processes, :class_name => 'Pbw::AttachedProcess'
5
5
 
6
6
  def self.viewable_by?(user, subject)
7
7
  user.admin?
@@ -5,13 +5,13 @@ module Pbw
5
5
  field :name, type: String
6
6
  validates_presence_of :name
7
7
 
8
- belongs_to :area
9
- belongs_to :user
10
- has_and_belongs_to_many :capabilities
11
- has_and_belongs_to_many :constraints
12
- has_and_belongs_to_many :triggers
13
- has_many :attached_processes
14
- has_many :item_containers
8
+ belongs_to :area, :class_name => 'Pbw::Area'
9
+ belongs_to :user, :class_name => 'Pbw::User'
10
+ has_and_belongs_to_many :capabilities, :class_name => 'Pbw::Capability'
11
+ has_and_belongs_to_many :constraints, :class_name => 'Pbw::Constraint'
12
+ has_and_belongs_to_many :triggers, :class_name => 'Pbw::Trigger'
13
+ has_many :attached_processes, :class_name => 'Pbw::AttachedProcess'
14
+ has_many :item_containers, :class_name => 'Pbw::ItemContainer'
15
15
 
16
16
  attr_accessible :name
17
17
 
@@ -1,8 +1,8 @@
1
1
  module Pbw
2
2
  class Trigger < Rule
3
- has_and_belongs_to_many :tokens
4
- has_and_belongs_to_many :areas
5
- belongs_to :process
3
+ has_and_belongs_to_many :tokens, :class_name => 'Pbw::Token'
4
+ has_and_belongs_to_many :areas, :class_name => 'Pbw::Area'
5
+ belongs_to :process, :class_name => 'Pbw::Process'
6
6
 
7
7
  def self.viewable_by?(user, subject)
8
8
  return true if user.admin?
@@ -6,7 +6,7 @@ module Pbw
6
6
  ROLES = %W{superadmin admin moderator player}
7
7
 
8
8
  devise :database_authenticatable, :registerable, :timeoutable,
9
- :recoverable, :rememberable, :trackable, :validatable, :lockable
9
+ :recoverable, :rememberable, :trackable, :lockable
10
10
 
11
11
  ## Database authenticatable
12
12
  field :email, :type => String, :default => ""
@@ -27,11 +27,7 @@ module Pbw
27
27
  field :last_sign_in_ip, :type => String
28
28
 
29
29
  field :name, :type => String
30
- validates_presence_of :name
31
- validates_uniqueness_of :name, :email, :case_sensitive => false
32
- validates_format_of :email, :with => /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/
33
- validates_confirmation_of :password
34
-
30
+
35
31
  field :role, :type => String, :default => 'player'
36
32
 
37
33
  ## Lockable
@@ -39,8 +35,14 @@ module Pbw
39
35
  field :unlock_token, :type => String # Only if unlock strategy is :email or :both
40
36
  field :locked_at, :type => Time
41
37
 
42
- has_many :resource_containers
43
- has_many :tokens
38
+ has_many :item_containers, :class_name => 'Pbw::ItemContainer'
39
+ has_many :tokens, :class_name => 'Pbw::Token'
40
+
41
+ validates :name, presence: true
42
+ validates :password, confirmation: true, length: {minimum: 8}
43
+ validates :email, uniqueness: {case_sensitive: false}, format: {with: /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/}
44
+
45
+ attr_accessible :email, :name, :password, :password_confirmation
44
46
 
45
47
  def superadmin?
46
48
  self.role == "superadmin"
@@ -73,6 +75,22 @@ module Pbw
73
75
  self.role == "player"
74
76
  end
75
77
 
78
+ def send_registration_email
79
+ UserMailer.registration(self).deliver
80
+ end
81
+
82
+ def reset_password!
83
+ token = User.friendly_token
84
+ self.password = token
85
+ self.password_confirmation = token
86
+ save!
87
+ send_password_email(token)
88
+ end
89
+
90
+ def send_password_email(password)
91
+ UserMailer.password_reset(self,password).deliver
92
+ end
93
+
76
94
  def self.viewable_by?(user, subject)
77
95
  true
78
96
  end
@@ -88,5 +106,9 @@ module Pbw
88
106
  def self.deletable_by?(user, subject)
89
107
  user.admin?
90
108
  end
109
+
110
+ def self.friendly_token
111
+ SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz')
112
+ end
91
113
  end
92
114
  end
@@ -1,71 +1,6 @@
1
1
  Devise.setup do |config|
2
- #config.mailer_sender = Pbw::Engine.config.mail_sender
3
-
4
- config.mailer = "Devise::Mailer"
5
-
6
2
  require 'devise/orm/mongoid'
7
-
8
- config.authentication_keys = [ :email ]
9
-
10
- config.request_keys = []
11
-
12
- config.case_insensitive_keys = [ :email ]
13
-
14
- config.strip_whitespace_keys = [ :email ]
15
-
16
- config.params_authenticatable = true
17
-
18
- config.http_authenticatable = false
19
-
20
- config.http_authenticatable_on_xhr = true
21
-
22
- config.http_authentication_realm = "Application"
23
-
24
- config.paranoid = true
25
-
26
- config.skip_session_storage = [:http_auth]
27
-
28
- config.stretches = Rails.env.test? ? 1 : 10
29
-
30
- config.pepper = "63818839cfabfff3dcf5983671b4d2f01708727af5d512fd79a8afe7e744187a8976280cd31e8d1b023c2c29f4f396810c90ef15de5faaa20595e84bee4c9545"
31
-
32
- config.remember_for = 2.weeks
33
-
34
- config.extend_remember_period = false
35
-
36
- config.rememberable_options = {}
37
-
38
- config.password_length = 8..128
39
-
40
- config.email_regexp = /\A[^@]+@[^@]+\z/
41
-
42
- config.timeout_in = 30.minutes
43
-
44
- config.expire_auth_token_on_timeout = false
45
-
46
- config.lock_strategy = :failed_attempts
47
-
48
- config.unlock_keys = [ :email ]
49
-
50
- config.unlock_strategy = :email
51
-
52
- config.maximum_attempts = 5
53
-
54
- config.reset_password_keys = [ :email ]
55
-
56
- config.reset_password_within = 6.hours
57
-
58
- config.token_authentication_key = :auth_token
59
-
60
- config.scoped_views = false
61
-
62
- config.default_scope = :user
63
-
64
- config.sign_out_all_scopes = true
65
-
66
- config.navigational_formats = ["*/*", :html]
67
-
68
3
  config.sign_out_via = :delete
69
-
70
4
  config.router_name = :pbw
5
+ DeviseController.respond_to :json
71
6
  end
@@ -0,0 +1,7 @@
1
+ en:
2
+ pbw:
3
+ users:
4
+ registration:
5
+ subject: "Account registered"
6
+ password_reset:
7
+ subject: "Password reset"
data/config/routes.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  Pbw::Engine.routes.draw do
2
2
  devise_for :users, {
3
3
  class_name: 'Pbw::User',
4
- controllers: { registrations: 'pbw/registrations', :sessions => 'pbw/sessions'},
4
+ controllers: { registrations: 'pbw/registrations', :sessions => 'pbw/sessions', :passwords => 'pbw/passwords'},
5
5
  module: :devise
6
6
  }
7
- %W{areas capabilities constraints processes items tokens triggers commands}.each do |controller|
7
+ %W{areas commands items tokens}.each do |controller|
8
8
  get "#{controller}/:_type" => "#{controller}\#index"
9
9
  get "#{controller}/:_type/:id" => "#{controller}\#show"
10
10
  post "#{controller}/:_type" => "#{controller}\#create"
@@ -16,6 +16,4 @@ Pbw::Engine.routes.draw do
16
16
 
17
17
  resources :item_containers
18
18
  resources :item_conversions
19
- resources :item_transfers
20
- resources :user_tokens
21
19
  end
@@ -28,11 +28,14 @@ module Pbw
28
28
  def create_home_controller
29
29
  template "index.erb", "app/views/home/index.html.erb"
30
30
  generate "controller", "home index --skip"
31
+ inject_into_file "app/controllers/home_controller.rb", :before => "def index" do
32
+ "layout '#{application_name.underscore}'\n "
33
+ end
31
34
  gsub_file "config/routes.rb", "get \"home/index\"", "root :to => \"home#index\""
32
35
  end
33
36
 
34
37
  def create_dir_layout
35
- %W{routers models views templates}.each do |dir|
38
+ %W{helpers routers models views templates}.each do |dir|
36
39
  empty_directory "app/assets/javascripts/#{dir}"
37
40
  create_file "app/assets/javascripts/#{dir}/.gitkeep" unless options[:skip_git]
38
41
  end
@@ -50,13 +53,29 @@ module Pbw
50
53
  route "mount Pbw::Engine, :at => '/pbw'"
51
54
  end
52
55
 
53
- def devise_views
54
- generate "devise:views"
56
+ def create_user_backbone
57
+ template "user_registration.coffee", "app/assets/javascripts/models/user_registration.js.coffee"
58
+ template "user_recovery.coffee", "app/assets/javascripts/models/user_recovery.js.coffee"
59
+ template "user_session.coffee", "app/assets/javascripts/models/user_session.js.coffee"
60
+ template "views/login_view.coffee", "app/assets/javascripts/views/users/login_view.js.coffee"
61
+ template "views/recovery_view.coffee", "app/assets/javascripts/views/users/recovery_view.js.coffee"
62
+ template "views/signup_view.coffee", "app/assets/javascripts/views/users/signup_view.js.coffee"
63
+ template "templates/login.jst", "app/assets/javascripts/templates/users/login.jst.ejs"
64
+ template "templates/recover_password.jst", "app/assets/javascripts/templates/users/recover_password.jst.ejs"
65
+ template "templates/signup.jst", "app/assets/javascripts/templates/users/signup.jst.ejs"
55
66
  end
56
67
 
57
68
  def user_lifecycle
58
69
  template "lifecycle.rb", "app/models/user/lifecycle.rb"
59
70
  end
71
+
72
+ def create_helper_javascript
73
+ template "pbw.coffee", "app/assets/javascripts/helpers/pbw.js.coffee"
74
+ end
75
+
76
+ def create_application_layout
77
+ template "application.erb", "app/views/layouts/#{application_name.underscore}.html.erb"
78
+ end
60
79
  end
61
80
  end
62
81
  end
@@ -10,6 +10,12 @@ module Pbw
10
10
  def create_backbone_model
11
11
  template "model.coffee", "#{backbone_path}/models/#{model_namespace.downcase}/#{file_name}.js.coffee"
12
12
  end
13
+
14
+ def create_model
15
+ generate "model", "#{model_namespace}::#{class_name} #{attributes.map{|attr| "#{attr.name}:#{attr.type}"}.join(' ')}"
16
+ gsub_file "app/models/#{model_namespace.downcase}/#{file_name}.rb", "class #{model_namespace}::#{class_name}", "class #{model_namespace}::#{class_name} < #{base_model_class}"
17
+ gsub_file "app/models/#{model_namespace.downcase}/#{file_name}.rb", "include Mongoid::Document", ""
18
+ end
13
19
  end
14
20
  end
15
21
  end
@@ -9,6 +9,10 @@ module Pbw
9
9
  def js_model_namespace
10
10
  [js_app_name, "Models", model_namespace, class_name].join(".")
11
11
  end
12
+
13
+ def js_user_model_namespace
14
+ [js_app_name, "Models", 'User'].join(".")
15
+ end
12
16
 
13
17
  def singular_model_name
14
18
  uncapitalize singular_name.camelize
@@ -22,6 +26,10 @@ module Pbw
22
26
  [js_app_name, "Collections", model_namespace, plural_name.camelize].join(".")
23
27
  end
24
28
 
29
+ def user_collection_namespace
30
+ [js_app_name, "Collections", 'Users'].join(".")
31
+ end
32
+
25
33
  def home_view_namespace
26
34
  [js_app_name, "Views", 'Home'].join(".")
27
35
  end
@@ -29,11 +37,19 @@ module Pbw
29
37
  def view_namespace
30
38
  [js_app_name, "Views", model_namespace, plural_name.camelize].join(".")
31
39
  end
40
+
41
+ def user_view_namespace
42
+ [js_app_name, "Views", 'Users'].join(".")
43
+ end
32
44
 
33
45
  def jst(action)
34
46
  "templates/#{model_namespace.downcase}/#{plural_name}/#{action}"
35
47
  end
36
48
 
49
+ def user_jst(action)
50
+ "templates/users/#{action}"
51
+ end
52
+
37
53
  def router_name
38
54
  [js_app_name, "Routers", 'AppRouter'].join(".")
39
55
  end
@@ -1,8 +1,10 @@
1
- require 'generators/pbw/scaffold_generator'
1
+ require 'generators/pbw/model_generator'
2
2
  require 'generators/pbw/rules/rules'
3
3
 
4
- class Pbw::Rules::CapabilityGenerator < Pbw::Generators::ScaffoldGenerator
4
+ class Pbw::Rules::CapabilityGenerator < Pbw::Generators::ModelGenerator
5
5
  source_root File.expand_path("../../../templates", __FILE__)
6
+ def create_backbone_model
7
+ end
6
8
  protected
7
9
  def base_model_class
8
10
  "Pbw::Capability"