iugusdk 1.0.0.alpha.3 → 1.0.0.alpha.4
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/iugu/account_controller.rb +14 -5
- data/app/controllers/iugu/pricing_controller.rb +8 -0
- data/app/controllers/iugu/profile_controller.rb +15 -2
- data/app/controllers/iugu/registrations_controller.rb +8 -0
- data/app/controllers/iugu/sessions_controller.rb +8 -0
- data/app/models/account.rb +1 -13
- data/app/models/api_token.rb +32 -0
- data/app/models/user.rb +25 -0
- data/app/views/iugu/pricing/index.html.haml +14 -0
- data/app/views/iugu/settings/account.html.haml +21 -6
- data/app/views/iugu/settings/profile.html.haml +11 -1
- data/config/locales/iugu.en.yml +5 -1
- data/config/locales/iugu.pt-BR.yml +5 -1
- data/config/routes.rb +3 -0
- data/db/migrate/20121023113304_create_api_token.rb +15 -0
- data/lib/iugusdk/engine.rb +8 -0
- data/lib/iugusdk/iugusdk_base_controller.rb +16 -7
- data/lib/iugusdk/root_tenancy_url.rb +3 -3
- data/lib/iugusdk/session_parameter_middleware.rb +15 -0
- data/lib/iugusdk/version.rb +1 -1
- data/lib/iugusdk.rb +17 -0
- data/spec/controllers/account_controller_spec.rb +19 -8
- data/spec/controllers/pricing_controller_spec.rb +16 -0
- data/spec/controllers/profile_controller_spec.rb +13 -4
- data/spec/controllers/registration_controller_spec.rb +15 -1
- data/spec/dummy/config/application.rb +4 -1
- data/spec/dummy/config/initializers/iugusdk.rb +2 -0
- data/spec/dummy/db/migrate/20121108115535_remove_api_token_from_account.rb +7 -0
- data/spec/dummy/db/schema.rb +11 -1
- data/spec/dummy/log/development.log +2967 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/CF1/A70/sprockets%2F368a631d9662bcc4891c91f739b7be37 +0 -0
- data/spec/dummy/tmp/cache/assets/CF6/A50/sprockets%2Ff434c1ed5d55916f790cf698832f76b1 +0 -0
- data/spec/dummy/tmp/cache/assets/CF9/650/sprockets%2F5767184d0e9646ef1aec88c89a47b761 +0 -0
- data/spec/dummy/tmp/cache/assets/D12/D70/sprockets%2F9c37ed72a191cf588665dcb621f401c3 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D77/920/sprockets%2Faf0e746c541e6cf4540db92c87da579c +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/410/sprockets%2F91b38c54838c97f0815ebf8aabddfc4e +0 -0
- data/spec/dummy/tmp/cache/assets/E01/940/sprockets%2F5fe65d209f8e909c4f3b080fceacac1e +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/sass/e35248e21fc26dee07372931d609e6a972a6818c/default.sassc +0 -0
- data/spec/fabricators/api_token_fabricator.rb +5 -0
- data/spec/models/account_spec.rb +0 -33
- data/spec/models/api_token_spec.rb +23 -0
- data/spec/models/user_spec.rb +9 -0
- data/spec/requests/account_spec.rb +19 -5
- data/spec/requests/user_spec.rb +18 -1
- metadata +289 -416
@@ -18,9 +18,13 @@ class Iugu::AccountController < Iugu::AccountSettingsController
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def destroy
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
if IuguSDK::enable_account_cancel
|
22
|
+
account = current_user.accounts.find(params[:id])
|
23
|
+
account.destroy
|
24
|
+
redirect_to(account_settings_path, :notice => I18n.t("iugu.account_destruction_in") + account.destruction_job.run_at.to_s)
|
25
|
+
else
|
26
|
+
raise ActionController::RoutingError.new('Not found')
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def cancel_destruction
|
@@ -49,9 +53,14 @@ class Iugu::AccountController < Iugu::AccountSettingsController
|
|
49
53
|
def generate_new_token
|
50
54
|
if IuguSDK::enable_account_api
|
51
55
|
@account = current_user.accounts.find(params[:account_id])
|
52
|
-
@account.
|
56
|
+
token = @account.tokens.create(description: params[:description], api_type: params[:api_type])
|
57
|
+
if token.new_record?
|
58
|
+
notice = token.errors.full_messages
|
59
|
+
else
|
60
|
+
notice = I18n.t("iugu.notices.new_token_generated")
|
61
|
+
end
|
53
62
|
flash[:group] = :api_token
|
54
|
-
redirect_to account_view_path(params[:account_id]), :notice =>
|
63
|
+
redirect_to account_view_path(params[:account_id]), :notice => notice
|
55
64
|
else
|
56
65
|
raise ActionController::RoutingError.new('Not found')
|
57
66
|
end
|
@@ -25,8 +25,12 @@ class Iugu::ProfileController < Iugu::SettingsController
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def destroy
|
28
|
-
|
29
|
-
|
28
|
+
if IuguSDK::enable_user_cancel
|
29
|
+
(user = current_user).destroy
|
30
|
+
redirect_to(profile_settings_path, :notice => I18n.t("iugu.user_destruction_in") + user.destruction_job.run_at.to_s)
|
31
|
+
else
|
32
|
+
raise ActionController::RoutingError.new("Not found")
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
def cancel_destruction
|
@@ -63,4 +67,13 @@ class Iugu::ProfileController < Iugu::SettingsController
|
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
70
|
+
def renew_token
|
71
|
+
if IuguSDK::enable_user_api
|
72
|
+
current_user.token.refresh
|
73
|
+
redirect_to profile_settings_path
|
74
|
+
else
|
75
|
+
raise ActionController::RoutingError.new("Not found")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
66
79
|
end
|
@@ -3,6 +3,14 @@ class Iugu::RegistrationsController < Devise::RegistrationsController
|
|
3
3
|
|
4
4
|
layout IuguSDK.alternative_layout
|
5
5
|
|
6
|
+
def new
|
7
|
+
if !IuguSDK::default_subscription_name && IuguSDK::enable_subscription_features
|
8
|
+
redirect_to pricing_index_path
|
9
|
+
else
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
6
14
|
def try_first
|
7
15
|
if IuguSDK::enable_guest_user
|
8
16
|
@user = User.create_guest
|
@@ -1,5 +1,13 @@
|
|
1
1
|
class Iugu::SessionsController < Devise::SessionsController
|
2
2
|
after_filter :select_account, :only => :create
|
3
3
|
|
4
|
+
def after_sign_in_path_for(resource_or_scope)
|
5
|
+
IuguSDK::app_main_url
|
6
|
+
end
|
7
|
+
|
8
|
+
def after_sign_out_path_for(resource_or_scope)
|
9
|
+
IuguSDK::app_root_url
|
10
|
+
end
|
11
|
+
|
4
12
|
layout IuguSDK.alternative_layout
|
5
13
|
end
|
data/app/models/account.rb
CHANGED
@@ -4,6 +4,7 @@ class Account < ActiveRecord::Base
|
|
4
4
|
has_many :account_users, :dependent => :destroy, :include => [:roles,:account]
|
5
5
|
has_many :account_domains, :dependent => :destroy
|
6
6
|
has_many :users, :through => :account_users
|
7
|
+
has_many :tokens, :as => :tokenable, :class_name => "ApiToken"
|
7
8
|
handle_asynchronously :destroy, :queue => Proc.new { |p| "account_#{p.id}_destroy" },
|
8
9
|
:run_at => Proc.new { DateTime.now + IuguSDK::delay_account_exclusion }
|
9
10
|
|
@@ -13,7 +14,6 @@ class Account < ActiveRecord::Base
|
|
13
14
|
|
14
15
|
attr_accessible :subdomain, :name
|
15
16
|
|
16
|
-
before_create :set_first_token
|
17
17
|
after_create :set_first_subdomain, :unless => :subdomain?
|
18
18
|
|
19
19
|
def self.get_from_domain(domain)
|
@@ -46,24 +46,12 @@ class Account < ActiveRecord::Base
|
|
46
46
|
(super.blank? ? "#{I18n.t('iugu.account')} ##{id}" : super)
|
47
47
|
end
|
48
48
|
|
49
|
-
def update_api_token
|
50
|
-
self.update_attribute(:api_token, generate_api_token)
|
51
|
-
end
|
52
|
-
|
53
49
|
private
|
54
50
|
|
55
|
-
def set_first_token
|
56
|
-
self.api_token = generate_api_token
|
57
|
-
end
|
58
|
-
|
59
51
|
def set_first_subdomain
|
60
52
|
self.update_attribute(:subdomain, "#{IuguSDK::account_alias_prefix}#{id}")
|
61
53
|
end
|
62
54
|
|
63
|
-
def generate_api_token
|
64
|
-
Digest::MD5.hexdigest("#{SecureRandom.hex(10)}-#{DateTime.now.to_s}")
|
65
|
-
end
|
66
|
-
|
67
55
|
def subdomain_blacklist
|
68
56
|
if subdomain
|
69
57
|
IuguSDK::custom_domain_invalid_prefixes.each do |invalid_prefix|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ApiToken < ActiveRecord::Base
|
2
|
+
belongs_to :tokenable, :polymorphic => true
|
3
|
+
|
4
|
+
before_create :set_first_token
|
5
|
+
|
6
|
+
validates :token, :uniqueness => true
|
7
|
+
validates :description, :uniqueness => { :scope => [:tokenable_id, :tokenable_type] }
|
8
|
+
validates :description, :tokenable, :api_type, :presence => true
|
9
|
+
validate :valid_account_api_type, :if => Proc.new { tokenable_type == "Account" }
|
10
|
+
|
11
|
+
def refresh
|
12
|
+
self.token = generate_api_token
|
13
|
+
save
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_first_token
|
20
|
+
self.token = generate_api_token
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_api_token
|
24
|
+
Digest::MD5.hexdigest("#{SecureRandom.hex(10)}-#{DateTime.now.to_s}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid_account_api_type
|
28
|
+
errors.add(:api_type, I18n.t('errors.messages.not_supported_api_type')) unless IuguSDK::account_api_tokens.include? api_type
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
data/app/models/user.rb
CHANGED
@@ -6,6 +6,7 @@ class User < ActiveRecord::Base
|
|
6
6
|
has_many :account_users, :dependent => :destroy, :include => [:roles,:account]
|
7
7
|
has_many :accounts, :through => :account_users
|
8
8
|
has_many :social_accounts, :dependent => :destroy
|
9
|
+
has_one :token, :as => :tokenable, :class_name => "ApiToken"
|
9
10
|
|
10
11
|
handle_asynchronously :destroy, :queue => Proc.new { |p| "user_#{p.id}_destroy" },
|
11
12
|
:run_at => Proc.new { DateTime.now + IuguSDK::delay_user_exclusion }
|
@@ -22,6 +23,8 @@ class User < ActiveRecord::Base
|
|
22
23
|
|
23
24
|
before_create :skip_confirmation!, :unless => Proc.new { IuguSDK::enable_user_confirmation }
|
24
25
|
|
26
|
+
after_create :init_token, :if => Proc.new { IuguSDK::enable_user_api }
|
27
|
+
|
25
28
|
after_create :create_account_for_user
|
26
29
|
|
27
30
|
after_create :send_welcome_mail, :if => Proc.new { |r| IuguSDK::enable_welcome_mail && !r.email.blank? }
|
@@ -132,8 +135,28 @@ class User < ActiveRecord::Base
|
|
132
135
|
end
|
133
136
|
end
|
134
137
|
|
138
|
+
def access_token
|
139
|
+
"none"
|
140
|
+
end
|
141
|
+
|
142
|
+
# def to_json
|
143
|
+
# super(:only => [:email,:id])
|
144
|
+
# end
|
145
|
+
def as_json(options = nil)
|
146
|
+
{
|
147
|
+
id: id,
|
148
|
+
email: email,
|
149
|
+
locale: locale,
|
150
|
+
access_token: access_token
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
135
154
|
private
|
136
155
|
|
156
|
+
def init_token
|
157
|
+
self.token = ApiToken.create(tokenable: self, api_type: "USER", description: "User")
|
158
|
+
end
|
159
|
+
|
137
160
|
def destroy_private_accounts
|
138
161
|
self.accounts.each do |acc|
|
139
162
|
acc.destroy if acc.account_users.count <= 1
|
@@ -161,4 +184,6 @@ class User < ActiveRecord::Base
|
|
161
184
|
account_user = new_account.account_users.create( { :user => self } )
|
162
185
|
end
|
163
186
|
end
|
187
|
+
|
188
|
+
|
164
189
|
end
|
@@ -42,23 +42,38 @@
|
|
42
42
|
= link_to I18n.t("iugu.payment_history")
|
43
43
|
|
44
44
|
|
45
|
+
%br
|
45
46
|
- if IuguSDK::enable_account_api
|
46
47
|
- if current_user.is?(:owner, @account)
|
47
|
-
%
|
48
|
+
%h2
|
49
|
+
= I18n.t("iugu.api_tokens")
|
48
50
|
- if flash[:group] == :api_token
|
49
51
|
%div
|
50
|
-
|
52
|
+
- if flash[:notice].class == Array
|
53
|
+
%ul
|
54
|
+
- flash[:notice].each do |e|
|
55
|
+
%li
|
56
|
+
= e
|
57
|
+
- else
|
58
|
+
= flash[:notice]
|
51
59
|
%div
|
52
|
-
|
53
|
-
|
60
|
+
- @account.tokens.each do |token|
|
61
|
+
= "#{token.description} - #{token.api_type} - #{token.token} - #{token.created_at}"
|
62
|
+
%br
|
54
63
|
%br
|
55
|
-
= @account.
|
64
|
+
= form_tag(account_generate_new_token_path(@account.id), :method => :post) do
|
65
|
+
= I18n.t('iugu.api_type')
|
66
|
+
= select_tag :api_type, options_for_select(IuguSDK::account_api_tokens)
|
67
|
+
= I18n.t('iugu.description')
|
68
|
+
= text_field_tag :description
|
69
|
+
= submit_tag I18n.t('iugu.create')
|
56
70
|
|
57
71
|
- if current_user.is?(:owner, @account)
|
58
72
|
%br
|
59
73
|
%br
|
60
74
|
- unless @account.destroying?
|
61
|
-
|
75
|
+
- if IuguSDK::enable_account_cancel
|
76
|
+
= link_to I18n.t("iugu.cancel_account"), account_destroy_path(@account.id), :method => :delete
|
62
77
|
- else
|
63
78
|
- if IuguSDK::delay_account_exclusion > 0
|
64
79
|
= link_to I18n.t("iugu.undo"), account_cancel_destruction_path(@account.id), :method => :delete
|
@@ -58,6 +58,15 @@
|
|
58
58
|
= f.submit "OK"
|
59
59
|
%br
|
60
60
|
|
61
|
+
- if IuguSDK::enable_user_api
|
62
|
+
%h3
|
63
|
+
Api Token
|
64
|
+
= @user.token.token
|
65
|
+
%br
|
66
|
+
= link_to "Renew", renew_user_token_path
|
67
|
+
%br
|
68
|
+
%br
|
69
|
+
|
61
70
|
- if IuguSDK::enable_signup_form
|
62
71
|
%div
|
63
72
|
%h3
|
@@ -91,7 +100,8 @@
|
|
91
100
|
- unless @user.destruction_job.locked_at
|
92
101
|
= link_to I18n.t("iugu.undo"), profile_cancel_destruction_path, :confirm => I18n.t("iugu.are_you_sure?")
|
93
102
|
- else
|
94
|
-
|
103
|
+
- if IuguSDK::enable_user_cancel
|
104
|
+
= link_to I18n.t("iugu.remove_user"), profile_destroy_path, :confirm => I18n.t("iugu.are_you_sure?")
|
95
105
|
%br
|
96
106
|
|
97
107
|
- if IuguSDK::enable_social_linking
|
data/config/locales/iugu.en.yml
CHANGED
@@ -5,6 +5,7 @@ en:
|
|
5
5
|
invalid_role: "Not a valid role"
|
6
6
|
only_social_and_no_email: "You need email and password to unlink this Social Account"
|
7
7
|
email_already_in_use: "This email is already in use"
|
8
|
+
not_supported_api_type: "not supported api type"
|
8
9
|
iugu:
|
9
10
|
welcome: "Welcome"
|
10
11
|
edit: "Edit"
|
@@ -19,6 +20,7 @@ en:
|
|
19
20
|
back_to: "Back to"
|
20
21
|
back: "Back"
|
21
22
|
save: "Save"
|
23
|
+
create: "Create"
|
22
24
|
invited_by: "Invited by"
|
23
25
|
accept: "Accept"
|
24
26
|
invite: "Invite"
|
@@ -83,7 +85,9 @@ en:
|
|
83
85
|
did_not_receive_confirmation_instructions?: "Didn't receive confirmation instructions?"
|
84
86
|
plan_name: "Plan name"
|
85
87
|
custom_domains: "Custom domains"
|
86
|
-
|
88
|
+
api_tokens: "Api tokens"
|
89
|
+
api_type: "Api type"
|
90
|
+
description: "Description"
|
87
91
|
i_dont_have_any_accounts: "I don't have any accounts"
|
88
92
|
owner: "owner"
|
89
93
|
admin: "admin"
|
@@ -5,6 +5,7 @@ pt-BR:
|
|
5
5
|
invalid_role: "Cargo invalido"
|
6
6
|
only_social_and_no_email: "Você precisa de um email para poder apagar essa rede social"
|
7
7
|
email_already_in_use: "Esse email já foi utilizado"
|
8
|
+
not_supported_api_type: "tipo de api não suportado"
|
8
9
|
iugu:
|
9
10
|
welcome: "Bem vindo"
|
10
11
|
edit: "Editar"
|
@@ -19,6 +20,7 @@ pt-BR:
|
|
19
20
|
back_to: "Voltar para"
|
20
21
|
back: "Voltar"
|
21
22
|
save: "Salvar"
|
23
|
+
create: "Criar"
|
22
24
|
invited_by: "Convidado por"
|
23
25
|
accept: "Aceitar"
|
24
26
|
invite: "Convidar"
|
@@ -83,7 +85,9 @@ pt-BR:
|
|
83
85
|
did_not_receive_confirmation_instructions?: "Não recebeu as instruções para confirmação?"
|
84
86
|
plan_name: "Nome do Plano"
|
85
87
|
custom_domains: "Dominios customizados"
|
86
|
-
|
88
|
+
api_tokens: "Tokens da api"
|
89
|
+
api_type: "Tipo de api"
|
90
|
+
description: "Descrição"
|
87
91
|
i_dont_have_any_accounts: "Eu não tenho nenhuma conta"
|
88
92
|
owner: "dono"
|
89
93
|
admin: "administrador"
|
data/config/routes.rb
CHANGED
@@ -33,6 +33,7 @@ Rails.application.routes.draw do
|
|
33
33
|
get "settings/profile/cancel_destruction" => "iugu/profile#cancel_destruction", :as => "profile_cancel_destruction"
|
34
34
|
post "settings/profile" => "iugu/profile#update", :as => "profile_update"
|
35
35
|
get "settings/profile/social/destroy" => "iugu/profile#destroy_social", :as => "social_destroy"
|
36
|
+
get "settings/profile/renew_token" => "iugu/profile#renew_token", :as => "renew_user_token"
|
36
37
|
post 'become_user' => 'iugu/profile#become_user', :as => 'become_user'
|
37
38
|
|
38
39
|
get '/settings/account/:account_id/invite' => 'iugu/invitations#new', :as => 'new_invite'
|
@@ -42,6 +43,8 @@ Rails.application.routes.draw do
|
|
42
43
|
get "/settings/account/(:id)/user/:user_id/roles" => "iugu/account_roles#edit", :as => "account_roles_edit"
|
43
44
|
post "/settings/account/(:id)/user/:user_id/roles" => "iugu/account_roles#update", :as => "account_roles_update"
|
44
45
|
|
46
|
+
get '/pricing' => 'iugu/pricing#index', :as => 'pricing_index'
|
47
|
+
|
45
48
|
devise_for :users,
|
46
49
|
:path => 'account',
|
47
50
|
:module => 'iugu',
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateApiToken < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
create_table :api_tokens do |t|
|
4
|
+
t.column :token, :string
|
5
|
+
t.column :description, :string
|
6
|
+
t.column :api_type, :string
|
7
|
+
t.references :tokenable, :polymorphic => true
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def down
|
13
|
+
drop_table :api_tokens
|
14
|
+
end
|
15
|
+
end
|
data/lib/iugusdk/engine.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module IuguSDK
|
2
2
|
class Engine < Rails::Engine
|
3
3
|
|
4
|
+
initializer "iugusdk.load_app_root" do |app|
|
5
|
+
|
6
|
+
IuguSDK.app_root = app.root
|
7
|
+
|
8
|
+
app.config.middleware.insert_before( app.config.session_store, SessionParameterMiddleware, app.config.session_options[:key])
|
9
|
+
|
10
|
+
end
|
11
|
+
|
4
12
|
initializer 'iugusdk.action_controller' do |app|
|
5
13
|
ActiveSupport.on_load(:action_controller) do
|
6
14
|
include IuguSDK::Controllers::Helpers
|
@@ -9,17 +9,26 @@ module IuguSDKBaseController
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def configure_locale
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if(params[:hl])
|
13
|
+
locale = params[:hl] if AvailableLanguage.all.values.include? params[:hl]
|
14
|
+
end
|
15
|
+
unless locale
|
16
|
+
@matched_locale_from_browser = request.preferred_language_from(AvailableLanguage.all.values)
|
17
|
+
if signed_in?
|
18
|
+
if current_user.locale.blank?
|
19
|
+
locale = "en"
|
20
|
+
else
|
21
|
+
locale = current_user.locale
|
22
|
+
end
|
16
23
|
else
|
17
|
-
locale =
|
24
|
+
locale = @matched_locale_from_browser
|
18
25
|
end
|
19
|
-
else
|
20
|
-
locale = @matched_locale_from_browser
|
21
26
|
end
|
22
27
|
I18n.locale = locale
|
23
28
|
end
|
24
29
|
|
30
|
+
def verify_api_key
|
31
|
+
raise ActionController::RoutingError.new("iws_api_key missing") unless IuguSDK::iws_api_key
|
32
|
+
end
|
33
|
+
|
25
34
|
end
|
@@ -14,10 +14,10 @@ module IuguSDK
|
|
14
14
|
# - Return true if request.host is not found in the invalid array
|
15
15
|
def self.matches?(request)
|
16
16
|
application_domain = IuguSDK::application_main_host
|
17
|
-
valids = [ application_domain, ['www.',application_domain].join ]
|
17
|
+
valids = [ application_domain, ['www.',application_domain].join, 'localhost' ]
|
18
18
|
unless Rails.env.production?
|
19
|
-
first_part_uri = application_domain.gsub('.dev','')
|
20
|
-
return true if request.host.match("#{
|
19
|
+
# first_part_uri = application_domain.gsub('.dev','')
|
20
|
+
return true if request.host.match("#{application_domain}\.[^\.]+\.[^\.]+\.[^\.]+\.[^\.]+\.xip.io")
|
21
21
|
end
|
22
22
|
valids.include?( request.host )
|
23
23
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
|
3
|
+
class SessionParameterMiddleware
|
4
|
+
def initialize(app, session_key = '_session_id')
|
5
|
+
@app = app
|
6
|
+
@session_key = session_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
|
11
|
+
params = ::Rack::Utils.parse_query(env['QUERY_STRING'])
|
12
|
+
env['HTTP_COOKIE'] = [ @session_key, params[@session_key] ].join('=').freeze unless params[@session_key].nil?
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
data/lib/iugusdk/version.rb
CHANGED
data/lib/iugusdk.rb
CHANGED
@@ -4,6 +4,7 @@ require 'simple_form'
|
|
4
4
|
require 'iugusdk/controllers/helpers'
|
5
5
|
require 'iugusdk/valid_tenancy_urls'
|
6
6
|
require 'iugusdk/root_tenancy_url'
|
7
|
+
require 'iugusdk/session_parameter_middleware'
|
7
8
|
require "iugusdk/engine"
|
8
9
|
require "iugusdk/iugusdk_base_controller"
|
9
10
|
require "http_accept_language"
|
@@ -62,6 +63,12 @@ module IuguSDK
|
|
62
63
|
mattr_accessor :enable_account_api
|
63
64
|
self.enable_account_api = false
|
64
65
|
|
66
|
+
mattr_accessor :account_api_tokens
|
67
|
+
self.account_api_tokens = []
|
68
|
+
|
69
|
+
mattr_accessor :enable_user_api
|
70
|
+
self.enable_user_api = false
|
71
|
+
|
65
72
|
mattr_accessor :enable_social_login
|
66
73
|
self.enable_social_login = false
|
67
74
|
|
@@ -95,6 +102,14 @@ module IuguSDK
|
|
95
102
|
mattr_accessor :enable_welcome_mail
|
96
103
|
self.enable_welcome_mail = false
|
97
104
|
|
105
|
+
mattr_accessor :enable_account_cancel
|
106
|
+
self.enable_account_cancel = true
|
107
|
+
|
108
|
+
mattr_accessor :enable_user_cancel
|
109
|
+
self.enable_user_cancel = true
|
110
|
+
|
111
|
+
mattr_accessor :iws_api_key
|
112
|
+
|
98
113
|
self.application_title = 'Application Name'
|
99
114
|
|
100
115
|
self.app_main_url = '/'
|
@@ -105,11 +120,13 @@ module IuguSDK
|
|
105
120
|
self.default_layout = "settings"
|
106
121
|
self.alternative_layout = "application"
|
107
122
|
|
123
|
+
|
108
124
|
def initialize
|
109
125
|
end
|
110
126
|
|
111
127
|
def self.setup
|
112
128
|
yield self
|
129
|
+
Iugu::Api.token = iws_api_key if self.iws_api_key
|
113
130
|
end
|
114
131
|
|
115
132
|
end
|
@@ -35,15 +35,25 @@ describe Iugu::AccountController do
|
|
35
35
|
|
36
36
|
context "destroy" do
|
37
37
|
login_as_user
|
38
|
-
context "when
|
39
|
-
|
40
|
-
|
38
|
+
context "when enable_account_cancel == true" do
|
39
|
+
context "and using right id" do
|
40
|
+
before do
|
41
|
+
IuguSDK::enable_account_cancel = true
|
42
|
+
get :destroy, :id => @user.accounts.first.id
|
43
|
+
end
|
44
|
+
|
45
|
+
it { response.should redirect_to account_settings_path }
|
46
|
+
|
47
|
+
it 'should start destruction job' do
|
48
|
+
@user.accounts.first.destroying?.should be_true
|
49
|
+
end
|
41
50
|
end
|
51
|
+
end
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@user.accounts.first.
|
53
|
+
context "when enable_account_cancel == false" do
|
54
|
+
it 'should raise RoutingError' do
|
55
|
+
IuguSDK::enable_account_cancel = false
|
56
|
+
lambda{ get :destroy, :id => @user.accounts.first.id }.should raise_error ActionController::RoutingError
|
47
57
|
end
|
48
58
|
end
|
49
59
|
|
@@ -116,8 +126,9 @@ describe Iugu::AccountController do
|
|
116
126
|
login_as_user
|
117
127
|
before(:each) do
|
118
128
|
IuguSDK::enable_account_api = true
|
129
|
+
IuguSDK::account_api_tokens = [ 'test' ]
|
119
130
|
@account = @user.accounts.last
|
120
|
-
post :generate_new_token, :account_id => @account.id
|
131
|
+
post :generate_new_token, :account_id => @account.id, :description => 'token x', :api_type => 'test'
|
121
132
|
end
|
122
133
|
|
123
134
|
it { response.should redirect_to account_view_path(@account.id) }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Iugu::PricingController do
|
4
|
+
login_as_user
|
5
|
+
describe "unless iws_api_key" do
|
6
|
+
before do
|
7
|
+
IuguSDK::iws_api_key = nil
|
8
|
+
end
|
9
|
+
it 'should raise routing error' do
|
10
|
+
lambda {
|
11
|
+
get :index
|
12
|
+
}.should raise_error ActionController::RoutingError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -39,13 +39,22 @@ describe Iugu::ProfileController do
|
|
39
39
|
|
40
40
|
context "destroy" do
|
41
41
|
login_as_user
|
42
|
+
context "when enable_user_cancel == true" do
|
43
|
+
before(:each) do
|
44
|
+
IuguSDK::enable_user_cancel = true
|
45
|
+
get :destroy
|
46
|
+
end
|
42
47
|
|
43
|
-
|
44
|
-
|
48
|
+
it 'user should be destroyed' do
|
49
|
+
@user.destroying?.should be_true
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
|
-
|
48
|
-
|
53
|
+
context "when enable_user_cancel == false" do
|
54
|
+
it 'should raise RoutingError' do
|
55
|
+
IuguSDK::enable_user_cancel = false
|
56
|
+
lambda{get :destroy}.should raise_error ActionController::RoutingError
|
57
|
+
end
|
49
58
|
end
|
50
59
|
|
51
60
|
end
|
@@ -26,7 +26,21 @@ describe Iugu::RegistrationsController do
|
|
26
26
|
}.should raise_error ActionController::RoutingError
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context "new" do
|
33
|
+
context "when enable_subscription_features == true and default_subscription_name = nil " do
|
34
|
+
before(:each) do
|
35
|
+
IuguSDK::enable_subscription_features = true
|
36
|
+
IuguSDK::default_subscription_name = nil
|
37
|
+
end
|
38
|
+
it 'should redirect to pricing' do
|
39
|
+
get :new
|
40
|
+
response.should redirect_to pricing_index_path
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
end
|
31
45
|
|
32
46
|
end
|
@@ -58,8 +58,11 @@ module Dummy
|
|
58
58
|
password: "envioiugu",
|
59
59
|
authentication: :plain,
|
60
60
|
enable_starttls_auto: true
|
61
|
-
}
|
61
|
+
}
|
62
62
|
|
63
|
+
# config.session_store :disabled
|
64
|
+
# config.middleware.delete(ActionDispatch::Cookies)
|
65
|
+
# config.middleware.delete(ActionDispatch::Session::CookieStore)
|
63
66
|
|
64
67
|
end
|
65
68
|
end
|