wbase 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +219 -2
- data/app/assets/javascripts/wbase/auth/bootstrap.min.js +7 -0
- data/app/assets/javascripts/wbase/auth/detect.js +7 -0
- data/app/assets/javascripts/wbase/auth/fastclick.js +841 -0
- data/app/assets/javascripts/wbase/auth/jquery.app.js +318 -0
- data/app/assets/javascripts/wbase/auth/jquery.blockUI.js +620 -0
- data/app/assets/javascripts/wbase/auth/jquery.core.js +323 -0
- data/app/assets/javascripts/wbase/auth/jquery.min.js +5 -0
- data/app/assets/javascripts/wbase/auth/jquery.nicescroll.js +113 -0
- data/app/assets/javascripts/wbase/auth/jquery.scrollTo.min.js +7 -0
- data/app/assets/javascripts/wbase/auth/jquery.slimscroll.js +474 -0
- data/app/assets/javascripts/wbase/auth/modernizr.min.js +1 -0
- data/app/assets/javascripts/wbase/auth/pace.min.js +2 -0
- data/app/assets/javascripts/wbase/auth/waves.js +498 -0
- data/app/assets/javascripts/wbase/auth/wow.min.js +2 -0
- data/app/assets/javascripts/wbase/auth.js +12 -0
- data/app/assets/stylesheets/wbase/auth/components.css +2362 -0
- data/app/assets/stylesheets/wbase/auth/core.css +2190 -0
- data/app/assets/stylesheets/wbase/auth/icons.css +12067 -0
- data/app/assets/stylesheets/wbase/auth/pages.css +2039 -0
- data/app/assets/stylesheets/wbase/auth/responsive.css +162 -0
- data/app/assets/stylesheets/wbase/auth/typicons.css +1370 -0
- data/app/assets/stylesheets/wbase/auth/variables.css +0 -0
- data/app/assets/stylesheets/wbase/auth.scss +9 -0
- data/app/controllers/wbase/application_controller.rb +13 -0
- data/app/controllers/wbase/mail_events_controller.rb +21 -0
- data/app/controllers/wbase/password_resets_controller.rb +43 -0
- data/app/controllers/wbase/sessions_controller.rb +35 -0
- data/app/controllers/wbase/static_pages_controller.rb +4 -0
- data/app/controllers/wbase/stripe_webhooks_controller.rb +54 -0
- data/app/controllers/wbase/subscriptions_controller.rb +50 -0
- data/app/controllers/wbase/users_controller.rb +65 -0
- data/app/helpers/wbase/auth_helper.rb +44 -0
- data/app/jobs/wbase/activate_drip_subscriber_job.rb +15 -0
- data/app/jobs/wbase/create_drip_subscriber_job.rb +13 -0
- data/app/jobs/wbase/dripable.rb +22 -0
- data/app/mailers/application_mailer.rb +4 -0
- data/app/mailers/wbase/admin_mailer.rb +35 -0
- data/app/mailers/wbase/password_reset_mailer.rb +20 -0
- data/app/models/wbase/mail_event.rb +21 -0
- data/app/models/wbase/plan.rb +26 -0
- data/app/models/wbase/ssl_verification.rb +21 -0
- data/app/models/wbase/stripe_webhook.rb +22 -0
- data/app/models/wbase/subscription.rb +47 -0
- data/app/models/wbase/userable.rb +85 -0
- data/app/services/wbase/mail_event_batch.rb +22 -0
- data/app/services/wbase/start_subscription.rb +81 -0
- data/app/views/layouts/mailer.html.erb +53 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app/views/layouts/wbase/_common_head.html.erb +46 -0
- data/app/views/layouts/wbase/auth.html.erb +23 -0
- data/app/views/layouts/wbase/landing.html.erb +9 -56
- data/app/views/shared/_errors.html.erb +10 -0
- data/app/views/wbase/admin_mailer/new_subscription.html.erb +33 -0
- data/app/views/wbase/admin_mailer/new_user.html.erb +7 -0
- data/app/views/wbase/password_reset_mailer/reset.html.erb +10 -0
- data/app/views/wbase/password_reset_mailer/reset.text.erb +5 -0
- data/app/views/wbase/password_resets/edit.html.erb +22 -0
- data/app/views/wbase/password_resets/new.html.erb +41 -0
- data/app/views/wbase/sessions/new.html.erb +58 -0
- data/app/views/wbase/static_pages/landing/_pricing.html.erb +6 -2
- data/app/views/wbase/static_pages/start.html.erb +1 -1
- data/app/views/wbase/static_pages/welcome.html.erb +1 -1
- data/app/views/wbase/subscriptions/edit.html.erb +2 -0
- data/app/views/wbase/subscriptions/new.html.erb +91 -0
- data/app/views/wbase/subscriptions/show.html.erb +2 -0
- data/app/views/wbase/users/_affiliate.html.erb +66 -0
- data/app/views/wbase/users/_plan.html.erb +11 -0
- data/app/views/wbase/users/_plans.html.erb +11 -0
- data/app/views/wbase/users/edit.html.erb +2 -0
- data/app/views/wbase/users/new.html.erb +38 -0
- data/app/views/wbase/users/show.html.erb +37 -0
- data/config/initializers/assets.rb +1 -3
- data/config/routes.rb +9 -0
- data/db/migrate/20161127212521_create_wbase_subscriptions.rb +17 -0
- data/db/migrate/20161127212831_create_wbase_plans.rb +15 -0
- data/db/migrate/20161127224117_create_wbase_ssl_verifications.rb +10 -0
- data/db/migrate/20161128022640_create_wbase_mail_events.rb +16 -0
- data/db/migrate/20161128031211_create_wbase_stripe_webhooks.rb +17 -0
- data/lib/wbase/engine.rb +37 -28
- data/lib/wbase/version.rb +1 -1
- data/test/controllers/wbase/mail_events_controller_test.rb +13 -0
- data/test/controllers/wbase/password_resets_controller_test.rb +13 -0
- data/test/controllers/wbase/sessions_controller_test.rb +13 -0
- data/test/controllers/wbase/stripe_webhooks_controller_test.rb +13 -0
- data/test/controllers/wbase/subscriptions_controller_test.rb +13 -0
- data/test/controllers/wbase/users_controller_test.rb +13 -0
- data/test/dummy/config/database.yml +4 -7
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +85 -0
- data/test/dummy/log/development.log +225 -0
- data/test/fixtures/wbase/mail_events.yml +38 -0
- data/test/fixtures/wbase/plans.yml +40 -0
- data/test/fixtures/wbase/stripe_webhooks.yml +41 -0
- data/test/fixtures/wbase/subscriptions.yml +46 -0
- data/test/jobs/wbase/activate_drip_subscriber_job_test.rb +9 -0
- data/test/jobs/wbase/create_drip_subscriber_job_job_test.rb +9 -0
- data/test/mailers/previews/wbase/admin_mailer_preview.rb +11 -0
- data/test/mailers/previews/wbase/password_reset_mailer_preview.rb +11 -0
- data/test/mailers/wbase/admin_mailer_test.rb +14 -0
- data/test/mailers/wbase/password_reset_mailer_test.rb +14 -0
- data/test/models/wbase/mail_event_test.rb +26 -0
- data/test/models/wbase/plan_test.rb +30 -0
- data/test/models/wbase/ssl_verification_test.rb +20 -0
- data/test/models/wbase/stripe_webhook_test.rb +27 -0
- data/test/models/wbase/subscription_test.rb +32 -0
- metadata +121 -12
- data/app/helpers/wbase/application_helper.rb +0 -4
- data/app/helpers/wbase/static_pages_helper.rb +0 -4
- data/app/views/wbase/static_pages/_map.html.erb +0 -17
- data/app/views/wbase/static_pages/_order_stats.html.erb +0 -28
- data/app/views/wbase/static_pages/_pricing.html.erb +0 -89
- data/app/views/wbase/static_pages/_stats.html.erb +0 -28
- data/app/views/wbase/static_pages/_testimonial.html.erb +0 -16
- data/app/views/wbase/static_pages/affiliate.html.erb +0 -54
- data/app/views/wbase/static_pages/faq.html.erb +0 -63
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
@import 'wbase/variables';
|
|
2
|
+
@import 'wbase/bootstrap/_bootstrap';
|
|
3
|
+
// Auth styles
|
|
4
|
+
@import 'wbase/auth/core';
|
|
5
|
+
@import 'wbase/auth/components';
|
|
6
|
+
@import 'wbase/auth/icons';
|
|
7
|
+
@import 'wbase/auth/pages';
|
|
8
|
+
@import 'wbase/auth/responsive';
|
|
9
|
+
@import 'font-awesome';
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
module Wbase
|
|
2
2
|
class ApplicationController < ActionController::Base
|
|
3
|
+
include AuthHelper
|
|
4
|
+
|
|
3
5
|
protect_from_forgery with: :exception
|
|
6
|
+
around_action :tag_logs_with_user_id
|
|
7
|
+
|
|
8
|
+
def tag_logs_with_user_id
|
|
9
|
+
tag = "user-anonymous"
|
|
10
|
+
if logged_in?
|
|
11
|
+
tag = "user-#{ current_user.id } #{ current_user.email }"
|
|
12
|
+
end
|
|
13
|
+
Rails.logger.tagged(tag) do
|
|
14
|
+
yield
|
|
15
|
+
end
|
|
16
|
+
end
|
|
4
17
|
end
|
|
5
18
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_dependency "wbase/application_controller"
|
|
2
|
+
|
|
3
|
+
module Wbase
|
|
4
|
+
class MailEventsController < ApplicationController
|
|
5
|
+
skip_before_action :verify_authenticity_token
|
|
6
|
+
skip_before_action :require_key
|
|
7
|
+
|
|
8
|
+
def create
|
|
9
|
+
Rails.logger.info("Processing mail event batch")
|
|
10
|
+
@event = MailEventBatch.new(params)
|
|
11
|
+
if @event.save
|
|
12
|
+
render json: { 'message': 'success' }, status: 200
|
|
13
|
+
else
|
|
14
|
+
render json: {
|
|
15
|
+
message: 'fail',
|
|
16
|
+
errors: @event.errors.full_messages
|
|
17
|
+
}, status: 422
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_dependency "wbase/application_controller"
|
|
2
|
+
|
|
3
|
+
module Wbase
|
|
4
|
+
class PasswordResetsController < ApplicationController
|
|
5
|
+
layout 'wbase/auth'
|
|
6
|
+
|
|
7
|
+
def new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def create
|
|
11
|
+
# If the user is found, generate password reset
|
|
12
|
+
user = User.find_by(email: params[:email])
|
|
13
|
+
if user
|
|
14
|
+
user.reset_reset_token!
|
|
15
|
+
PasswordResetMailer.reset(user).deliver_later
|
|
16
|
+
end
|
|
17
|
+
flash.now[:alert] = "Thanks! If we find a user with that email, we'll be in touch"
|
|
18
|
+
render :new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def edit
|
|
22
|
+
@user = User.find_by(reset_token: params[:reset_token])
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def update
|
|
26
|
+
@user = User.find_by(reset_token: params[:reset_token])
|
|
27
|
+
if @user
|
|
28
|
+
@user.password = params[:password]
|
|
29
|
+
if @user.save
|
|
30
|
+
login(@user)
|
|
31
|
+
redirect_to '/'
|
|
32
|
+
else
|
|
33
|
+
flash.now[:errors] = @user.errors.full_messages
|
|
34
|
+
render :edit
|
|
35
|
+
end
|
|
36
|
+
else
|
|
37
|
+
flash.now[:errors] = [
|
|
38
|
+
"Hmmm. We didn't find a user with that password reset token :/. try again?"]
|
|
39
|
+
render :edit
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require_dependency "wbase/application_controller"
|
|
2
|
+
|
|
3
|
+
module Wbase
|
|
4
|
+
class SessionsController < ApplicationController
|
|
5
|
+
layout 'wbase/auth'
|
|
6
|
+
|
|
7
|
+
def new
|
|
8
|
+
@user = User.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create
|
|
12
|
+
@user = User.find_by_params(user_params)
|
|
13
|
+
if @user
|
|
14
|
+
login(@user)
|
|
15
|
+
redirect_to '/'
|
|
16
|
+
else
|
|
17
|
+
@user = User.new(user_params)
|
|
18
|
+
flash.now[:errors] = [
|
|
19
|
+
'Hmm. There is not a user with that email / password combo. Try again?']
|
|
20
|
+
render :new
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def destroy
|
|
25
|
+
logout
|
|
26
|
+
redirect_to '/welcome'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def user_params
|
|
32
|
+
params.require(:user).permit(:email, :password)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require_dependency "wbase/application_controller"
|
|
2
|
+
|
|
3
|
+
module Wbase
|
|
4
|
+
class StripeWebhooksController < ApplicationController
|
|
5
|
+
skip_before_filter :verify_authenticity_token
|
|
6
|
+
|
|
7
|
+
def create
|
|
8
|
+
@event = StripeWebhook.new(event_params)
|
|
9
|
+
|
|
10
|
+
if @event.save
|
|
11
|
+
render json: @event
|
|
12
|
+
else
|
|
13
|
+
render json: @event.errors.full_messages, status: :unprocessable_entity
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def event_params
|
|
20
|
+
adaptor = WebhookAdaptor.new(params)
|
|
21
|
+
adaptor.to_h
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class WebhookAdaptor
|
|
26
|
+
attr_reader :params
|
|
27
|
+
|
|
28
|
+
def initialize(params)
|
|
29
|
+
@params = params
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def external_id
|
|
33
|
+
params['id']
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def created
|
|
37
|
+
Time.at(params['created'])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_h
|
|
41
|
+
{
|
|
42
|
+
external_id: external_id,
|
|
43
|
+
object: params['object'],
|
|
44
|
+
api_version: params['api_version'],
|
|
45
|
+
created: created,
|
|
46
|
+
data: params['data'],
|
|
47
|
+
livemode: params['livemode'],
|
|
48
|
+
pending_webhooks: params['pending_webhooks'],
|
|
49
|
+
external_type: params['type'],
|
|
50
|
+
external_request: params['request']
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require_dependency "wbase/application_controller"
|
|
2
|
+
|
|
3
|
+
module Wbase
|
|
4
|
+
class SubscriptionsController < ApplicationController
|
|
5
|
+
before_action :require_login!
|
|
6
|
+
layout 'wbase/auth'
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
if current_user.trial?
|
|
10
|
+
redirect_to '/'
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if params[:plan]
|
|
15
|
+
current_user.selected_plan = params[:plan]
|
|
16
|
+
current_user.save
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create
|
|
21
|
+
# Does the user have a subscription?
|
|
22
|
+
# - if so see if it matches the planid that was passed
|
|
23
|
+
service = StartSubscription.new(current_user, subscription_params)
|
|
24
|
+
service.call
|
|
25
|
+
if service.valid?
|
|
26
|
+
login(service.user)
|
|
27
|
+
AdminMailer.new_subscription(service.user).deliver_later
|
|
28
|
+
ActivateDripSubscriberJob.perform_later(service.user)
|
|
29
|
+
redirect_to '/subscribed'
|
|
30
|
+
else
|
|
31
|
+
flash.now[:errors] = service.errors
|
|
32
|
+
render :new
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def subscription_params
|
|
39
|
+
params
|
|
40
|
+
.require(:subscription)
|
|
41
|
+
.permit(
|
|
42
|
+
:plan_id,
|
|
43
|
+
:stripe_id,
|
|
44
|
+
:credit_card_token,
|
|
45
|
+
:card_type,
|
|
46
|
+
:last_four
|
|
47
|
+
)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require_dependency "wbase/application_controller"
|
|
2
|
+
|
|
3
|
+
module Wbase
|
|
4
|
+
class UsersController < ApplicationController
|
|
5
|
+
before_action :require_login!, only: [:show, :update]
|
|
6
|
+
|
|
7
|
+
def new
|
|
8
|
+
@user = User.new
|
|
9
|
+
render layout: 'wbase/auth'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create
|
|
13
|
+
@user = User.new(user_params)
|
|
14
|
+
@user.verified = true
|
|
15
|
+
if @user.save
|
|
16
|
+
login(@user)
|
|
17
|
+
AdminMailer.new_user(@user).deliver_later
|
|
18
|
+
CreateDripSubscriberJob.perform_later(@user.id)
|
|
19
|
+
redirect_to '/'
|
|
20
|
+
else
|
|
21
|
+
flash.now[:errors] = @user.errors.full_messages
|
|
22
|
+
render :new, layout: 'wbase/auth'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def edit
|
|
27
|
+
@user = current_user
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def update
|
|
31
|
+
@user = current_user
|
|
32
|
+
if !@user.update(update_params)
|
|
33
|
+
flash[:errors] = @user.errors.full_messages
|
|
34
|
+
end
|
|
35
|
+
redirect_to '/user'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def show
|
|
39
|
+
@time_zones = ActiveSupport::TimeZone.us_zones.map(&:name)
|
|
40
|
+
render layout: 'application'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def update_params
|
|
46
|
+
params
|
|
47
|
+
.require(:user)
|
|
48
|
+
.permit(
|
|
49
|
+
:email,
|
|
50
|
+
:name,
|
|
51
|
+
:initial_investment,
|
|
52
|
+
:reinvest_percent,
|
|
53
|
+
:facebook_page,
|
|
54
|
+
:time_zone,
|
|
55
|
+
:phone,
|
|
56
|
+
:notify_email,
|
|
57
|
+
:notify_text
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def user_params
|
|
62
|
+
params.require(:user).permit(:email, :password, :time_zone)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Wbase
|
|
4
|
+
module AuthHelper
|
|
5
|
+
def logged_in?
|
|
6
|
+
!!current_user
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def subscribed?
|
|
10
|
+
logged_in? && current_user && current_user.try(:subscribed?)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def current_user
|
|
14
|
+
@current_user ||= User.find_by(session_token: session[:token])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def admin?
|
|
18
|
+
session[:root]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def require_subscription!
|
|
22
|
+
redirect_to '/subscription/new' unless subscribed?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def require_root!
|
|
26
|
+
redirect_to '/' unless current_user.try(:root)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def require_login!
|
|
30
|
+
redirect_to '/welcome' unless logged_in?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def login(user)
|
|
34
|
+
session[:token] = user.session_token
|
|
35
|
+
session[:root] = user.root?
|
|
36
|
+
user.update(login_at: Time.now)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def logout
|
|
40
|
+
current_user.try(:reset_session_token!)
|
|
41
|
+
session[:root] = false
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Wbase
|
|
2
|
+
class ActivateDripSubscriberJob < ActiveJob::Base
|
|
3
|
+
include Dripable
|
|
4
|
+
queue_as :default
|
|
5
|
+
attr_reader :user
|
|
6
|
+
|
|
7
|
+
def perform(user_id)
|
|
8
|
+
@user = User.find(user_id)
|
|
9
|
+
update_subscriber!
|
|
10
|
+
# TODO: make this a setting!
|
|
11
|
+
drip.unsubscribe(user.email, { campaign_id: 86616253 })
|
|
12
|
+
drip.track_event(user.email, 'Customer subscription updated')
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Wbase
|
|
2
|
+
class CreateDripSubscriberJob < ActiveJob::Base
|
|
3
|
+
include Dripable
|
|
4
|
+
queue_as :default
|
|
5
|
+
attr_reader :user
|
|
6
|
+
|
|
7
|
+
def perform(user_id)
|
|
8
|
+
@user = User.find(user_id)
|
|
9
|
+
update_subscriber!
|
|
10
|
+
drip.track_event(user.email, 'Signed up')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Wbase
|
|
2
|
+
module Dripable
|
|
3
|
+
def update_subscriber!
|
|
4
|
+
drip.create_or_update_subscriber(
|
|
5
|
+
user.email,
|
|
6
|
+
status: user.status,
|
|
7
|
+
user_id: user.id,
|
|
8
|
+
custom_fields: {
|
|
9
|
+
name: user.name,
|
|
10
|
+
api_key: user.api_key,
|
|
11
|
+
}
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def drip
|
|
16
|
+
@client ||= Drip::Client.new do |c|
|
|
17
|
+
c.api_key = ENV['DRIP_API_TOKEN']
|
|
18
|
+
c.account_id = ENV['DRIP_ACCOUNT_ID']
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Wbase
|
|
2
|
+
class AdminMailer < ApplicationMailer
|
|
3
|
+
def new_user(user)
|
|
4
|
+
headers "X-SMTPAPI" => {
|
|
5
|
+
unique_args: {
|
|
6
|
+
user_id: user.id,
|
|
7
|
+
mail_eventable_id: user.id,
|
|
8
|
+
mail_eventable_type: 'User'
|
|
9
|
+
}
|
|
10
|
+
}.to_json
|
|
11
|
+
@user = user
|
|
12
|
+
|
|
13
|
+
mail(
|
|
14
|
+
to: Wbase.admin_email,
|
|
15
|
+
subject: "New User #{ user.email }"
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def new_subscription(user)
|
|
20
|
+
headers "X-SMTPAPI" => {
|
|
21
|
+
unique_args: {
|
|
22
|
+
user_id: user.id,
|
|
23
|
+
mail_eventable_id: user.id,
|
|
24
|
+
mail_eventable_type: 'User'
|
|
25
|
+
}
|
|
26
|
+
}.to_json
|
|
27
|
+
@user = user
|
|
28
|
+
|
|
29
|
+
mail(
|
|
30
|
+
to: Wbase.admin_email,
|
|
31
|
+
subject: "New Subscription #{ user.email }"
|
|
32
|
+
)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Wbase
|
|
2
|
+
class PasswordResetMailer < ApplicationMailer
|
|
3
|
+
def reset(user)
|
|
4
|
+
headers "X-SMTPAPI" => {
|
|
5
|
+
unique_args: {
|
|
6
|
+
user_id: user.id,
|
|
7
|
+
mail_eventable_id: user.id,
|
|
8
|
+
mail_eventable_type: 'User'
|
|
9
|
+
}
|
|
10
|
+
}.to_json
|
|
11
|
+
|
|
12
|
+
@user = user
|
|
13
|
+
mail(
|
|
14
|
+
to: user.email,
|
|
15
|
+
bcc: [Wbase.firehose_email],
|
|
16
|
+
subject: "[#{ Wbase.site_name }] Password Reset"
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# == Schema Information
|
|
2
|
+
#
|
|
3
|
+
# Table name: wbase_mail_events
|
|
4
|
+
#
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# sg_message_id :string
|
|
7
|
+
# email :string
|
|
8
|
+
# timestamp :string
|
|
9
|
+
# smtp_id :string
|
|
10
|
+
# event :string
|
|
11
|
+
# data :json
|
|
12
|
+
# mail_eventable_id :integer
|
|
13
|
+
# mail_eventable_type :string
|
|
14
|
+
# created_at :datetime not null
|
|
15
|
+
# updated_at :datetime not null
|
|
16
|
+
#
|
|
17
|
+
|
|
18
|
+
module Wbase
|
|
19
|
+
class MailEvent < ActiveRecord::Base
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# == Schema Information
|
|
2
|
+
#
|
|
3
|
+
# Table name: wbase_plans
|
|
4
|
+
#
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# name :string not null
|
|
7
|
+
# stripe_id :string not null
|
|
8
|
+
# price :integer not null
|
|
9
|
+
# interval :string default("monthly")
|
|
10
|
+
# features :text
|
|
11
|
+
# highlight :boolean default(FALSE)
|
|
12
|
+
# display_order :integer default(0)
|
|
13
|
+
# created_at :datetime not null
|
|
14
|
+
# updated_at :datetime not null
|
|
15
|
+
#
|
|
16
|
+
# Indexes
|
|
17
|
+
#
|
|
18
|
+
# index_wbase_plans_on_name (name)
|
|
19
|
+
# index_wbase_plans_on_stripe_id (stripe_id)
|
|
20
|
+
#
|
|
21
|
+
|
|
22
|
+
module Wbase
|
|
23
|
+
class Plan < ActiveRecord::Base
|
|
24
|
+
has_many :subscriptions
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# == Schema Information
|
|
2
|
+
#
|
|
3
|
+
# Table name: wbase_ssl_verifications
|
|
4
|
+
#
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# key :string not null
|
|
7
|
+
# value :string not null
|
|
8
|
+
# created_at :datetime not null
|
|
9
|
+
# updated_at :datetime not null
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
module Wbase
|
|
13
|
+
class SslVerification < ActiveRecord::Base
|
|
14
|
+
validates :key, :value, presence: true
|
|
15
|
+
|
|
16
|
+
def self.go(key, value)
|
|
17
|
+
# Helper method for updating quickly
|
|
18
|
+
create!(key: key, value: value)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# == Schema Information
|
|
2
|
+
#
|
|
3
|
+
# Table name: wbase_stripe_webhooks
|
|
4
|
+
#
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# external_id :string
|
|
7
|
+
# object :string
|
|
8
|
+
# api_version :string
|
|
9
|
+
# created :datetime
|
|
10
|
+
# data :json
|
|
11
|
+
# livemode :boolean
|
|
12
|
+
# pending_webhooks :integer
|
|
13
|
+
# external_type :string
|
|
14
|
+
# external_request :string
|
|
15
|
+
# created_at :datetime not null
|
|
16
|
+
# updated_at :datetime not null
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
module Wbase
|
|
20
|
+
class StripeWebhook < ActiveRecord::Base
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# == Schema Information
|
|
2
|
+
#
|
|
3
|
+
# Table name: wbase_subscriptions
|
|
4
|
+
#
|
|
5
|
+
# id :integer not null, primary key
|
|
6
|
+
# stripe_id :string not null
|
|
7
|
+
# plan_id :integer not null
|
|
8
|
+
# last_four :string
|
|
9
|
+
# coupon_id :integer
|
|
10
|
+
# card_type :string
|
|
11
|
+
# current_price :integer
|
|
12
|
+
# user_id :integer not null
|
|
13
|
+
# paid_thru :datetime
|
|
14
|
+
# credit_card_token :string
|
|
15
|
+
# created_at :datetime not null
|
|
16
|
+
# updated_at :datetime not null
|
|
17
|
+
#
|
|
18
|
+
# Indexes
|
|
19
|
+
#
|
|
20
|
+
# index_wbase_subscriptions_on_plan_id (plan_id)
|
|
21
|
+
# index_wbase_subscriptions_on_user_id (user_id)
|
|
22
|
+
#
|
|
23
|
+
|
|
24
|
+
module Wbase
|
|
25
|
+
class Subscription < ActiveRecord::Base
|
|
26
|
+
validates :user, :plan, :credit_card_token, presence: true
|
|
27
|
+
belongs_to :plan
|
|
28
|
+
belongs_to :user
|
|
29
|
+
|
|
30
|
+
def self.current
|
|
31
|
+
where('paid_thru > ?', 7.days.ago)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def current?
|
|
35
|
+
paid_thru && paid_thru > 7.days.ago
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def trial?
|
|
39
|
+
created_at > 14.days.ago
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def trial_days_left
|
|
43
|
+
return 0 unless trial?
|
|
44
|
+
(conversion_day.to_date - Date.current.to_date).to_i
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|