iugusdk 1.0.0.alpha.1 → 1.0.0.alpha.2

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.
Files changed (90) hide show
  1. data/app/controllers/iugu/account_controller.rb +24 -28
  2. data/app/controllers/iugu/account_domains_controller.rb +35 -5
  3. data/app/controllers/iugu/account_roles_controller.rb +2 -5
  4. data/app/controllers/iugu/account_users_controller.rb +6 -12
  5. data/app/controllers/iugu/confirmations_controller.rb +1 -0
  6. data/app/controllers/iugu/invitations_controller.rb +17 -23
  7. data/app/controllers/iugu/omniauth_callbacks_controller.rb +3 -1
  8. data/app/controllers/iugu/passwords_controller.rb +1 -0
  9. data/app/controllers/iugu/registrations_controller.rb +11 -0
  10. data/app/controllers/iugu/sessions_controller.rb +1 -0
  11. data/app/controllers/iugu/settings_controller.rb +14 -0
  12. data/app/mailers/iugu_mailer.rb +2 -2
  13. data/app/models/account.rb +15 -0
  14. data/app/models/account_domain.rb +25 -2
  15. data/app/models/user.rb +19 -3
  16. data/app/models/user_invitation.rb +15 -2
  17. data/app/views/iugu/account_domains/index.html.haml +50 -25
  18. data/app/views/iugu/account_domains/instructions.html.haml +3 -0
  19. data/app/views/iugu/account_users/index.html.haml +4 -2
  20. data/app/views/iugu/invitations/new.html.haml +19 -5
  21. data/app/views/iugu/registrations/new.html.haml +4 -1
  22. data/app/views/iugu/sessions/new.html.haml +9 -8
  23. data/app/views/iugu/settings/account.html.haml +31 -23
  24. data/app/views/iugu/settings/accounts.html.haml +5 -3
  25. data/app/views/iugu/settings/profile.html.haml +47 -44
  26. data/app/views/iugu/shared/_links.haml +14 -11
  27. data/app/views/layouts/settings.html.haml +1 -1
  28. data/config/initializers/devise.rb +0 -13
  29. data/config/locales/iugu.en.yml +6 -0
  30. data/config/locales/iugu.pt-BR.yml +6 -0
  31. data/config/routes.rb +9 -4
  32. data/db/migrate/20120725170859_add_api_token_to_account.rb +9 -0
  33. data/db/migrate/20120803172545_add_guest_to_users.rb +9 -0
  34. data/lib/iugusdk/controllers/helpers.rb +1 -1
  35. data/lib/iugusdk/engine.rb +1 -1
  36. data/lib/iugusdk/iugusdk_base_controller.rb +17 -0
  37. data/lib/iugusdk/version.rb +1 -1
  38. data/lib/iugusdk.rb +30 -5
  39. data/spec/controller_macros.rb +1 -1
  40. data/spec/controllers/account_controller_spec.rb +26 -45
  41. data/spec/controllers/account_domains_controller_spec.rb +87 -5
  42. data/spec/controllers/account_roles_controller_spec.rb +0 -14
  43. data/spec/controllers/invitations_controller_spec.rb +21 -1
  44. data/spec/controllers/registration_controller_spec.rb +15 -0
  45. data/spec/controllers/settings_controller_spec.rb +105 -0
  46. data/spec/dummy/db/schema.rb +3 -1
  47. data/spec/dummy/log/development.log +1579 -0
  48. data/spec/dummy/tmp/cache/assets/C91/3F0/sprockets%2Fcd844928d19e586b4146833b720e7d29 +0 -0
  49. data/spec/dummy/tmp/cache/assets/CAA/190/sprockets%2Fee7298fdc707d359368983e09687c627 +0 -0
  50. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  51. data/spec/dummy/tmp/cache/assets/CE6/A00/sprockets%2F583256e44957e430e1eca9ba1739b6b6 +0 -0
  52. data/spec/dummy/tmp/cache/assets/CE7/4B0/sprockets%2Fd3774b9099289a36db44caec70813a19 +0 -0
  53. data/spec/dummy/tmp/cache/assets/CF1/A70/sprockets%2F368a631d9662bcc4891c91f739b7be37 +0 -0
  54. data/spec/dummy/tmp/cache/assets/CF6/A50/sprockets%2Ff434c1ed5d55916f790cf698832f76b1 +0 -0
  55. data/spec/dummy/tmp/cache/assets/CFB/F30/sprockets%2F84131db318a2faf415628c1075c32bdd +0 -0
  56. data/spec/dummy/tmp/cache/assets/D1A/F20/sprockets%2F102cc77ec78847746b1c164edcb9b639 +0 -0
  57. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  58. data/spec/dummy/tmp/cache/assets/D3A/D70/sprockets%2Fa3bc2dd9e66062ea36222fc6154827ee +0 -0
  59. data/spec/dummy/tmp/cache/assets/D46/E20/sprockets%2F1de16fe0c12f9988664ed66a835a6ab0 +0 -0
  60. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  61. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  62. data/spec/dummy/tmp/cache/assets/D64/F60/sprockets%2F4755d7f5deef0f3212cb7ae30172a33e +0 -0
  63. data/spec/dummy/tmp/cache/assets/D69/850/sprockets%2F5c160a5a6d1068a17af57ab38affd379 +0 -0
  64. data/spec/dummy/tmp/cache/assets/D77/1A0/sprockets%2Ff3864fc006a0674b4c977ff5ca5c7d2e +0 -0
  65. data/spec/dummy/tmp/cache/assets/D77/920/sprockets%2Faf0e746c541e6cf4540db92c87da579c +0 -0
  66. data/spec/dummy/tmp/cache/assets/D7A/850/sprockets%2Fd1e5bf9f64829d062ed7314af28a4e7e +0 -0
  67. data/spec/dummy/tmp/cache/assets/D86/3F0/sprockets%2F8f648e11dfcec044b2997b98f619cfa6 +0 -0
  68. data/spec/dummy/tmp/cache/assets/DA5/130/sprockets%2F7d741fa9ebe86e96fb2bd116ca91234e +0 -0
  69. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  70. data/spec/dummy/tmp/cache/assets/DF2/910/sprockets%2F02db4a9e6f91b47261fa5b0eece2ab8b +0 -0
  71. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  72. data/spec/dummy/tmp/cache/assets/E25/5A0/sprockets%2F795f5759cf9bc7cde9f8acf8c0ca479f +0 -0
  73. data/spec/dummy/tmp/cache/assets/E35/0E0/sprockets%2F9f57eaeefd4c9d5efb41c9801e3f1c1a +0 -0
  74. data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/settings.sassc +0 -0
  75. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/default.sassc +0 -0
  76. data/spec/fabricators/account_domain_fabricator.rb +5 -1
  77. data/spec/models/account_domain_spec.rb +49 -12
  78. data/spec/models/account_spec.rb +32 -4
  79. data/spec/models/user_invitation_spec.rb +23 -1
  80. data/spec/models/user_spec.rb +76 -0
  81. data/spec/requests/account_domain_spec.rb +71 -37
  82. data/spec/requests/account_roles_spec.rb +1 -0
  83. data/spec/requests/account_spec.rb +65 -3
  84. data/spec/requests/account_users_spec.rb +1 -0
  85. data/spec/requests/omniauth_spec.rb +34 -0
  86. data/spec/requests/settings_spec.rb +4 -4
  87. data/spec/requests/user_invitation_spec.rb +32 -1
  88. data/spec/requests/user_spec.rb +13 -0
  89. metadata +126 -70
  90. data/lib/iugusdk/locale_filter.rb +0 -12
@@ -1,9 +1,10 @@
1
1
  %h2 Sign in
2
- = simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
3
- .inputs
4
- = f.input :email, :required => false, :autofocus => true
5
- = f.input :password, :required => false
6
- = f.input :remember_me, :as => :boolean if devise_mapping.rememberable?
7
- .actions
8
- = f.button :submit, "Sign in"
9
- = render :partial => "devise/shared/links"
2
+ - unless IuguSDK::enable_social_only
3
+ = simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
4
+ .inputs
5
+ = f.input :email, :required => false, :autofocus => true
6
+ = f.input :password, :required => false
7
+ = f.input :remember_me, :as => :boolean if devise_mapping.rememberable?
8
+ .actions
9
+ = f.button :submit, "Sign in"
10
+ = render :partial => "iugu/shared/links"
@@ -4,38 +4,48 @@
4
4
  %h2
5
5
  = I18n.t("iugu.account_settings") + " (##{@account.id})"
6
6
 
7
- = simple_form_for @account, :url => account_update_path(:id => @account.id), :method => :put do |f|
8
- = f.label :name
9
- = f.text_field :name
10
- %br
11
- = f.label :subdomain
12
- = f.text_field :subdomain
13
- %br
14
- = f.submit I18n.t("iugu.save")
7
+ - if current_user.is?(:owner, @account)
8
+
9
+ = simple_form_for @account, :url => account_update_path(:id => @account.id), :method => :put do |f|
10
+ = f.label :name
11
+ = f.text_field :name
12
+ %br
13
+ = f.submit I18n.t("iugu.save")
15
14
 
16
15
  %br
17
16
  Plan Name
18
17
  = link_to I18n.t("iugu.change")
19
18
 
20
- %br
21
- %br
22
- Custom Domains
23
- = link_to I18n.t("iugu.manage"), account_domains_index_path(@account.id)
24
- %br
25
- - if @primary_domain
26
- Primary:
27
- = @primary_domain.url
19
+ - unless IuguSDK::enable_custom_domain == false && IuguSDK::enable_subdomain == false
20
+ %br
21
+ %br
22
+ Custom Domains
23
+ - if current_user.is?(:owner, @account) || current_user.is?(:admin, @account)
24
+ = link_to I18n.t("iugu.manage"), account_domains_index_path(@account.id)
25
+ %br
26
+ - if @primary_domain
27
+ Primary:
28
+ = @primary_domain.url
28
29
 
29
- %br
30
30
  %br
31
31
  = link_to I18n.t("iugu.users_and_roles"), account_users_index_path(@account.id)
32
32
 
33
+ - if IuguSDK::enable_subscription_features
34
+ %br
35
+ %br
36
+ %div
37
+ = link_to I18n.t("iugu.payment_history")
33
38
  %br
34
- %br
35
- = link_to I18n.t("iugu.payment_history")
36
39
 
37
- - if current_user.is?(:owner, @account) || current_user.is?(:admin, @account)
38
- %br
40
+ - unless IuguSDK::enable_account_api_token == false
41
+ - if current_user.is?(:owner, @account)
42
+ %div
43
+ Api Token
44
+ = link_to I18n.t("iugu.generate_new_token"), account_generate_new_token_path(@account.id), :method => :post
45
+ %br
46
+ = @account.api_token
47
+
48
+ - if current_user.is?(:owner, @account)
39
49
  %br
40
50
  - unless @account.destroying?
41
51
  = link_to I18n.t("iugu.cancel_account"), account_destroy_path(@account.id), :method => :delete
@@ -44,5 +54,3 @@ Custom Domains
44
54
  = link_to I18n.t("iugu.undo"), account_cancel_destruction_path(@account.id), :method => :delete
45
55
  - else
46
56
  = I18n.t("iugu.account_destruction_in") + @account.destruction_job.run_at.to_s
47
-
48
-
@@ -6,15 +6,13 @@
6
6
  - if current_user.accounts.count > 0
7
7
 
8
8
  %h3
9
- - if IuguSDK::allow_create_account
9
+ - if IuguSDK::enable_multiple_accounts
10
10
  = I18n.t("iugu.accounts")
11
11
  - else
12
12
  - if current_user.accounts.count > 1
13
13
  = I18n.t("iugu.accounts")
14
14
  - else
15
15
  = I18n.t("iugu.account")
16
- %div
17
- = link_to I18n.t("iugu.create_account"), account_create_path, :method => :post
18
16
 
19
17
  - current_user.accounts.each do |account|
20
18
  %div
@@ -31,3 +29,7 @@
31
29
  - else
32
30
  %h2
33
31
  I dont have any Accounts
32
+
33
+ - if IuguSDK::enable_multiple_accounts == true
34
+ %div
35
+ = link_to I18n.t("iugu.create_account"), account_create_path, :method => :post
@@ -30,61 +30,64 @@
30
30
  = f.submit "OK"
31
31
  %br
32
32
 
33
- %div
34
- %h3
35
- = I18n.t "iugu.change_password"
36
-
37
- = simple_form_for @user, :url => profile_update_path, :method => :post do |f|
38
- - if @user.errors.include?(:password)
39
- #error_explanation{ :style => "margin-bottom: 15px" }
40
- %ul
41
- %li
42
- = "Password " + @user.errors[:password].first
43
-
33
+ - unless IuguSDK::enable_social_only
44
34
  %div
45
- = f.label :password
46
- = f.password_field :password
35
+ %h3
36
+ = I18n.t "iugu.change_password"
47
37
 
48
- %div
49
- = f.label :password_confirmation
50
- = f.password_field :password_confirmation
38
+ = simple_form_for @user, :url => profile_update_path, :method => :post do |f|
39
+ - if @user.errors.include?(:password)
40
+ #error_explanation{ :style => "margin-bottom: 15px" }
41
+ %ul
42
+ %li
43
+ = "Password " + @user.errors[:password].first
51
44
 
52
- %div
53
- = f.submit "OK", :id => "new_password_submit"
45
+ %div
46
+ = f.label :password
47
+ = f.password_field :password
48
+
49
+ %div
50
+ = f.label :password_confirmation
51
+ = f.password_field :password_confirmation
54
52
 
55
- %div
56
- - if @user.destroying?
57
- = I18n.t("iugu.user_destruction_in")
58
- = @user.destruction_job.run_at
59
- - unless @user.destruction_job.locked_at
60
- = link_to I18n.t("iugu.undo"), profile_cancel_destruction_path, :confirm => I18n.t("iugu.are_you_sure?")
61
- - else
62
- = link_to I18n.t("iugu.remove_user"), profile_destroy_path, :confirm => I18n.t("iugu.are_you_sure?")
63
- %br
53
+ %div
54
+ = f.submit "OK", :id => "new_password_submit"
64
55
 
65
56
  %div
66
- %h3
67
- = I18n.t "iugu.social_account"
57
+ - if @user.destroying?
58
+ = I18n.t("iugu.user_destruction_in")
59
+ = @user.destruction_job.run_at
60
+ - unless @user.destruction_job.locked_at
61
+ = link_to I18n.t("iugu.undo"), profile_cancel_destruction_path, :confirm => I18n.t("iugu.are_you_sure?")
62
+ - else
63
+ = link_to I18n.t("iugu.remove_user"), profile_destroy_path, :confirm => I18n.t("iugu.are_you_sure?")
64
+ %br
68
65
 
69
- - if flash[:social]
70
- #error_explanation{ :style => "margin-bottom: 15px" }
71
- %ul
72
- %li
73
- = flash[:social]
66
+ - if IuguSDK::enable_social_linking
74
67
 
75
- - @social_accounts.each do |social_account|
68
+ %div
69
+ %h3
70
+ = I18n.t "iugu.social_account"
76
71
 
77
- %div
78
- = social_account.provider.capitalize
79
- UID:
80
- = social_account.social_id
81
- = link_to "Remove", social_destroy_path(:id => social_account.id)
72
+ - if flash[:social]
73
+ #error_explanation{ :style => "margin-bottom: 15px" }
74
+ %ul
75
+ %li
76
+ = flash[:social]
77
+
78
+ - @social_accounts.each do |social_account|
82
79
 
83
- - SOCIAL_ACCOUNTS.keys.each do |provider|
84
-
85
- - unless @social_accounts.where(:provider => provider).first
86
80
  %div
87
- = link_to "Sign in with #{provider.capitalize}", "/account/auth/#{provider}"
81
+ = social_account.provider.capitalize
82
+ UID:
83
+ = social_account.social_id
84
+ = link_to "Remove", social_destroy_path(:id => social_account.id)
85
+
86
+ - SOCIAL_ACCOUNTS.keys.each do |provider|
87
+
88
+ - unless @social_accounts.where(:provider => provider).first
89
+ %div
90
+ = link_to "Sign in with #{provider.capitalize}", "/account/auth/#{provider}"
88
91
 
89
92
 
90
93
 
@@ -1,19 +1,22 @@
1
1
  - if controller_name != 'sessions'
2
2
  = link_to "Sign in", new_session_path(resource_name)
3
3
  %br/
4
- - if devise_mapping.registerable? && controller_name != 'registrations'
5
- = link_to "Sign up", new_registration_path(resource_name)
6
- %br/
7
- - if devise_mapping.recoverable? && controller_name != 'passwords'
8
- = link_to "Forgot your password?", new_password_path(resource_name)
4
+ - unless IuguSDK::enable_social_only
5
+ - if devise_mapping.registerable? && controller_name != 'registrations'
6
+ = link_to "Sign up", new_registration_path(resource_name)
7
+ %br/
8
+ - if devise_mapping.recoverable? && controller_name != 'passwords'
9
+ = link_to "Forgot your password?", new_password_path(resource_name)
9
10
  %br/
10
- - if devise_mapping.confirmable? && controller_name != 'confirmations'
11
- = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name)
11
+ - if IuguSDK::enable_user_confirmation
12
+ - if devise_mapping.confirmable? && controller_name != 'confirmations'
13
+ = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name)
12
14
  %br/
13
15
  - if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
14
16
  = link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name)
15
17
  %br/
16
- - if devise_mapping.omniauthable?
17
- - resource_class.omniauth_providers.each do |provider|
18
- = link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider)
19
- %br/
18
+ - if IuguSDK::enable_social_login
19
+ - if devise_mapping.omniauthable?
20
+ - resource_class.omniauth_providers.each do |provider|
21
+ = link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider)
22
+ %br/
@@ -33,7 +33,7 @@
33
33
 
34
34
  = link_to I18n.t("iugu.profile"), profile_settings_path
35
35
  = ' | '
36
- - if IuguSDK::allow_create_account == false && current_user.accounts.count <= 1
36
+ - if IuguSDK::enable_multiple_accounts == false && current_user.accounts.count <= 1
37
37
  = link_to I18n.t("iugu.account"), account_view_path
38
38
  - else
39
39
  = link_to I18n.t("iugu.accounts"), account_settings_path
@@ -227,16 +227,3 @@ Devise.setup do |config|
227
227
  # end
228
228
 
229
229
  end
230
-
231
- Warden::Manager.after_authentication do |record,auth,opts|
232
- if record && record.respond_to?(:accounts)
233
- include IuguSDK::Controllers::Helpers
234
- cookie_name = 'account'
235
- account = record.default_account( auth.cookies['last_' + cookie_name + '_id'] )
236
- if account
237
- auth.cookies['last_' + cookie_name.downcase + '_id'] = { :value => account.id, :expires => 365.days.from_now }
238
- auth.env['rack.session'][ 'current_' + cookie_name.downcase + '_id' ] = account.id
239
- end
240
- end
241
- end
242
-
@@ -6,6 +6,8 @@ en:
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
8
  iugu:
9
+ try_first: "Try first"
10
+ generate_new_token: "Generate new token"
9
11
  create_account: "Create Account"
10
12
  add: "Add"
11
13
  active: "Active"
@@ -62,6 +64,10 @@ en:
62
64
  verify_later: "Verify later"
63
65
  instructions: "Instructions"
64
66
  notices:
67
+ guest_login: "Guest successfully login"
68
+ subdomain_updated: "Subdomain successfully updated"
69
+ you_are_already_member_of_this_account: "You already member of this account"
70
+ new_token_generated: "New token generated"
65
71
  account_updated: "Account was successfully updated"
66
72
  account_not_found: "Account not found"
67
73
  user_invited: "User invited"
@@ -6,6 +6,8 @@ pt-BR:
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
8
  iugu:
9
+ try_first: "Testar Primeiro"
10
+ generate_new_token: "Gerar novo token"
9
11
  create_account: "Criar Conta"
10
12
  add: "Adicionar"
11
13
  active: "Ativa"
@@ -62,6 +64,10 @@ pt-BR:
62
64
  verify_later: "Verificar depois"
63
65
  instructions: "Instruções"
64
66
  notices:
67
+ guest_login: "Convidado logado com sucesso"
68
+ subdomain_updated: "Subdominio atualizado com sucesso"
69
+ you_are_already_member_of_this_account: "Você já é membro dessa conta"
70
+ new_token_generated: "Novo token gerado"
65
71
  account_updated: "Conta atualizada com sucesso."
66
72
  account_not_found: "Conta não encontrada"
67
73
  user_invited: "Usuário convidado"
data/config/routes.rb CHANGED
@@ -6,10 +6,11 @@ Rails.application.routes.draw do
6
6
  constraints(IuguSDK::RootTenancyUrl) do
7
7
 
8
8
  get "settings" => "iugu/settings#index", :as => "settings"
9
- get "settings/account" => "iugu/account#index", :as => "account_settings"
9
+ get "settings/accounts" => "iugu/account#index", :as => "account_settings"
10
10
  get "settings/account/(:id)" => "iugu/account#view", :as => "account_view"
11
11
  delete "settings/account/(:id)" => "iugu/account#destroy", :as => "account_destroy"
12
12
  delete "settings/account/(:id)/cancel" => "iugu/account#cancel_destruction", :as => "account_cancel_destruction"
13
+ post "settings/account/(:account_id)/generate_new_token" => "iugu/account#generate_new_token", :as => "account_generate_new_token"
13
14
  put "settings/account/(:id)" => "iugu/account#update", :as => "account_update"
14
15
  post "settings/account" => "iugu/account#create", :as => "account_create"
15
16
 
@@ -24,6 +25,7 @@ Rails.application.routes.draw do
24
25
  get "settings/account/:account_id/domain/:domain_id" => "iugu/account_domains#instructions", :as => "account_domains_instructions"
25
26
  post '/settings/account/:account_id/domain/:domain_id' => 'iugu/account_domains#verify', :as => 'verify_domain'
26
27
  post '/settings/account/:account_id/domain/:domain_id/primary' => 'iugu/account_domains#primary', :as => 'primary_domain'
28
+ put '/settings/account/:account_id/subdomain' => 'iugu/account_domains#update_subdomain', :as => 'update_subdomain'
27
29
 
28
30
  get "select_account/:id" => "iugu/account#select", :as => "account_select"
29
31
  get "settings/profile" => "iugu/profile#index", :as => "profile_settings"
@@ -52,9 +54,12 @@ Rails.application.routes.draw do
52
54
  delete 'logout' => 'iugu/sessions#destroy', :as => 'destroy_user_session'
53
55
 
54
56
  # Registration Stuff
55
- get 'signup' => 'iugu/registrations#new', :as => 'new_user_registration'
56
- post 'signup' => 'iugu/registrations#create', :as => 'user_registration'
57
- get 'cancel_signup' => 'iugu/registrations#cancel', :as => 'cancel_user_registration'
57
+ unless IuguSDK::enable_social_only
58
+ get 'signup' => 'iugu/registrations#new', :as => 'new_user_registration'
59
+ post 'signup' => 'iugu/registrations#create', :as => 'user_registration'
60
+ get 'cancel_signup' => 'iugu/registrations#cancel', :as => 'cancel_user_registration'
61
+ end
62
+ post 'try_first' => 'iugu/registrations#try_first', :as => 'try_first'
58
63
 
59
64
  # Confirmation Stuff
60
65
  post 'confirmation' => 'iugu/confirmations#create', :as => 'user_confirmation'
@@ -0,0 +1,9 @@
1
+ class AddApiTokenToAccount < ActiveRecord::Migration
2
+ def up
3
+ add_column :accounts, :api_token, :string
4
+ end
5
+
6
+ def down
7
+ remove_column :accounts, :api_token
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class AddGuestToUsers < ActiveRecord::Migration
2
+ def up
3
+ add_column :users, :guest, :boolean
4
+ end
5
+
6
+ def down
7
+ remove_column :users, :guest
8
+ end
9
+ end
@@ -12,7 +12,7 @@ module IuguSDK
12
12
  @current_user_account ||= search_user_account( session[:current_account_id] )
13
13
  end
14
14
 
15
- def select_account( resource, account_id=nil )
15
+ def set_account( resource, account_id=nil )
16
16
  if account_id == nil
17
17
  account_id = cookies[:last_used_account_id] if cookies[:last_used_account_id]
18
18
  end
@@ -5,7 +5,7 @@ module IuguSDK
5
5
  ActiveSupport.on_load(:action_controller) do
6
6
  include IuguSDK::Controllers::Helpers
7
7
  helper_method "search_user_account", "current_user_account", "is_active?", "body_classes"
8
- ActionController::Base.send(:include, LocaleFilter)
8
+ ActionController::Base.send(:include, IuguSDKBaseController)
9
9
  end
10
10
  end
11
11
 
@@ -0,0 +1,17 @@
1
+ module IuguSDKBaseController
2
+
3
+ def self.included(receiver)
4
+ receiver.append_before_filter :configure_locale
5
+ end
6
+
7
+ def select_account
8
+ Rails.logger.info "SELECT ACCOUNT"
9
+ set_account(current_user) if current_user
10
+ end
11
+
12
+ def configure_locale
13
+ @matched_locale_from_browser = request.preferred_language_from(AvailableLanguage.all)
14
+ I18n.locale = current_user.locale || "en" if signed_in?
15
+ end
16
+
17
+ end
@@ -1,3 +1,3 @@
1
1
  module IuguSDK
2
- VERSION = "1.0.0.alpha.1"
2
+ VERSION = "1.0.0.alpha.2"
3
3
  end
data/lib/iugusdk.rb CHANGED
@@ -5,7 +5,7 @@ require 'iugusdk/controllers/helpers'
5
5
  require 'iugusdk/valid_tenancy_urls'
6
6
  require 'iugusdk/root_tenancy_url'
7
7
  require "iugusdk/engine"
8
- require "iugusdk/locale_filter"
8
+ require "iugusdk/iugusdk_base_controller"
9
9
  require "http_accept_language"
10
10
  require 'devise'
11
11
  require 'omniauth'
@@ -27,11 +27,10 @@ module IuguSDK
27
27
  mattr_accessor :default_subscription_name
28
28
  mattr_accessor :guest_user_prefix
29
29
  mattr_accessor :multiple_accounts_per_user
30
- mattr_accessor :custom_domain_for_accounts
31
30
  mattr_accessor :default_layout
32
31
 
33
- mattr_accessor :allow_create_account
34
- self.allow_create_account = false
32
+ mattr_accessor :enable_multiple_accounts
33
+ self.enable_multiple_accounts = true
35
34
 
36
35
  mattr_accessor :application_main_host
37
36
  self.application_main_host = "iugusdk.dev"
@@ -51,6 +50,33 @@ module IuguSDK
51
50
  mattr_accessor :delay_user_exclusion
52
51
  self.delay_user_exclusion = 0
53
52
 
53
+ mattr_accessor :enable_subdomain
54
+ self.enable_subdomain = false
55
+
56
+ mattr_accessor :enable_custom_domain
57
+ self.enable_custom_domain = false
58
+
59
+ mattr_accessor :enable_account_api_token
60
+ self.enable_custom_domain = false
61
+
62
+ mattr_accessor :enable_social_login
63
+ self.enable_social_login = false
64
+
65
+ mattr_accessor :enable_social_linking
66
+ self.enable_social_linking = false
67
+
68
+ mattr_accessor :enable_user_confirmation
69
+ self.enable_user_confirmation = false
70
+
71
+ mattr_accessor :enable_email_reconfirmation
72
+ self.enable_email_reconfirmation = false
73
+
74
+ mattr_accessor :enable_subscription_features
75
+ self.enable_subscription_features = false
76
+
77
+ mattr_accessor :enable_social_only
78
+ self.enable_social_only = false
79
+
54
80
  self.application_title = 'Application Name'
55
81
 
56
82
  self.no_signup_form = false
@@ -59,7 +85,6 @@ module IuguSDK
59
85
  self.default_subscription_name = 'free'
60
86
  self.guest_user_prefix = 'appuser'
61
87
  self.multiple_accounts_per_user = false
62
- self.custom_domain_for_accounts = false
63
88
 
64
89
  self.default_layout = "settings"
65
90
 
@@ -33,7 +33,7 @@ module ControllerMacros
33
33
  account = Fabricate(:account)
34
34
  account.account_users << Fabricate(:account_user, :user => user)
35
35
  sign_in user
36
- # select_account
36
+ set_account user
37
37
  end
38
38
  end
39
39
  end
@@ -47,35 +47,6 @@ describe Iugu::AccountController do
47
47
  end
48
48
  end
49
49
 
50
- context "when using wrong id" do
51
- before do
52
- get :destroy, :id => 31241
53
- end
54
-
55
- it { response.should redirect_to account_settings_path }
56
-
57
- it { flash.now[:notice].should == I18n.t("iugu.notices.account_not_found") }
58
-
59
- end
60
-
61
- context "when user is not the owner" do
62
- before(:each) do
63
- @account_user = @user.accounts.first.account_users.find_by_user_id(@user.id)
64
- @account = @user.accounts.first
65
- @account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
66
- @account_user.roles.destroy_all
67
- @account_user.roles << AccountRole.create(:name => "user")
68
- get :destroy, :id => @user.accounts.first.id
69
- end
70
-
71
- it { response.should redirect_to account_settings_path }
72
-
73
- it 'should not destroy the account' do
74
- @user.accounts.first.destroying?.should be_false
75
- end
76
-
77
- end
78
-
79
50
  end
80
51
 
81
52
  context "cancel_destruction" do
@@ -96,16 +67,6 @@ describe Iugu::AccountController do
96
67
  end
97
68
  end
98
69
 
99
- context "when using wrong id" do
100
- before do
101
- get :cancel_destruction, :id => 987213
102
- end
103
-
104
- it { response.should redirect_to account_settings_path }
105
-
106
- it { flash.now[:notice].should == I18n.t("iugu.notices.account_not_found") }
107
-
108
- end
109
70
  end
110
71
 
111
72
  context "select" do
@@ -133,12 +94,6 @@ describe Iugu::AccountController do
133
94
  @user.accounts.first.name.should == "fudum"
134
95
  end
135
96
 
136
- it 'should raise error if receive an invalid id' do
137
- lambda {
138
- put :update, :id => 892738912731893719237, :account => { :name => "fudum" }
139
- }.should raise_error ActionController::RoutingError
140
- end
141
-
142
97
  end
143
98
 
144
99
  context "create" do
@@ -154,7 +109,33 @@ describe Iugu::AccountController do
154
109
  post :create
155
110
  end.should change(@user.accounts, :count).by(1)
156
111
  end
112
+
113
+ end
114
+
115
+ context "generate_new_token" do
116
+ login_as_user
117
+ before(:each) do
118
+ IuguSDK::enable_account_api_token = true
119
+ @account = @user.accounts.last
120
+ post :generate_new_token, :account_id => @account.id
121
+ end
122
+
123
+ it { response.should redirect_to account_view_path(@account.id) }
124
+
125
+ it { flash.now[:notice].should == I18n.t("iugu.notices.new_token_generated") }
126
+
127
+ context "when enable_account_api_token == false" do
128
+ before(:each) do
129
+ IuguSDK::enable_account_api_token = false
130
+ end
157
131
 
132
+ it 'should raise RoutingError' do
133
+ lambda {
134
+ post :generate_new_token, :account_id => @account.id
135
+ }.should raise_error ActionController::RoutingError
136
+ end
137
+
138
+ end
158
139
 
159
140
  end
160
141