mtwarden 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +9 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/mtwarden/account/accounts.js +2 -0
- data/app/assets/javascripts/mtwarden/account/dashboard.js +2 -0
- data/app/assets/javascripts/mtwarden/account/sessions.js +2 -0
- data/app/assets/javascripts/mtwarden/account/users.js +2 -0
- data/app/assets/javascripts/mtwarden/accounts.js +2 -0
- data/app/assets/javascripts/mtwarden/application.js +13 -0
- data/app/assets/javascripts/mtwarden/dashboard.js +2 -0
- data/app/assets/stylesheets/mtwarden/account/accounts.css +4 -0
- data/app/assets/stylesheets/mtwarden/account/dashboard.css +4 -0
- data/app/assets/stylesheets/mtwarden/account/sessions.css +4 -0
- data/app/assets/stylesheets/mtwarden/account/users.css +4 -0
- data/app/assets/stylesheets/mtwarden/accounts.css +4 -0
- data/app/assets/stylesheets/mtwarden/application.css +15 -0
- data/app/assets/stylesheets/mtwarden/dashboard.css +4 -0
- data/app/controllers/mtwarden/account/accounts_controller.rb +67 -0
- data/app/controllers/mtwarden/account/dashboard_controller.rb +7 -0
- data/app/controllers/mtwarden/account/sessions_controller.rb +20 -0
- data/app/controllers/mtwarden/account/users_controller.rb +23 -0
- data/app/controllers/mtwarden/accounts_controller.rb +32 -0
- data/app/controllers/mtwarden/application_controller.rb +12 -0
- data/app/controllers/mtwarden/dashboard_controller.rb +6 -0
- data/app/extenders/controllers/application_controller_extender.rb +38 -0
- data/app/helpers/mtwarden/account/accounts_helper.rb +4 -0
- data/app/helpers/mtwarden/account/dashboard_helper.rb +4 -0
- data/app/helpers/mtwarden/account/sessions_helper.rb +4 -0
- data/app/helpers/mtwarden/account/users_helper.rb +4 -0
- data/app/helpers/mtwarden/accounts_helper.rb +4 -0
- data/app/helpers/mtwarden/application_helper.rb +4 -0
- data/app/helpers/mtwarden/dashboard_helper.rb +4 -0
- data/app/models/mtwarden/account.rb +39 -0
- data/app/models/mtwarden/member.rb +8 -0
- data/app/models/mtwarden/plan.rb +6 -0
- data/app/models/mtwarden/user.rb +7 -0
- data/app/views/layouts/mtwarden/application.html.erb +16 -0
- data/app/views/mtwarden/account/accounts/_existing_subscription.html.erb +3 -0
- data/app/views/mtwarden/account/accounts/_new_subscription.html.erb +38 -0
- data/app/views/mtwarden/account/accounts/edit.html.erb +17 -0
- data/app/views/mtwarden/account/accounts/plan.html.erb +15 -0
- data/app/views/mtwarden/account/dashboard/index.html.erb +1 -0
- data/app/views/mtwarden/account/sessions/new.html.erb +19 -0
- data/app/views/mtwarden/account/users/_form.html.erb +14 -0
- data/app/views/mtwarden/account/users/new.html.erb +6 -0
- data/app/views/mtwarden/accounts/new.html.erb +20 -0
- data/app/views/mtwarden/dashboard/index.html.erb +1 -0
- data/app/views/mtwarden/shared/_login.html.erb +7 -0
- data/config/initializers/braintree.rb +4 -0
- data/config/initializers/warden/strategies/password.rb +16 -0
- data/config/routes.rb +29 -0
- data/db/migrate/20140621030847_create_mtwarden_accounts.rb +9 -0
- data/db/migrate/20140621114149_add_owner_id_to_mtwarden_accounts.rb +5 -0
- data/db/migrate/20140621114231_create_mtwarden_users.rb +10 -0
- data/db/migrate/20140621114308_create_mtwarden_members.rb +10 -0
- data/db/migrate/20140621114417_add_subdomain_to_mtwarden_accounts.rb +6 -0
- data/db/migrate/20140829231923_create_mtwarden_plans.rb +11 -0
- data/db/migrate/20140830011033_add_plan_id_to_mtwarden_accounts.rb +5 -0
- data/db/migrate/20140830020346_add_braintree_subscription_id_to_mtwarden_accounts.rb +5 -0
- data/lib/mtwarden.rb +5 -0
- data/lib/mtwarden/braintree_plan_fetcher.rb +20 -0
- data/lib/mtwarden/constraints/subdomain_required.rb +9 -0
- data/lib/mtwarden/engine.rb +51 -0
- data/lib/mtwarden/scoped_to.rb +7 -0
- data/lib/mtwarden/testing_support/authentication_helpers.rb +17 -0
- data/lib/mtwarden/testing_support/factories/account_factory.rb +13 -0
- data/lib/mtwarden/testing_support/factories/user_factory.rb +7 -0
- data/lib/mtwarden/testing_support/subdomain_helpers.rb +14 -0
- data/lib/mtwarden/version.rb +3 -0
- data/lib/tasks/mtwarden_tasks.rake +7 -0
- metadata +297 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b153390fcb074e88e44ab311db4faa6875f5df9
|
4
|
+
data.tar.gz: 5a4db2f7c423105962bfb06049b89dcb12d1ba79
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 13aec2ed56d94f40946c3de0f9f3496d6e7659abaf417ebb15aa3f16e00d99e2cdfba0cc039088df5e25825d94ce5eb86e2e4a2356b567e2ea60b0997afa5084
|
7
|
+
data.tar.gz: eefea1fe2937dc8c6d624246dd944b675d0c50e7c3fdef36f5f02d97fcad5bd3c8b8606bbb702fc7c29a8fdf164b7f4068101274546b87baba9a9c8a0f56e4e4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-2016 PHCNetworks
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'Mtwarden'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.rdoc')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
20
|
+
load 'rails/tasks/engine.rake'
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
task :default => :spec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_dependency "mtwarden/application_controller"
|
2
|
+
|
3
|
+
module Mtwarden
|
4
|
+
class Account::AccountsController < ApplicationController
|
5
|
+
before_filter :authenticate_user!
|
6
|
+
before_filter :authorize_owner, only: [:edit, :update, :plan]
|
7
|
+
|
8
|
+
def update
|
9
|
+
plan_id = account_params.delete(:plan_id)
|
10
|
+
if current_account.update_attributes(account_params)
|
11
|
+
flash[:success] = "Account updated successfully."
|
12
|
+
if plan_id != current_account.plan_id
|
13
|
+
redirect_to plan_account_url(:plan_id => plan_id)
|
14
|
+
else
|
15
|
+
redirect_to root_path
|
16
|
+
end
|
17
|
+
else
|
18
|
+
flash[:error] = "Account could not be updated."
|
19
|
+
render :edit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def plan
|
24
|
+
@plan = Mtwarden::Plan.find(params[:plan_id])
|
25
|
+
end
|
26
|
+
|
27
|
+
def subscribe
|
28
|
+
@plan = Mtwarden::Plan.find(params[:plan_id])
|
29
|
+
@result = Braintree::TransparentRedirect.confirm(request.query_string)
|
30
|
+
if @result.success?
|
31
|
+
subscription_result = Braintree::Subscription.create(
|
32
|
+
:payment_method_token => @result.customer.credit_cards[0].token,
|
33
|
+
:plan_id => @plan.braintree_id
|
34
|
+
)
|
35
|
+
current_account.update_column(:plan_id, params[:plan_id])
|
36
|
+
subscription_id = subscription_result.subscription.id
|
37
|
+
current_account.update_column(:braintree_subscription_id, subscription_id)
|
38
|
+
flash[:success] = "You have switched to the '#{plan.name}' plan."
|
39
|
+
redirect_to root_path
|
40
|
+
else
|
41
|
+
flash[:error] = "Invalid credit card details. Please try again."
|
42
|
+
render "plan"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def confirm_plan
|
47
|
+
@plan = Mtwarden::Plan.find(params[:plan_id])
|
48
|
+
subscription_id = current_account.braintree_subscription_id
|
49
|
+
subscription_result = Braintree::Subscription.update(subscription_id,
|
50
|
+
:plan_id => plan.braintree_id)
|
51
|
+
if subscription_result.success?
|
52
|
+
current_account.update_column(:plan_id, plan.id)
|
53
|
+
flash[:success] = "You have switched to the '#{plan.name}' plan."
|
54
|
+
redirect_to root_path
|
55
|
+
else
|
56
|
+
flash[:error] = "Something went wrong. Please try again."
|
57
|
+
render "plan"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def account_params
|
64
|
+
params.require(:account).permit(:name, :plan_id)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_dependency "mtwarden/application_controller"
|
2
|
+
|
3
|
+
module Mtwarden
|
4
|
+
class Account::SessionsController < Mtwarden::ApplicationController
|
5
|
+
def new
|
6
|
+
@user = User.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
if env["warden"].authenticate(:scope => :user)
|
11
|
+
flash[:success] = "You are now signed in."
|
12
|
+
redirect_to root_path
|
13
|
+
else
|
14
|
+
@user = User.new
|
15
|
+
flash[:error] = "Invalid email or password."
|
16
|
+
render :action => "new"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_dependency "mtwarden/application_controller"
|
2
|
+
|
3
|
+
module Mtwarden
|
4
|
+
class Account::UsersController < ApplicationController
|
5
|
+
def new
|
6
|
+
@user = Mtwarden::User.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
account = Mtwarden::Account.find_by(:subdomain => request.subdomain)
|
11
|
+
user = account.users.create(user_params)
|
12
|
+
force_authentication!(user)
|
13
|
+
flash[:success] = "You have signed up successfully."
|
14
|
+
redirect_to root_path
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def user_params
|
20
|
+
params.require(:user).permit(:email, :password, :password_confirmation)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +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
|
@@ -0,0 +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
|
@@ -0,0 +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
|