mtwarden 6.0.1 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -20
  3. data/README.md +35 -35
  4. data/Rakefile +33 -33
  5. data/app/assets/config/mtwarden_manifest.js +2 -2
  6. data/app/assets/javascripts/mtwarden/application.js +2 -2
  7. data/app/assets/stylesheets/mtwarden/application.scss +2 -2
  8. data/app/controllers/mtwarden/account/accounts_controller.rb +67 -67
  9. data/app/controllers/mtwarden/account/dashboard_controller.rb +7 -7
  10. data/app/controllers/mtwarden/account/sessions_controller.rb +20 -20
  11. data/app/controllers/mtwarden/account/users_controller.rb +23 -23
  12. data/app/controllers/mtwarden/accounts_controller.rb +32 -32
  13. data/app/controllers/mtwarden/application_controller.rb +12 -12
  14. data/app/controllers/mtwarden/dashboard_controller.rb +6 -6
  15. data/app/extenders/controllers/application_controller_extender.rb +38 -38
  16. data/app/helpers/mtwarden/application_helper.rb +4 -4
  17. data/app/jobs/mtwarden/application_job.rb +4 -4
  18. data/app/mailers/mtwarden/application_mailer.rb +8 -8
  19. data/app/models/mtwarden/account.rb +39 -39
  20. data/app/models/mtwarden/application_record.rb +5 -5
  21. data/app/models/mtwarden/member.rb +6 -6
  22. data/app/models/mtwarden/plan.rb +4 -4
  23. data/app/models/mtwarden/user.rb +7 -7
  24. data/app/views/layouts/mtwarden/application.html.erb +16 -16
  25. data/app/views/mtwarden/account/accounts/_existing_subscription.html.erb +3 -3
  26. data/app/views/mtwarden/account/accounts/_new_subscription.html.erb +38 -38
  27. data/app/views/mtwarden/account/accounts/edit.html.erb +17 -17
  28. data/app/views/mtwarden/account/accounts/plan.html.erb +14 -14
  29. data/app/views/mtwarden/account/dashboard/index.html.erb +1 -1
  30. data/app/views/mtwarden/account/sessions/new.html.erb +19 -19
  31. data/app/views/mtwarden/account/users/_form.html.erb +14 -14
  32. data/app/views/mtwarden/account/users/new.html.erb +6 -6
  33. data/app/views/mtwarden/accounts/new.html.erb +20 -20
  34. data/app/views/mtwarden/dashboard/index.html.erb +1 -1
  35. data/app/views/mtwarden/shared/_login.html.erb +7 -7
  36. data/config/initializers/warden/strategies/password.rb +18 -18
  37. data/config/routes.rb +30 -30
  38. data/db/migrate/20140621030847_create_mtwarden_accounts.rb +11 -11
  39. data/db/migrate/20140621114149_add_owner_id_to_mtwarden_accounts.rb +7 -7
  40. data/db/migrate/20140621114231_create_mtwarden_users.rb +12 -12
  41. data/db/migrate/20140621114308_create_mtwarden_members.rb +12 -12
  42. data/db/migrate/20140621114417_add_subdomain_to_mtwarden_accounts.rb +8 -8
  43. data/db/migrate/20140829231923_create_mtwarden_plans.rb +13 -13
  44. data/db/migrate/20140830011033_add_plan_id_to_mtwarden_accounts.rb +7 -7
  45. data/db/migrate/20140830020346_add_braintree_subscription_id_to_mtwarden_accounts.rb +7 -7
  46. data/lib/mtwarden.rb +4 -4
  47. data/lib/mtwarden/braintree_plan_fetcher.rb +22 -22
  48. data/lib/mtwarden/constraints/subdomain_required.rb +11 -11
  49. data/lib/mtwarden/engine.rb +52 -52
  50. data/lib/mtwarden/scoped_to.rb +9 -9
  51. data/lib/mtwarden/testing_support/authentication_helpers.rb +21 -21
  52. data/lib/mtwarden/testing_support/factories/account_factory.rb +14 -14
  53. data/lib/mtwarden/testing_support/factories/user_factory.rb +7 -7
  54. data/lib/mtwarden/testing_support/subdomain_helpers.rb +16 -16
  55. data/lib/mtwarden/version.rb +3 -3
  56. data/lib/tasks/mtwarden_tasks.rake +6 -6
  57. metadata +23 -53
@@ -1,32 +1,32 @@
1
- require_dependency "mtwarden/application_controller"
2
-
3
- module Mtwarden
4
- class AccountsController < ApplicationController
5
- def new
6
- @account = Mtwarden::Account.new
7
- @account.build_owner
8
- end
9
-
10
- def create
11
- @account = Mtwarden::Account.create_with_owner(account_params)
12
- if @account.valid?
13
- force_authentication!(@account.owner)
14
- flash[:success] = "Your account has been successfully created."
15
- redirect_to mtwarden.root_url(:subdomain => @account.subdomain)
16
- else
17
- flash[:error] = "Sorry, your account could not be created."
18
- render :new
19
- end
20
- end
21
-
22
- private
23
-
24
- def account_params
25
- params.require(:account).permit(:name, :subdomain,
26
- { :owner_attributes => [
27
- [:email, :password, :password_confirmation]
28
- ]}
29
- )
30
- end
31
- end
32
- end
1
+ require_dependency "mtwarden/application_controller"
2
+
3
+ module Mtwarden
4
+ class AccountsController < ApplicationController
5
+ def new
6
+ @account = Mtwarden::Account.new
7
+ @account.build_owner
8
+ end
9
+
10
+ def create
11
+ @account = Mtwarden::Account.create_with_owner(account_params)
12
+ if @account.valid?
13
+ force_authentication!(@account.owner)
14
+ flash[:success] = "Your account has been successfully created."
15
+ redirect_to mtwarden.root_url(:subdomain => @account.subdomain)
16
+ else
17
+ flash[:error] = "Sorry, your account could not be created."
18
+ render :new
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def account_params
25
+ params.require(:account).permit(:name, :subdomain,
26
+ { :owner_attributes => [
27
+ [:email, :password, :password_confirmation]
28
+ ]}
29
+ )
30
+ end
31
+ end
32
+ end
@@ -1,12 +1,12 @@
1
- module Mtwarden
2
- class ApplicationController < ::ApplicationController
3
-
4
- def authorize_owner
5
- unless owner?
6
- flash[:error] = "You are not allowed to do that."
7
- redirect_to root_path
8
- end
9
- end
10
- end
11
-
12
- end
1
+ module Mtwarden
2
+ class ApplicationController < ::ApplicationController
3
+
4
+ def authorize_owner
5
+ unless owner?
6
+ flash[:error] = "You are not allowed to do that."
7
+ redirect_to root_path
8
+ end
9
+ end
10
+ end
11
+
12
+ end
@@ -1,6 +1,6 @@
1
- require_dependency "mtwarden/application_controller"
2
-
3
- module Mtwarden
4
- class DashboardController < ApplicationController
5
- end
6
- end
1
+ require_dependency "mtwarden/application_controller"
2
+
3
+ module Mtwarden
4
+ class DashboardController < ApplicationController
5
+ end
6
+ end
@@ -1,38 +1,38 @@
1
- ::ApplicationController.class_eval do
2
- def current_account
3
- @current_account ||= env['X-Houser-Object']
4
- end
5
- helper_method :current_account
6
-
7
- def current_user
8
- if user_signed_in?
9
- @current_user ||= begin
10
- user_id = env["warden"].user(:scope => :user)
11
- Mtwarden::User.find_by_id(user_id)
12
- end
13
- end
14
- end
15
- helper_method :current_user
16
-
17
- def user_signed_in?
18
- env["warden"].authenticated?(:user)
19
- end
20
- helper_method :user_signed_in?
21
-
22
- def authenticate_user!
23
- unless user_signed_in?
24
- flash[:info] = "Please sign in."
25
- redirect_to '/sign_in'
26
- end
27
- end
28
-
29
- def force_authentication!(user)
30
- env["warden"].set_user(user, :scope => :user)
31
- end
32
-
33
- def owner?
34
- current_account.owner?(current_user)
35
- end
36
- helper_method :owner?
37
-
38
- end
1
+ ::ApplicationController.class_eval do
2
+ def current_account
3
+ @current_account ||= env['X-Houser-Object']
4
+ end
5
+ helper_method :current_account
6
+
7
+ def current_user
8
+ if user_signed_in?
9
+ @current_user ||= begin
10
+ user_id = env["warden"].user(:scope => :user)
11
+ Mtwarden::User.find_by_id(user_id)
12
+ end
13
+ end
14
+ end
15
+ helper_method :current_user
16
+
17
+ def user_signed_in?
18
+ env["warden"].authenticated?(:user)
19
+ end
20
+ helper_method :user_signed_in?
21
+
22
+ def authenticate_user!
23
+ unless user_signed_in?
24
+ flash[:info] = "Please sign in."
25
+ redirect_to '/sign_in'
26
+ end
27
+ end
28
+
29
+ def force_authentication!(user)
30
+ env["warden"].set_user(user, :scope => :user)
31
+ end
32
+
33
+ def owner?
34
+ current_account.owner?(current_user)
35
+ end
36
+ helper_method :owner?
37
+
38
+ end
@@ -1,4 +1,4 @@
1
- module Mtwarden
2
- module ApplicationHelper
3
- end
4
- end
1
+ module Mtwarden
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Mtwarden
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
1
+ module Mtwarden
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -1,8 +1,8 @@
1
- module Mtwarden
2
- class ApplicationMailer < ActionMailer::Base
3
-
4
- default from: 'from@example.com'
5
- layout 'mailer'
6
-
7
- end
8
- end
1
+ module Mtwarden
2
+ class ApplicationMailer < ActionMailer::Base
3
+
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+
7
+ end
8
+ end
@@ -1,39 +1,39 @@
1
- module Mtwarden
2
- class Account < ActiveRecord::Base
3
-
4
- belongs_to :owner, :class_name => "Mtwarden::User"
5
- accepts_nested_attributes_for :owner
6
-
7
- belongs_to :plan, :class_name => "Mtwarden::Plan"
8
-
9
- validates :subdomain, :presence => true, :uniqueness => true
10
- validates :name, presence: true
11
-
12
- has_many :members, :class_name => "Mtwarden::Member"
13
- has_many :users, :through => :members
14
-
15
- EXCLUDED_SUBDOMAINS = %w(admin)
16
- validates_exclusion_of :subdomain, :in => EXCLUDED_SUBDOMAINS,
17
- :message => "is not allowed. Please choose another subdomain."
18
-
19
- validates_format_of :subdomain, :with => /\A[\w\-]+\Z/i,
20
- :message => "is not allowed. Please choose another subdomain."
21
-
22
- before_validation do
23
- self.subdomain = subdomain.to_s.downcase
24
- end
25
-
26
- def self.create_with_owner(params={})
27
- account = new(params)
28
- if account.save
29
- account.users << account.owner
30
- end
31
- account
32
- end
33
-
34
- def owner?(user)
35
- owner == user
36
- end
37
- end
38
-
39
- end
1
+ module Mtwarden
2
+ class Account < ActiveRecord::Base
3
+
4
+ belongs_to :owner, :class_name => "Mtwarden::User"
5
+ accepts_nested_attributes_for :owner
6
+
7
+ belongs_to :plan, :class_name => "Mtwarden::Plan"
8
+
9
+ validates :subdomain, :presence => true, :uniqueness => true
10
+ validates :name, presence: true
11
+
12
+ has_many :members, :class_name => "Mtwarden::Member"
13
+ has_many :users, :through => :members
14
+
15
+ EXCLUDED_SUBDOMAINS = %w(admin)
16
+ validates_exclusion_of :subdomain, :in => EXCLUDED_SUBDOMAINS,
17
+ :message => "is not allowed. Please choose another subdomain."
18
+
19
+ validates_format_of :subdomain, :with => /\A[\w\-]+\Z/i,
20
+ :message => "is not allowed. Please choose another subdomain."
21
+
22
+ before_validation do
23
+ self.subdomain = subdomain.to_s.downcase
24
+ end
25
+
26
+ def self.create_with_owner(params={})
27
+ account = new(params)
28
+ if account.save
29
+ account.users << account.owner
30
+ end
31
+ account
32
+ end
33
+
34
+ def owner?(user)
35
+ owner == user
36
+ end
37
+ end
38
+
39
+ end
@@ -1,5 +1,5 @@
1
- module Mtwarden
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
1
+ module Mtwarden
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
- module Mtwarden
2
- class Member < ActiveRecord::Base
3
- belongs_to :account, :class_name => "Mtwarden::Account"
4
- belongs_to :user, :class_name => "Mtwarden::User"
5
- end
6
- end
1
+ module Mtwarden
2
+ class Member < ActiveRecord::Base
3
+ belongs_to :account, :class_name => "Mtwarden::Account"
4
+ belongs_to :user, :class_name => "Mtwarden::User"
5
+ end
6
+ end
@@ -1,4 +1,4 @@
1
- module Mtwarden
2
- class Plan < ActiveRecord::Base
3
- end
4
- end
1
+ module Mtwarden
2
+ class Plan < ActiveRecord::Base
3
+ end
4
+ end
@@ -1,7 +1,7 @@
1
- module Mtwarden
2
- class User < ActiveRecord::Base
3
- include Gravtastic
4
- gravtastic
5
- has_secure_password
6
- end
7
- end
1
+ module Mtwarden
2
+ class User < ActiveRecord::Base
3
+ include Gravtastic
4
+ gravtastic
5
+ has_secure_password
6
+ end
7
+ end
@@ -1,16 +1,16 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>CoastDigitalGroup Mtwarden Warden Edition</title>
5
- <%= stylesheet_link_tag "mtwarden/application", media: "all" %>
6
- <%= javascript_include_tag "mtwarden/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
- <% flash.each do |k,v| %>
11
- <div class='flash <%= k %>'><%= v %></div>
12
- <% end %>
13
- <%= render "mtwarden/shared/login" %>
14
- <%= yield %>
15
- </body>
16
- </html>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>CoastDigitalGroup Mtwarden Warden Edition</title>
5
+ <%= stylesheet_link_tag "mtwarden/application", media: "all" %>
6
+ <%= javascript_include_tag "mtwarden/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <% flash.each do |k,v| %>
11
+ <div class='flash <%= k %>'><%= v %></div>
12
+ <% end %>
13
+ <%= render "mtwarden/shared/login" %>
14
+ <%= yield %>
15
+ </body>
16
+ </html>
@@ -1,3 +1,3 @@
1
- <%= form_tag confirm_plan_account_path(:plan_id => params[:plan_id]) do %>
2
- <%= submit_tag "Change plan" %>
3
- <% end %>
1
+ <%= form_tag confirm_plan_account_path(:plan_id => params[:plan_id]) do %>
2
+ <%= submit_tag "Change plan" %>
3
+ <% end %>
@@ -1,38 +1,38 @@
1
- <% if @result && @result.message %>
2
- <ul class="gateway_messages">
3
- <% @result.message.split("\n").each do |message| %>
4
- <li><%= message %></li>
5
- <% end %>
6
- </ul>
7
- <% end %>
8
-
9
- <%= form_for :customer,
10
- :url => Braintree::TransparentRedirect.url,
11
- :html => {:autocomplete => "off"} do |customer| -%>
12
- <% tr_data = Braintree::TransparentRedirect.create_customer_data(
13
- :redirect_url => mtwarden.subscribe_account_url(:plan_id => params[:plan_id]),
14
- ) %>
15
- <%= hidden_field_tag "tr_data", tr_data %>
16
- <%= customer.fields_for :credit_card do |cc| -%>
17
- <p>
18
- <%= cc.label :number, "Credit card number" %><br>
19
- <%= cc.text_field :number %>
20
- </p>
21
-
22
- <p>
23
- <%= cc.label :cardholder_name, "Name on card" %><br>
24
- <%= cc.text_field :cardholder_name %>
25
- </p>
26
-
27
- <p>
28
- <%= cc.label :expiration_date, "Expiration date" %><br>
29
- <%= cc.text_field :expiration_date %>
30
- </p>
31
-
32
- <p>
33
- <%= cc.label :cvv, "CVV" %><br>
34
- <%= cc.text_field :cvv %>
35
- </p>
36
- <%= customer.submit "Change plan" %>
37
- <% end %>
38
- <% end %>
1
+ <% if @result && @result.message %>
2
+ <ul class="gateway_messages">
3
+ <% @result.message.split("\n").each do |message| %>
4
+ <li><%= message %></li>
5
+ <% end %>
6
+ </ul>
7
+ <% end %>
8
+
9
+ <%= form_for :customer,
10
+ :url => Braintree::TransparentRedirect.url,
11
+ :html => {:autocomplete => "off"} do |customer| -%>
12
+ <% tr_data = Braintree::TransparentRedirect.create_customer_data(
13
+ :redirect_url => mtwarden.subscribe_account_url(:plan_id => params[:plan_id]),
14
+ ) %>
15
+ <%= hidden_field_tag "tr_data", tr_data %>
16
+ <%= customer.fields_for :credit_card do |cc| -%>
17
+ <p>
18
+ <%= cc.label :number, "Credit card number" %><br>
19
+ <%= cc.text_field :number %>
20
+ </p>
21
+
22
+ <p>
23
+ <%= cc.label :cardholder_name, "Name on card" %><br>
24
+ <%= cc.text_field :cardholder_name %>
25
+ </p>
26
+
27
+ <p>
28
+ <%= cc.label :expiration_date, "Expiration date" %><br>
29
+ <%= cc.text_field :expiration_date %>
30
+ </p>
31
+
32
+ <p>
33
+ <%= cc.label :cvv, "CVV" %><br>
34
+ <%= cc.text_field :cvv %>
35
+ </p>
36
+ <%= customer.submit "Change plan" %>
37
+ <% end %>
38
+ <% end %>