iugusdk 1.0.0.alpha.2 → 1.0.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/app/controllers/iugu/account_controller.rb +3 -1
  2. data/app/controllers/iugu/account_domains_controller.rb +3 -2
  3. data/app/controllers/iugu/account_users_controller.rb +7 -3
  4. data/app/controllers/iugu/confirmations_controller.rb +2 -0
  5. data/app/controllers/iugu/omniauth_callbacks_controller.rb +1 -1
  6. data/app/controllers/iugu/passwords_controller.rb +2 -0
  7. data/app/controllers/iugu/profile_controller.rb +24 -2
  8. data/app/controllers/iugu/registrations_controller.rb +17 -7
  9. data/app/controllers/iugu/sessions_controller.rb +2 -0
  10. data/app/controllers/iugu/unlocks_controller.rb +1 -0
  11. data/app/mailers/iugu_mailer.rb +7 -0
  12. data/app/models/account.rb +8 -1
  13. data/app/models/account_domain.rb +7 -1
  14. data/app/models/account_role.rb +2 -0
  15. data/app/models/account_user.rb +2 -0
  16. data/app/models/available_language.rb +27 -2
  17. data/app/models/user.rb +44 -3
  18. data/app/models/user_invitation.rb +1 -1
  19. data/app/views/iugu/account_domains/index.html.haml +3 -1
  20. data/app/views/iugu/account_roles/edit.html.haml +2 -2
  21. data/app/views/iugu/account_users/index.html.haml +4 -1
  22. data/app/views/iugu/confirmations/new.html.haml +3 -2
  23. data/app/views/iugu/invitations/new.html.haml +3 -3
  24. data/app/views/iugu/mailer/confirmation_instructions.html.haml +4 -2
  25. data/app/views/iugu/mailer/reset_password_instructions.html.haml +6 -4
  26. data/app/views/iugu/mailer/welcome.html.haml +2 -0
  27. data/app/views/iugu/passwords/edit.html.haml +5 -4
  28. data/app/views/iugu/passwords/new.html.haml +3 -2
  29. data/app/views/iugu/registrations/edit.html.haml +10 -7
  30. data/app/views/iugu/registrations/new.html.haml +11 -5
  31. data/app/views/iugu/sessions/new.html.haml +6 -5
  32. data/app/views/iugu/settings/account.html.haml +23 -13
  33. data/app/views/iugu/settings/accounts.html.haml +2 -2
  34. data/app/views/iugu/settings/profile.html.haml +92 -61
  35. data/app/views/iugu/shared/_links.haml +6 -6
  36. data/{spec/dummy/tmp/restart.txt → app/views/iugu/shared/_signup_fields.haml} +0 -0
  37. data/app/views/layouts/settings.html.haml +2 -2
  38. data/config/initializers/devise.rb +1 -1
  39. data/config/locales/iugu.en.yml +39 -0
  40. data/config/locales/iugu.pt-BR.yml +43 -4
  41. data/config/routes.rb +2 -1
  42. data/lib/iugusdk.rb +29 -12
  43. data/lib/iugusdk/controllers/helpers.rb +4 -0
  44. data/lib/iugusdk/engine.rb +1 -1
  45. data/lib/iugusdk/iugusdk_base_controller.rb +11 -3
  46. data/lib/iugusdk/root_tenancy_url.rb +4 -0
  47. data/lib/iugusdk/version.rb +1 -1
  48. data/spec/controllers/account_controller_spec.rb +3 -3
  49. data/spec/controllers/account_domains_controller_spec.rb +6 -6
  50. data/spec/controllers/account_users_controller_spec.rb +15 -3
  51. data/spec/controllers/profile_controller_spec.rb +35 -0
  52. data/spec/controllers/registration_controller_spec.rb +22 -5
  53. data/spec/dummy/config/initializers/iugusdk.rb +1 -0
  54. data/spec/dummy/config/social_accounts.yml +2 -0
  55. data/spec/dummy/db/schema.rb +6 -6
  56. data/spec/fabricators/user_fabricator.rb +1 -0
  57. data/spec/models/account_domain_spec.rb +5 -3
  58. data/spec/models/account_spec.rb +14 -1
  59. data/spec/models/available_language_spec.rb +26 -0
  60. data/spec/models/user_spec.rb +80 -5
  61. data/spec/requests/account_domain_spec.rb +4 -4
  62. data/spec/requests/account_spec.rb +26 -5
  63. data/spec/requests/account_users_spec.rb +6 -5
  64. data/spec/requests/user_spec.rb +14 -0
  65. metadata +427 -372
  66. data/spec/dummy/log/development.log +0 -1683
  67. data/spec/dummy/log/test.log +0 -13269
  68. data/spec/dummy/tmp/cache/assets/C91/3F0/sprockets%2Fcd844928d19e586b4146833b720e7d29 +0 -0
  69. data/spec/dummy/tmp/cache/assets/CAA/190/sprockets%2Fee7298fdc707d359368983e09687c627 +0 -0
  70. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  71. data/spec/dummy/tmp/cache/assets/CE6/A00/sprockets%2F583256e44957e430e1eca9ba1739b6b6 +0 -0
  72. data/spec/dummy/tmp/cache/assets/CE7/4B0/sprockets%2Fd3774b9099289a36db44caec70813a19 +0 -0
  73. data/spec/dummy/tmp/cache/assets/CF1/A70/sprockets%2F368a631d9662bcc4891c91f739b7be37 +0 -0
  74. data/spec/dummy/tmp/cache/assets/CF6/A50/sprockets%2Ff434c1ed5d55916f790cf698832f76b1 +0 -0
  75. data/spec/dummy/tmp/cache/assets/CFB/F30/sprockets%2F84131db318a2faf415628c1075c32bdd +0 -0
  76. data/spec/dummy/tmp/cache/assets/D1A/F20/sprockets%2F102cc77ec78847746b1c164edcb9b639 +0 -0
  77. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  78. data/spec/dummy/tmp/cache/assets/D3A/D70/sprockets%2Fa3bc2dd9e66062ea36222fc6154827ee +0 -0
  79. data/spec/dummy/tmp/cache/assets/D46/E20/sprockets%2F1de16fe0c12f9988664ed66a835a6ab0 +0 -0
  80. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  81. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  82. data/spec/dummy/tmp/cache/assets/D64/F60/sprockets%2F4755d7f5deef0f3212cb7ae30172a33e +0 -0
  83. data/spec/dummy/tmp/cache/assets/D69/850/sprockets%2F5c160a5a6d1068a17af57ab38affd379 +0 -0
  84. data/spec/dummy/tmp/cache/assets/D77/1A0/sprockets%2Ff3864fc006a0674b4c977ff5ca5c7d2e +0 -0
  85. data/spec/dummy/tmp/cache/assets/D77/920/sprockets%2Faf0e746c541e6cf4540db92c87da579c +0 -0
  86. data/spec/dummy/tmp/cache/assets/D7A/850/sprockets%2Fd1e5bf9f64829d062ed7314af28a4e7e +0 -0
  87. data/spec/dummy/tmp/cache/assets/D86/3F0/sprockets%2F8f648e11dfcec044b2997b98f619cfa6 +0 -0
  88. data/spec/dummy/tmp/cache/assets/DA5/130/sprockets%2F7d741fa9ebe86e96fb2bd116ca91234e +0 -0
  89. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  90. data/spec/dummy/tmp/cache/assets/DF2/910/sprockets%2F02db4a9e6f91b47261fa5b0eece2ab8b +0 -0
  91. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  92. data/spec/dummy/tmp/cache/assets/E25/5A0/sprockets%2F795f5759cf9bc7cde9f8acf8c0ca479f +0 -0
  93. data/spec/dummy/tmp/cache/assets/E35/0E0/sprockets%2F9f57eaeefd4c9d5efb41c9801e3f1c1a +0 -0
  94. data/spec/dummy/tmp/cache/sass/1f198e4a81e57d6c86c6fff1f0e13592b233ebc2/prettify.cssc +0 -0
  95. data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_css3.scssc +0 -0
  96. data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_support.scssc +0 -0
  97. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/components.sassc +0 -0
  98. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/iugu-ux.sassc +0 -0
  99. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/mixins.sassc +0 -0
  100. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/reset.sassc +0 -0
  101. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/typography.sassc +0 -0
  102. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/utilities.sassc +0 -0
  103. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/variables.sassc +0 -0
  104. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_appearance.scssc +0 -0
  105. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-clip.scssc +0 -0
  106. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-origin.scssc +0 -0
  107. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-size.scssc +0 -0
  108. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_border-radius.scssc +0 -0
  109. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-shadow.scssc +0 -0
  110. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-sizing.scssc +0 -0
  111. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box.scssc +0 -0
  112. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_columns.scssc +0 -0
  113. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_font-face.scssc +0 -0
  114. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_images.scssc +0 -0
  115. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_inline-block.scssc +0 -0
  116. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_opacity.scssc +0 -0
  117. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_shared.scssc +0 -0
  118. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_text-shadow.scssc +0 -0
  119. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transform.scssc +0 -0
  120. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transition.scssc +0 -0
  121. data/spec/dummy/tmp/cache/sass/9da4e62a062dae83baa33f29455be2ba30cf5dce/_sprites.scssc +0 -0
  122. data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_base.scssc +0 -0
  123. data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_sprite-img.scssc +0 -0
  124. data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/base_settings.sassc +0 -0
  125. data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/settings.sassc +0 -0
  126. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/application.sassc +0 -0
  127. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/base_settings.sassc +0 -0
  128. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/default.sassc +0 -0
  129. data/spec/dummy/tmp/cache/sass/eab9c0816f626278a6731ce2928de6fdbe99322b/_hacks.scssc +0 -0
@@ -37,6 +37,7 @@ class Iugu::AccountController < Iugu::AccountSettingsController
37
37
  def update
38
38
  @account = Account.find(params[:id])
39
39
  @account.update_attributes(params[:account])
40
+ flash[:group] = :account_update
40
41
  redirect_to account_view_path(params[:id]), :notice => I18n.t("iugu.notices.account_updated")
41
42
  end
42
43
 
@@ -46,9 +47,10 @@ class Iugu::AccountController < Iugu::AccountSettingsController
46
47
  end
47
48
 
48
49
  def generate_new_token
49
- if IuguSDK::enable_account_api_token == true
50
+ if IuguSDK::enable_account_api
50
51
  @account = current_user.accounts.find(params[:account_id])
51
52
  @account.update_api_token
53
+ flash[:group] = :api_token
52
54
  redirect_to account_view_path(params[:account_id]), :notice => I18n.t("iugu.notices.new_token_generated")
53
55
  else
54
56
  raise ActionController::RoutingError.new('Not found')
@@ -5,7 +5,7 @@ class Iugu::AccountDomainsController < Iugu::AccountSettingsController
5
5
  before_filter(:only => [:index, :create, :destroy, :instruction, :verify, :primary, :update_subdomain]) { |c| c.must_be [:owner, :admin], :account_id }
6
6
 
7
7
  def index
8
- unless IuguSDK::enable_custom_domain == false && IuguSDK::enable_subdomain == false
8
+ unless IuguSDK::enable_custom_domain == false && IuguSDK::enable_account_alias == false
9
9
  @account = current_user.accounts.find(params[:account_id])
10
10
  @account_domains = @account.account_domains.where(:account_id => params[:account_id])
11
11
  @account_domain = AccountDomain.new
@@ -25,6 +25,7 @@ class Iugu::AccountDomainsController < Iugu::AccountSettingsController
25
25
  end
26
26
 
27
27
  def destroy
28
+ flash[:group] = :account_domain
28
29
  begin
29
30
  @account = current_user.accounts.find(params[:account_id])
30
31
  @domain = @account.account_domains.find(params[:domain_id])
@@ -71,7 +72,7 @@ class Iugu::AccountDomainsController < Iugu::AccountSettingsController
71
72
  end
72
73
 
73
74
  def update_subdomain
74
- if IuguSDK::enable_subdomain == true
75
+ if IuguSDK::enable_account_alias == true
75
76
  @account = current_user.accounts.find(params[:account_id])
76
77
  if @account.update_attributes(params[:account])
77
78
  redirect_to account_domains_index_path(@account.id), :notice => I18n.t("iugu.notices.subdomain_updated")
@@ -3,9 +3,13 @@ class Iugu::AccountUsersController < Iugu::AccountSettingsController
3
3
  before_filter(:only => [:destroy, :cancel_destruction]) { |c| c.must_be [:owner, :admin], :account_id }
4
4
 
5
5
  def index
6
- @account = Account.find(params[:account_id])
7
- @account_users = @account.account_users
8
- render 'iugu/account_users/index'
6
+ if IuguSDK::enable_multiple_users_per_account
7
+ @account = Account.find(params[:account_id])
8
+ @account_users = @account.account_users
9
+ render 'iugu/account_users/index'
10
+ else
11
+ raise ActionController::RoutingError.new("Not found")
12
+ end
9
13
  end
10
14
 
11
15
  def view
@@ -1,3 +1,5 @@
1
1
  class Iugu::ConfirmationsController < Devise::ConfirmationsController
2
2
  after_filter :select_account, :only => :show
3
+
4
+ layout IuguSDK.alternative_layout
3
5
  end
@@ -5,7 +5,7 @@ class Iugu::OmniauthCallbacksController < Devise::OmniauthCallbacksController
5
5
  if current_user
6
6
  raise ActionController::RoutingError.new("Not found") unless IuguSDK::enable_social_linking
7
7
  current_user.find_or_create_social(env["omniauth.auth"])
8
- redirect_to after_sign_in_path_for( current_user )
8
+ redirect_to(env["omniauth.origin"] || root_path)
9
9
  else
10
10
  raise ActionController::RoutingError.new("Not found") unless IuguSDK::enable_social_login
11
11
  if user = User.find_or_create_by_social(env["omniauth.auth"])
@@ -1,3 +1,5 @@
1
1
  class Iugu::PasswordsController < Devise::PasswordsController
2
2
  after_filter :select_account, :only => :update
3
+
4
+ layout IuguSDK.alternative_layout
3
5
  end
@@ -9,10 +9,17 @@ class Iugu::ProfileController < Iugu::SettingsController
9
9
  def update
10
10
  @user = current_user
11
11
  @social_accounts = @user.social_accounts
12
+ if !params[:user][:password].blank?
13
+ flash.now[:group] = :password_update
14
+ else
15
+ flash.now[:group] = :profile_update
16
+ end
12
17
  if @user.update_attributes(params[:user])
13
- flash[:notice] = I18n.t('iugu.notices.user_update')
18
+ I18n.locale = @user.locale
19
+ sign_in @user, :bypass => true if !params[:user][:password].blank?
20
+ flash.now[:notice] = I18n.t('iugu.notices.user_update')
14
21
  else
15
- flash[:error] = @user.errors.full_messages
22
+ flash.now[:error] = @user.errors.full_messages
16
23
  end
17
24
  render 'iugu/settings/profile'
18
25
  end
@@ -41,4 +48,19 @@ class Iugu::ProfileController < Iugu::SettingsController
41
48
  redirect_to profile_settings_path
42
49
  end
43
50
 
51
+ def become_user
52
+ if current_user.guest
53
+ @user = current_user
54
+ if current_user.become_user(params[:user])
55
+ sign_in @user
56
+ select_account
57
+ redirect_to root_path, :notice => I18n.t("iugu.notices.congrats_for_becoming_user")
58
+ else
59
+ render 'iugu/settings/profile'
60
+ end
61
+ else
62
+ raise ActionController::RoutingError.new("Not found")
63
+ end
64
+ end
65
+
44
66
  end
@@ -1,14 +1,24 @@
1
1
  class Iugu::RegistrationsController < Devise::RegistrationsController
2
2
  after_filter :select_account, :only => [:create,:update]
3
3
 
4
+ layout IuguSDK.alternative_layout
5
+
4
6
  def try_first
5
- @user = User.create_guest
6
- @user.remember_me = true
7
- sign_in @user
8
- select_account
9
- flash[:notice] = I18n.t("iugu.notices.guest_login")
10
- redirect_to root_path
11
- #respond_with @user, :location => sign_up_path_for(@user)
7
+ if IuguSDK::enable_guest_user
8
+ @user = User.create_guest
9
+ @user.remember_me = true
10
+ sign_in @user
11
+ select_account
12
+ flash[:notice] = I18n.t("iugu.notices.guest_login")
13
+ redirect_to root_path
14
+ #respond_with @user, :location => sign_up_path_for(@user)
15
+ else
16
+ raise ActionController::RoutingError.new("Not found")
17
+ end
18
+ end
19
+
20
+ def after_sign_up_path_for(resource)
21
+ IuguSDK::app_main_url
12
22
  end
13
23
  end
14
24
 
@@ -1,3 +1,5 @@
1
1
  class Iugu::SessionsController < Devise::SessionsController
2
2
  after_filter :select_account, :only => :create
3
+
4
+ layout IuguSDK.alternative_layout
3
5
  end
@@ -1,2 +1,3 @@
1
1
  class Iugu::UnlocksController < Devise::UnlocksController
2
+ layout IuguSDK.alternative_layout
2
3
  end
@@ -13,4 +13,11 @@ class IuguMailer < Devise::Mailer
13
13
  format.html { render "iugu/mailer/invitation" }
14
14
  end
15
15
  end
16
+
17
+ def welcome(user)
18
+ @user = user
19
+ mail(to: @user.email, :subject => "Bem vindo!") do |format|
20
+ format.html { render "iugu/mailer/welcome" }
21
+ end
22
+ end
16
23
  end
@@ -9,9 +9,12 @@ class Account < ActiveRecord::Base
9
9
 
10
10
  validates :subdomain, :uniqueness => true, :unless => Proc.new { |a| a.subdomain.blank? }
11
11
  validates :api_token, :uniqueness => true, :if => :api_token?
12
- validate :subdomain_blacklist
12
+ validate :subdomain_blacklist, :name
13
+
14
+ attr_accessible :subdomain, :name
13
15
 
14
16
  before_create :set_first_token
17
+ after_create :set_first_subdomain, :unless => :subdomain?
15
18
 
16
19
  def self.get_from_domain(domain)
17
20
  AccountDomain.verified.find_by_url(domain).try(:account) || Account.find_by_subdomain(domain.gsub(".#{IuguSDK::application_main_host}",""))
@@ -53,6 +56,10 @@ class Account < ActiveRecord::Base
53
56
  self.api_token = generate_api_token
54
57
  end
55
58
 
59
+ def set_first_subdomain
60
+ self.update_attribute(:subdomain, "#{IuguSDK::account_alias_prefix}#{id}")
61
+ end
62
+
56
63
  def generate_api_token
57
64
  Digest::MD5.hexdigest("#{SecureRandom.hex(10)}-#{DateTime.now.to_s}")
58
65
  end
@@ -5,9 +5,15 @@ class AccountDomain < ActiveRecord::Base
5
5
  validates :url, :account_id, :presence => true
6
6
  validate :validate_pattern, :validate_blacklist
7
7
 
8
+ attr_accessible :url
9
+
8
10
  before_create :validate_not_repeated
9
11
 
10
- before_destroy { |record| record.update_attributes(:verified => false, :primary => false) }
12
+ before_destroy do |record|
13
+ record.verified = false
14
+ record.primary = false
15
+ record.save
16
+ end
11
17
  before_destroy :set_first_domain
12
18
 
13
19
  scope :verified, where(:verified => true)
@@ -5,6 +5,8 @@ class AccountRole < ActiveRecord::Base
5
5
  validates_uniqueness_of :name, :scope => :account_user_id, :allow_nil => false
6
6
  validates_presence_of :account_user
7
7
 
8
+ attr_accessible :name
9
+
8
10
  before_destroy do
9
11
  false if only_owner?
10
12
  end
@@ -8,6 +8,8 @@ class AccountUser < ActiveRecord::Base
8
8
  validates_presence_of :user
9
9
  validates_presence_of :account
10
10
 
11
+ attr_accessible :user
12
+
11
13
  handle_asynchronously :destroy, :queue => Proc.new { |p| "account_user_#{p.id}_destroy" },
12
14
  :run_at => Proc.new { DateTime.now + IuguSDK::delay_account_user_exclusion }
13
15
 
@@ -1,9 +1,34 @@
1
+ # encoding: utf-8
2
+ #
1
3
  class AvailableLanguage
2
4
  def self.all
5
+ default = {"English" => "en", 'Português (Brasil)' => "pt-BR"}
3
6
  begin
4
- YAML.load_file("#{Rails.root.to_s}/config/available_language.yml")['locales']
7
+ YAML.load_file("#{Rails.root.to_s}/config/available_language.yml")['locales'] || default
5
8
  rescue
6
- ["en"]
9
+ default
10
+ end
11
+ end
12
+
13
+ def self.best_locale_for(lang)
14
+ lang.gsub!('_', '-')
15
+ locale = "en"
16
+ if self.all.values.include? lang
17
+ locale = lang
18
+ else
19
+ self.all.values.each do |l|
20
+ locale = l if l.gsub(/-.*/, '') == lang.gsub(/-.*/, '')
21
+ end
22
+ end
23
+ locale
24
+ end
25
+
26
+ def self.default_locale
27
+ default = "en"
28
+ begin
29
+ YAML.load_file("#{Rails.root.to_s}/config/available_language.yml")['default'] || default
30
+ rescue
31
+ default
7
32
  end
8
33
  end
9
34
 
@@ -14,15 +14,24 @@ class User < ActiveRecord::Base
14
14
  :recoverable, :rememberable, :validatable, :omniauthable
15
15
 
16
16
  # Setup accessible (or protected) attributes for your model
17
- attr_accessible :email, :password, :password_confirmation, :remember_me, :locale, :name, :birthdate, :guest
17
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :locale, :name, :birthdate, :guest, :account_alias
18
+
19
+ mattr_accessor :account_alias
20
+
21
+ before_destroy :destroy_private_accounts
18
22
 
19
23
  before_create :skip_confirmation!, :unless => Proc.new { IuguSDK::enable_user_confirmation }
20
24
 
21
25
  after_create :create_account_for_user
22
26
 
27
+ after_create :send_welcome_mail, :if => Proc.new { |r| IuguSDK::enable_welcome_mail && !r.email.blank? }
28
+
23
29
  before_save :skip_reconfirmation!, :unless => Proc.new { IuguSDK::enable_email_reconfirmation }
24
30
 
25
31
  validates :email, :email => true, :unless => :guest?
32
+ validates :locale, :presence => true
33
+
34
+ default_value_for :locale, AvailableLanguage.default_locale
26
35
 
27
36
  def destruction_job
28
37
  Delayed::Job.find_by_queue("user_#{id}_destroy")
@@ -55,7 +64,8 @@ class User < ActiveRecord::Base
55
64
  :locale => locale
56
65
  })
57
66
  user.skip_confirmation!
58
- user.save
67
+ user.save(:validate => false)
68
+ user.delay(:run_at => DateTime.now + IuguSDK::destroy_guest_in, :queue => "guest_#{user.id}").destroy
59
69
  user
60
70
  end
61
71
 
@@ -67,6 +77,9 @@ class User < ActiveRecord::Base
67
77
  return false if !User.where(:email => auth["extra"]["raw_info"]["email"]).empty?
68
78
  user.email = auth["extra"]["raw_info"]["email"]
69
79
  end
80
+ user.birthdate = Date.strptime(auth["extra"]["raw_info"]["birthday"], '%m/%d/%Y') if auth["extra"]["raw_info"]["birthday"]
81
+ user.locale = AvailableLanguage.best_locale_for(auth["extra"]["raw_info"]["locale"]) if auth["extra"]["raw_info"]["locale"]
82
+ user.locale = AvailableLanguage.best_locale_for(auth["extra"]["raw_info"]["lang"]) if auth["extra"]["raw_info"]["lang"]
70
83
  user.skip_confirmation!
71
84
  user.save(:validate => false)
72
85
  social_account = user.create_social(auth)
@@ -101,12 +114,40 @@ class User < ActiveRecord::Base
101
114
  self.accounts.where( [ "accounts.id = ?", account_id] ).first || self.accounts.first
102
115
  end
103
116
 
117
+ def become_user(data)
118
+ if self.guest
119
+ self.guest = false
120
+ self.email = data[:email]
121
+ self.password = data[:password]
122
+ self.password_confirmation = data[:password_confirmation]
123
+ if self.save
124
+ Delayed::Job.find_by_queue("guest_#{id}").destroy
125
+ self
126
+ else
127
+ self.guest = true
128
+ false
129
+ end
130
+ else
131
+ false
132
+ end
133
+ end
134
+
104
135
  private
105
136
 
137
+ def destroy_private_accounts
138
+ self.accounts.each do |acc|
139
+ acc.destroy if acc.account_users.count <= 1
140
+ end
141
+ end
142
+
106
143
  def email_required?
107
144
  !(has_social? || guest?)
108
145
  end
109
146
 
147
+ def send_welcome_mail
148
+ IuguMailer.welcome(self).deliver
149
+ end
150
+
110
151
 
111
152
  #def self.reconfirmable
112
153
  # true
@@ -116,7 +157,7 @@ class User < ActiveRecord::Base
116
157
 
117
158
  def create_account_for_user
118
159
  if accountable?
119
- new_account = Account.create({})
160
+ new_account = Account.create( :subdomain => account_alias )
120
161
  account_user = new_account.account_users.create( { :user => self } )
121
162
  end
122
163
  end
@@ -23,7 +23,7 @@ class UserInvitation < ActiveRecord::Base
23
23
  def accept(user)
24
24
  account = Account.find(account_id)
25
25
  if account.account_users.where(:user_id => user.id).empty?
26
- account.account_users << account_user = AccountUser.create(:user_id => user.id)
26
+ account.account_users << account_user = AccountUser.create(:user => user)
27
27
  account_user.set_roles(roles.split(',')) if roles
28
28
  true
29
29
  else
@@ -1,7 +1,9 @@
1
1
  %h2
2
2
  = I18n.t("iugu.account_domains") + " (##{@account.id})"
3
+ - if flash[:group] == :account_domain
4
+ = flash[:notice]
3
5
 
4
- - if IuguSDK::enable_subdomain == true
6
+ - if IuguSDK::enable_account_alias == true
5
7
  %div
6
8
  = simple_form_for @account, :url => update_subdomain_path(:id => @account.id), :method => :put do |f|
7
9
  - if @account.errors.any?
@@ -4,14 +4,14 @@
4
4
  - APP_ROLES['roles'].each do |role|
5
5
  %div
6
6
  = check_box_tag "roles[]", role, @account_user.is?(role), :id => "#{role}_checkbox"
7
- = label_tag "#{role}_checkbox", role
7
+ = label_tag "#{role}_checkbox", I18n.t("iugu.#{role}")
8
8
 
9
9
  - elsif current_user.is?(:admin, @account)
10
10
  - APP_ROLES['roles'].each do |role|
11
11
  - unless role == APP_ROLES['owner_role'] || role == APP_ROLES['admin_role']
12
12
  %div
13
13
  = check_box_tag "roles[]", role, @account_user.is?(role), :id => "#{role}_checkbox"
14
- = label_tag "#{role}_checkbox", role
14
+ = label_tag "#{role}_checkbox", I18n.t("iugu.#{role}")
15
15
 
16
16
  %div
17
17
  = submit_tag I18n.t("iugu.save")
@@ -2,7 +2,10 @@
2
2
 
3
3
  - @account_users.each do |account_user|
4
4
  %div
5
- = account_user.user.name || account_user.user.email
5
+ - if account_user.user.name.blank?
6
+ = account_user.user.email
7
+ - else
8
+ = account_user.user.name
6
9
  - if current_user.is?(:owner, @account) || current_user.is?(:admin, @account)
7
10
  |
8
11
  = link_to I18n.t("iugu.permissions"), account_roles_edit_path(:id => @account.id, :user_id => account_user.user_id)
@@ -1,8 +1,9 @@
1
- %h2 Resend confirmation instructions
1
+ %h2
2
+ = I18n.t("iugu.resend_confirmation_instructions")
2
3
  = simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f|
3
4
  = f.error_notification
4
5
  .inputs
5
6
  = f.input :email, :required => true
6
7
  .actions
7
- = f.button :submit, "Resend confirmation instructions"
8
+ = f.button :submit, I18n.t("iugu.resend_confirmation_instructions")
8
9
  = render :partial => "devise/shared/links"
@@ -13,14 +13,14 @@
13
13
  - APP_ROLES['roles'].each do |role|
14
14
  %div
15
15
  = check_box_tag "user_invitation[roles][]", role, false, :id => "#{role}_checkbox"
16
- = label_tag "#{role}_checkbox", role
16
+ = label_tag "#{role}_checkbox", I18n.t("iugu.#{role}")
17
17
 
18
- - if current_user.is?(:admin, @account)
18
+ - elsif current_user.is?(:admin, @account)
19
19
  - APP_ROLES['roles'].each do |role|
20
20
  - unless role == APP_ROLES['owner_role'] || role == APP_ROLES['admin_role']
21
21
  %div
22
22
  = check_box_tag "user_invitation[roles][]", role, false, :id => "#{role}_checkbox"
23
- = label_tag "#{role}_checkbox", role
23
+ = label_tag "#{role}_checkbox", I18n.t("iugu.#{role}")
24
24
 
25
25
  %div
26
26
  = f.submit I18n.t("iugu.invite")