iugusdk 1.0.0.alpha.21 → 1.0.0.alpha.22
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.
- data/app/assets/stylesheets/iugu-sdk.css.sass +9 -1
- data/app/assets/stylesheets/settings.sass +13 -1
- data/app/controllers/iugu/account_controller.rb +58 -8
- data/app/controllers/iugu/invitations_controller.rb +5 -7
- data/app/controllers/iugu/plan_controller.rb +4 -3
- data/app/controllers/iugu/pricing_controller.rb +1 -1
- data/app/controllers/iugu/registrations_controller.rb +8 -1
- data/app/controllers/iugu/sessions_controller.rb +10 -2
- data/app/mailers/iugu_mailer.rb +4 -4
- data/app/models/account.rb +37 -0
- data/app/models/user.rb +24 -9
- data/app/models/user_invitation.rb +2 -0
- data/app/views/iugu/account/payment_history.html.haml +10 -2
- data/app/views/iugu/account_domains/index.html.haml +49 -31
- data/app/views/iugu/account_domains/instructions.html.haml +24 -5
- data/app/views/iugu/account_roles/edit.html.haml +22 -10
- data/app/views/iugu/account_users/index.html.haml +33 -20
- data/app/views/iugu/invitations/edit.html.haml +6 -1
- data/app/views/iugu/invitations/new.html.haml +21 -15
- data/app/views/iugu/plan/index.html.haml +14 -7
- data/app/views/iugu/registrations/new.html.haml +2 -0
- data/app/views/iugu/sessions/new.html.haml +2 -0
- data/app/views/iugu/settings/account.html.haml +61 -29
- data/app/views/iugu/settings/accounts.html.haml +21 -25
- data/config/locales/iugu.en.yml +20 -0
- data/config/locales/iugu.pt-BR.yml +21 -1
- data/config/routes.rb +3 -0
- data/db/migrate/20130723173704_add_used_to_user_invitation.rb +5 -0
- data/lib/iugusdk/version.rb +1 -1
- data/lib/iugusdk.rb +1 -1
- metadata +99 -87
| @@ -88,7 +88,7 @@ | |
| 88 88 | 
             
                    float: none
         | 
| 89 89 | 
             
                    display: inline
         | 
| 90 90 | 
             
                    text-decoration: underline
         | 
| 91 | 
            -
                     | 
| 91 | 
            +
                    font-weight: bold
         | 
| 92 92 |  | 
| 93 93 | 
             
                .text
         | 
| 94 94 | 
             
                  display: block
         | 
| @@ -141,6 +141,14 @@ | |
| 141 141 | 
             
                .tabbed .container
         | 
| 142 142 | 
             
                  overflow: hidden
         | 
| 143 143 |  | 
| 144 | 
            +
            .form_no_margin_bottom
         | 
| 145 | 
            +
              form
         | 
| 146 | 
            +
                margin-bottom: 20px
         | 
| 147 | 
            +
             | 
| 148 | 
            +
            .plan
         | 
| 149 | 
            +
              td
         | 
| 150 | 
            +
                line-height: 44px
         | 
| 151 | 
            +
             | 
| 144 152 | 
             
            @include for-small-screens(390px)
         | 
| 145 153 | 
             
              .iugu-ui,.iugu-ui.settings
         | 
| 146 154 | 
             
                .wrapper
         | 
| @@ -1,3 +1,6 @@ | |
| 1 | 
            +
            @import "iugu-ux/core"
         | 
| 2 | 
            +
            @import "compass/utilities/general/clearfix"
         | 
| 3 | 
            +
             | 
| 1 4 | 
             
            .container
         | 
| 2 5 | 
             
              .header
         | 
| 3 6 | 
             
                position: relative
         | 
| @@ -9,4 +12,13 @@ | |
| 9 12 | 
             
                  position: absolute
         | 
| 10 13 | 
             
                  top: 18px
         | 
| 11 14 | 
             
                  right: 18px
         | 
| 12 | 
            -
                  width:  | 
| 15 | 
            +
                  width: 180px
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            @include for-small-screens(390px)
         | 
| 18 | 
            +
              .container
         | 
| 19 | 
            +
                .header
         | 
| 20 | 
            +
                  #btn-settings-back
         | 
| 21 | 
            +
                    display: block
         | 
| 22 | 
            +
                    width: 100%
         | 
| 23 | 
            +
                    top: -53px
         | 
| 24 | 
            +
                    left: 0px
         | 
| @@ -4,6 +4,7 @@ class Iugu::AccountController < Iugu::AccountSettingsController | |
| 4 4 | 
             
              before_filter(:only => [:generate_new_token]) { |c| c.must_be :owner, :account_id }
         | 
| 5 5 |  | 
| 6 6 | 
             
              def index
         | 
| 7 | 
            +
                @accounts = current_user.accounts.order(:created_at)
         | 
| 7 8 | 
             
                render 'iugu/settings/accounts'
         | 
| 8 9 | 
             
              end
         | 
| 9 10 |  | 
| @@ -13,10 +14,16 @@ class Iugu::AccountController < Iugu::AccountSettingsController | |
| 13 14 | 
             
                else
         | 
| 14 15 | 
             
                  @account = current_user_account.account
         | 
| 15 16 | 
             
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                @has_subscription = false
         | 
| 19 | 
            +
             | 
| 16 20 | 
             
                if IuguSDK::enable_subscription_features
         | 
| 17 | 
            -
                   | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 21 | 
            +
                  unless @account.subscription_id.blank?
         | 
| 22 | 
            +
                    @has_subscription = true
         | 
| 23 | 
            +
                    @subscription = @account.subscription
         | 
| 24 | 
            +
                    plan = Iugu::Api::Plan.find_by_identifier @subscription.plan_identifier
         | 
| 25 | 
            +
                    @plan_name = plan.try :name
         | 
| 26 | 
            +
                  end
         | 
| 20 27 | 
             
                end
         | 
| 21 28 | 
             
                @primary_domain = @account.account_domains.where(:primary => true).first if @account
         | 
| 22 29 | 
             
                render 'iugu/settings/account'
         | 
| @@ -54,7 +61,13 @@ class Iugu::AccountController < Iugu::AccountSettingsController | |
| 54 61 | 
             
              end
         | 
| 55 62 |  | 
| 56 63 | 
             
              def create
         | 
| 57 | 
            -
                 | 
| 64 | 
            +
                create_parameters = {}
         | 
| 65 | 
            +
                if IuguSDK::enable_subscription_features
         | 
| 66 | 
            +
                  plan_identifier = params[:plan] || IuguSDK::default_subscription_name
         | 
| 67 | 
            +
                  currency = locale_to_currency I18n.locale
         | 
| 68 | 
            +
                  create_parameters = {plan_identifier: plan_identifier, currency: currency, email: current_user.email}
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
                current_user.accounts << Account.create(create_parameters)
         | 
| 58 71 | 
             
                redirect_to account_settings_path
         | 
| 59 72 | 
             
              end
         | 
| 60 73 |  | 
| @@ -72,22 +85,59 @@ class Iugu::AccountController < Iugu::AccountSettingsController | |
| 72 85 | 
             
                else
         | 
| 73 86 | 
             
                  raise ActionController::RoutingError.new('Not found')
         | 
| 74 87 | 
             
                end
         | 
| 88 | 
            +
              end
         | 
| 75 89 |  | 
| 90 | 
            +
              def remove_token
         | 
| 91 | 
            +
                if IuguSDK::enable_account_api
         | 
| 92 | 
            +
                  account = current_user.accounts.find params[:account_id]
         | 
| 93 | 
            +
                  token = account.tokens.find params[:token] 
         | 
| 94 | 
            +
                  if token.destroy
         | 
| 95 | 
            +
                    notice = I18n.t("iugu.notices.token_removed")
         | 
| 96 | 
            +
                  else
         | 
| 97 | 
            +
                    notice = token.errors.full_messages
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
                  flash[:group] = :api_token
         | 
| 100 | 
            +
                  redirect_to account_view_path(params[:account_id]), :notice => notice
         | 
| 101 | 
            +
                else
         | 
| 102 | 
            +
                  raise ActionController::RoutingError.new('Not found')
         | 
| 103 | 
            +
                end
         | 
| 76 104 | 
             
              end
         | 
| 77 105 |  | 
| 78 106 | 
             
              def payment_history
         | 
| 79 107 | 
             
                get_account
         | 
| 80 | 
            -
                subscription = Iugu::Api::Subscription.find @account.subscription_id
         | 
| 108 | 
            +
                subscription = Iugu::Api::Subscription.find @account.subscription_id.to_uuid.to_s
         | 
| 81 109 | 
             
                customer = Iugu::Api::Customer.find subscription.customer_id
         | 
| 82 | 
            -
                @invoices = customer. | 
| 110 | 
            +
                @invoices = Iugu::Api::Invoice.find :all, params: {hl: current_user.locale, customer_id: customer.id.to_param, status_filter: ["pending", "paid"], limit: 10}
         | 
| 83 111 | 
             
                render 'iugu/account/payment_history'
         | 
| 84 112 | 
             
              end
         | 
| 85 113 |  | 
| 114 | 
            +
              def activate
         | 
| 115 | 
            +
                get_account
         | 
| 116 | 
            +
                if @account.subscription.try :activate 
         | 
| 117 | 
            +
                  notice = I18n.t("iugu.notices.account_activated")
         | 
| 118 | 
            +
                  @account.clear_cached_subscription_active
         | 
| 119 | 
            +
                else
         | 
| 120 | 
            +
                  notice = I18n.t("iugu.notices.error_activating_account")
         | 
| 121 | 
            +
                end
         | 
| 122 | 
            +
                redirect_to account_view_path(params[:account_id]), :notice => notice
         | 
| 123 | 
            +
              end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
              def suspend
         | 
| 126 | 
            +
                get_account
         | 
| 127 | 
            +
                if @account.subscription.try :suspend 
         | 
| 128 | 
            +
                  notice = I18n.t("iugu.notices.account_suspended")
         | 
| 129 | 
            +
                  @account.clear_cached_subscription_active
         | 
| 130 | 
            +
                else
         | 
| 131 | 
            +
                  notice = I18n.t("iugu.notices.error_suspending_account")
         | 
| 132 | 
            +
                end
         | 
| 133 | 
            +
                redirect_to account_view_path(params[:account_id]), :notice => notice
         | 
| 134 | 
            +
              end
         | 
| 135 | 
            +
             | 
| 86 136 | 
             
              private
         | 
| 87 137 |  | 
| 88 138 | 
             
              def get_account
         | 
| 89 | 
            -
                if params[: | 
| 90 | 
            -
                  @account = current_user.accounts.find(params[: | 
| 139 | 
            +
                if params[:account_id]
         | 
| 140 | 
            +
                  @account = current_user.accounts.find(params[:account_id])
         | 
| 91 141 | 
             
                else
         | 
| 92 142 | 
             
                  @account = current_user_account.account
         | 
| 93 143 | 
             
                end
         | 
| @@ -1,6 +1,8 @@ | |
| 1 1 | 
             
            class Iugu::InvitationsController < Iugu::SettingsController
         | 
| 2 2 |  | 
| 3 | 
            +
              skip_before_filter :authenticate_user!, :only => :edit
         | 
| 3 4 | 
             
              before_filter(:only => [:new, :create]) { |c| c.must_be [:owner, :admin], :account_id } 
         | 
| 5 | 
            +
              after_filter :select_account, :only => [:update]
         | 
| 4 6 |  | 
| 5 7 | 
             
              def new
         | 
| 6 8 | 
             
                @user_invitation = UserInvitation.new
         | 
| @@ -21,17 +23,14 @@ class Iugu::InvitationsController < Iugu::SettingsController | |
| 21 23 | 
             
              end
         | 
| 22 24 |  | 
| 23 25 | 
             
              def edit
         | 
| 24 | 
            -
                 | 
| 25 | 
            -
             | 
| 26 | 
            -
                else
         | 
| 27 | 
            -
                  raise ActionController::RoutingError.new('Not Found')
         | 
| 28 | 
            -
                end
         | 
| 26 | 
            +
                raise ActionController::RoutingError.new('Not Found') unless @user_invitation = UserInvitation.find_by_invitation_token(params[:invitation_token])
         | 
| 27 | 
            +
                @inviter = User.find(@user_invitation.invited_by)
         | 
| 29 28 | 
             
              end
         | 
| 30 29 |  | 
| 31 30 | 
             
              def update
         | 
| 32 31 | 
             
                if @user_invitation = UserInvitation.find_by_invitation_token(params[:invitation_token])
         | 
| 33 32 | 
             
                  if @user_invitation.accept(current_user)
         | 
| 34 | 
            -
                    redirect_to  | 
| 33 | 
            +
                    redirect_to IuguSDK::app_main_url
         | 
| 35 34 | 
             
                  else
         | 
| 36 35 | 
             
                    redirect_to root_path, :notice => I18n.t("iugu.notices.you_are_already_member_of_this_account")
         | 
| 37 36 | 
             
                  end
         | 
| @@ -39,5 +38,4 @@ class Iugu::InvitationsController < Iugu::SettingsController | |
| 39 38 | 
             
                  raise ActionController::RoutingError.new('Not Found')
         | 
| 40 39 | 
             
                end
         | 
| 41 40 | 
             
              end
         | 
| 42 | 
            -
             | 
| 43 41 | 
             
            end
         | 
| @@ -9,8 +9,8 @@ class Iugu::PlanController < Iugu::AccountSettingsController | |
| 9 9 | 
             
                return unless params[:plan]
         | 
| 10 10 | 
             
                params[:id] ? @account = current_user.accounts.find(params[:id]) : @account = current_user_account.account
         | 
| 11 11 |  | 
| 12 | 
            -
                subscription = Iugu::Api::Subscription.find @account.subscription_id
         | 
| 13 | 
            -
                subscription.change_plan params[:plan]
         | 
| 12 | 
            +
                subscription = Iugu::Api::Subscription.find @account.subscription_id.to_uuid.to_s
         | 
| 13 | 
            +
                @account.clear_cached_subscription_features if subscription.change_plan params[:plan]
         | 
| 14 14 |  | 
| 15 15 | 
             
                get_index_data
         | 
| 16 16 | 
             
                render 'iugu/plan/index'
         | 
| @@ -21,6 +21,7 @@ class Iugu::PlanController < Iugu::AccountSettingsController | |
| 21 21 | 
             
              def get_index_data
         | 
| 22 22 | 
             
                @currency = locale_to_currency I18n.locale
         | 
| 23 23 | 
             
                @plans = Iugu::Api::Plan.with_currency @currency
         | 
| 24 | 
            -
             | 
| 24 | 
            +
             | 
| 25 | 
            +
                @subscription = Iugu::Api::Subscription.find @account.subscription_id.to_uuid.to_s
         | 
| 25 26 | 
             
              end
         | 
| 26 27 | 
             
            end
         | 
| @@ -17,6 +17,10 @@ class Iugu::RegistrationsController < Devise::RegistrationsController | |
| 17 17 | 
             
              end
         | 
| 18 18 |  | 
| 19 19 | 
             
              def create
         | 
| 20 | 
            +
                if !params[:user][:user_invitation].blank? 
         | 
| 21 | 
            +
                  invite = UserInvitation.find_by_invitation_token(params[:user][:user_invitation])
         | 
| 22 | 
            +
                  return invalid_invitation if !invite or invite.try(:used)
         | 
| 23 | 
            +
                end
         | 
| 20 24 | 
             
                params[:user][:locale] = @matched_locale_from_browser unless params[:user][:locale]
         | 
| 21 25 | 
             
                super
         | 
| 22 26 | 
             
              end
         | 
| @@ -29,7 +33,6 @@ class Iugu::RegistrationsController < Devise::RegistrationsController | |
| 29 33 | 
             
                  select_account
         | 
| 30 34 | 
             
                  flash[:notice] = I18n.t("iugu.notices.guest_login")
         | 
| 31 35 | 
             
                  redirect_to IuguSDK::app_main_url
         | 
| 32 | 
            -
                  #respond_with @user, :location => sign_up_path_for(@user)
         | 
| 33 36 | 
             
                else
         | 
| 34 37 | 
             
                  raise ActionController::RoutingError.new("Not found")
         | 
| 35 38 | 
             
                end
         | 
| @@ -41,6 +44,10 @@ class Iugu::RegistrationsController < Devise::RegistrationsController | |
| 41 44 |  | 
| 42 45 | 
             
              private
         | 
| 43 46 |  | 
| 47 | 
            +
              def invalid_invitation
         | 
| 48 | 
            +
                redirect_to new_user_registration_path
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 44 51 | 
             
              def verify_private_api_secret
         | 
| 45 52 | 
             
                if request.format.json?
         | 
| 46 53 | 
             
                  render :json=>{:errors=>"Unauthorized"}, :status=>401 unless params[:private_api_secret] == IuguSDK::private_api_secret 
         | 
| @@ -1,13 +1,21 @@ | |
| 1 1 | 
             
            class Iugu::SessionsController < Devise::SessionsController
         | 
| 2 2 | 
             
              after_filter :select_account, :only => :create 
         | 
| 3 3 |  | 
| 4 | 
            +
              layout IuguSDK.alternative_layout
         | 
| 5 | 
            +
             | 
| 4 6 | 
             
              def after_sign_in_path_for(resource_or_scope)
         | 
| 5 | 
            -
                 | 
| 7 | 
            +
                puts params
         | 
| 8 | 
            +
                params[:user].try(:[], :user_invitation).blank? ? IuguSDK::app_main_url : invitation_url
         | 
| 6 9 | 
             
              end
         | 
| 7 10 |  | 
| 8 11 | 
             
              def after_sign_out_path_for(resource_or_scope)
         | 
| 9 12 | 
             
                IuguSDK::app_root_url
         | 
| 10 13 | 
             
              end
         | 
| 11 14 |  | 
| 12 | 
            -
               | 
| 15 | 
            +
              private
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              def invitation_url
         | 
| 18 | 
            +
                edit_invite_url(:invitation_token => params[:user][:user_invitation])
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 13 21 | 
             
            end
         | 
    
        data/app/mailers/iugu_mailer.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            class IuguMailer < Devise::Mailer
         | 
| 2 2 |  | 
| 3 | 
            -
              default from: " | 
| 4 | 
            -
                      reply_to: " | 
| 3 | 
            +
              default from: "Iugu <no-reply@iugu.com>",
         | 
| 4 | 
            +
                      reply_to: "Iugu <no-reply@iugu.com>"
         | 
| 5 5 |  | 
| 6 6 | 
             
              def template_paths
         | 
| 7 7 | 
             
                "iugu/mailer"
         | 
| @@ -17,7 +17,7 @@ class IuguMailer < Devise::Mailer | |
| 17 17 | 
             
                user = User.find(user_invitation.invited_by)
         | 
| 18 18 | 
             
                set_locale(user)
         | 
| 19 19 | 
             
                @user_invitation = user_invitation
         | 
| 20 | 
            -
                mail(to: @user_invitation.email, :subject => I18n.t("user_invitation")) do |format|
         | 
| 20 | 
            +
                mail(to: @user_invitation.email, :subject => I18n.t("user_invitation", account_name: @user_invitation.account.try(:name))) do |format|
         | 
| 21 21 | 
             
                  format.html { render "iugu/mailer/invitation" }
         | 
| 22 22 | 
             
                end
         | 
| 23 23 | 
             
                set_default_locale
         | 
| @@ -26,7 +26,7 @@ class IuguMailer < Devise::Mailer | |
| 26 26 | 
             
              def welcome(user)
         | 
| 27 27 | 
             
                set_locale(user)
         | 
| 28 28 | 
             
                @user = user
         | 
| 29 | 
            -
                mail(to: @user.email, :subject => I18n.t("user_welcome")) do |format|
         | 
| 29 | 
            +
                mail(to: @user.email, :subject => I18n.t("user_welcome", application_title: IuguSDK::application_title)) do |format|
         | 
| 30 30 | 
             
                  format.html { render "iugu/mailer/welcome" }
         | 
| 31 31 | 
             
                end
         | 
| 32 32 | 
             
                set_default_locale
         | 
    
        data/app/models/account.rb
    CHANGED
    
    | @@ -53,6 +53,43 @@ class Account < ActiveRecord::Base | |
| 53 53 | 
             
              def name
         | 
| 54 54 | 
             
                (super.blank? ? "#{I18n.t('iugu.account')} ##{id}" : super)
         | 
| 55 55 | 
             
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              def subscription
         | 
| 58 | 
            +
                return nil unless subscription_id
         | 
| 59 | 
            +
                Iugu::Api::Subscription.find subscription_id.to_uuid.to_s
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              def cached_subscription_active?
         | 
| 63 | 
            +
                key = [self, "subscription_active?"]
         | 
| 64 | 
            +
                if Rails.cache.exist? key
         | 
| 65 | 
            +
                  Rails.cache.read key
         | 
| 66 | 
            +
                else
         | 
| 67 | 
            +
                  active = subscription_active?
         | 
| 68 | 
            +
                  active ? time = 1.day : time = 5.minutes
         | 
| 69 | 
            +
                  Rails.cache.write key, active, expires_in: time
         | 
| 70 | 
            +
                  active
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              def clear_cached_subscription_active
         | 
| 75 | 
            +
                Rails.cache.delete [self, "subscription_active?"]
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              def cached_subscription_features
         | 
| 79 | 
            +
                Rails.cache.fetch([self, "subscription_features"], expires_in: 1.day) { JSON.parse(subscription_features.to_json) || {} }
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              def clear_cached_subscription_features
         | 
| 83 | 
            +
                Rails.cache.delete [self, "subscription_features"]
         | 
| 84 | 
            +
              end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              def subscription_active?
         | 
| 87 | 
            +
                subscription.try :active 
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              def subscription_features
         | 
| 91 | 
            +
                subscription.try :features
         | 
| 92 | 
            +
              end
         | 
| 56 93 |  | 
| 57 94 | 
             
              private
         | 
| 58 95 |  | 
    
        data/app/models/user.rb
    CHANGED
    
    | @@ -20,11 +20,11 @@ class User < ActiveRecord::Base | |
| 20 20 | 
             
                     :recoverable, :rememberable, :validatable, :omniauthable
         | 
| 21 21 |  | 
| 22 22 | 
             
              # Setup accessible (or protected) attributes for your model
         | 
| 23 | 
            -
              attr_accessible :email, :password, :password_confirmation, :remember_me, :locale, :name, :birthdate, :guest, :account_alias, :plan_identifier, :currency
         | 
| 23 | 
            +
              attr_accessible :email, :password, :password_confirmation, :remember_me, :locale, :name, :birthdate, :guest, :account_alias, :plan_identifier, :currency, :user_invitation
         | 
| 24 24 |  | 
| 25 25 | 
             
              attr_accessor :plan_identifier, :currency
         | 
| 26 26 |  | 
| 27 | 
            -
              mattr_accessor :account_alias
         | 
| 27 | 
            +
              mattr_accessor :account_alias, :user_invitation
         | 
| 28 28 |  | 
| 29 29 | 
             
              before_destroy :destroy_private_accounts
         | 
| 30 30 |  | 
| @@ -32,10 +32,16 @@ class User < ActiveRecord::Base | |
| 32 32 |  | 
| 33 33 | 
             
              after_create :init_token, :if => Proc.new { IuguSDK::enable_user_api }
         | 
| 34 34 |  | 
| 35 | 
            -
              after_create :create_account_for_user
         | 
| 35 | 
            +
              after_create :create_account_for_user, :if => Proc.new { accountable? && !user_invitation }
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              after_create :accept_invitation, :if => Proc.new { |user| !user.user_invitation.blank? }
         | 
| 36 38 |  | 
| 37 39 | 
             
              after_create :send_welcome_mail, :if => Proc.new { |r| IuguSDK::enable_welcome_mail && !r.email.blank? }
         | 
| 38 40 |  | 
| 41 | 
            +
              after_rollback do
         | 
| 42 | 
            +
                Rails.logger.info errors.full_messages
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 39 45 | 
             
              before_save :skip_reconfirmation!, :unless => Proc.new { IuguSDK::enable_email_reconfirmation }
         | 
| 40 46 |  | 
| 41 47 | 
             
              validates :email, :email => true, :unless => :guest?
         | 
| @@ -155,8 +161,20 @@ class User < ActiveRecord::Base | |
| 155 161 |  | 
| 156 162 | 
             
              private
         | 
| 157 163 |  | 
| 164 | 
            +
              def accept_invitation
         | 
| 165 | 
            +
                @invite = UserInvitation.find_by_invitation_token(user_invitation)
         | 
| 166 | 
            +
                @invite.accept(self) if @invite
         | 
| 167 | 
            +
              end
         | 
| 168 | 
            +
             | 
| 158 169 | 
             
              def init_token
         | 
| 159 | 
            -
                 | 
| 170 | 
            +
                for i in 0..256 do
         | 
| 171 | 
            +
                  begin
         | 
| 172 | 
            +
                    self.token = ApiToken.create(tokenable: self, api_type: "USER", description: "User")
         | 
| 173 | 
            +
                    break unless token.nil?
         | 
| 174 | 
            +
                  rescue
         | 
| 175 | 
            +
                    next
         | 
| 176 | 
            +
                  end
         | 
| 177 | 
            +
                end
         | 
| 160 178 | 
             
              end
         | 
| 161 179 |  | 
| 162 180 | 
             
              def destroy_private_accounts
         | 
| @@ -181,11 +199,8 @@ class User < ActiveRecord::Base | |
| 181 199 | 
             
              @reconfirmable = true
         | 
| 182 200 |  | 
| 183 201 | 
             
              def create_account_for_user
         | 
| 184 | 
            -
                 | 
| 185 | 
            -
             | 
| 186 | 
            -
                  account_user = new_account.account_users.create( { :user => self } )
         | 
| 187 | 
            -
                end
         | 
| 202 | 
            +
                new_account = Account.create( :subdomain => account_alias, plan_identifier: plan_identifier, currency: currency, email: email)
         | 
| 203 | 
            +
                account_user = new_account.account_users.create( { :user => self } )
         | 
| 188 204 | 
             
              end
         | 
| 189 205 |  | 
| 190 | 
            -
             | 
| 191 206 | 
             
            end
         | 
| @@ -28,6 +28,8 @@ class UserInvitation < ActiveRecord::Base | |
| 28 28 | 
             
                if account.account_users.where(:user_id => user.id).empty?
         | 
| 29 29 | 
             
                  account_user = account.account_users.create(:user => user)
         | 
| 30 30 | 
             
                  account_user.set_roles(roles.split(',')) if roles
         | 
| 31 | 
            +
                  self.used = true
         | 
| 32 | 
            +
                  save
         | 
| 31 33 | 
             
                  true
         | 
| 32 34 | 
             
                else
         | 
| 33 35 | 
             
                  false
         | 
| @@ -1,13 +1,21 @@ | |
| 1 | 
            +
            %h3
         | 
| 2 | 
            +
              Histórico de Pagamentos
         | 
| 3 | 
            +
             | 
| 1 4 | 
             
            %table
         | 
| 2 5 | 
             
              %tr
         | 
| 3 6 | 
             
                %th ID
         | 
| 4 7 | 
             
                %th Total
         | 
| 8 | 
            +
                %th Vencimento
         | 
| 5 9 | 
             
                %th Status
         | 
| 6 10 | 
             
              - @invoices.each do |invoice|
         | 
| 7 11 | 
             
                %tr
         | 
| 8 12 | 
             
                  %td
         | 
| 9 | 
            -
                    = invoice.id
         | 
| 13 | 
            +
                    = link_to invoice.id[-8,8], invoice.secure_url, :target => "_blank"
         | 
| 10 14 | 
             
                  %td
         | 
| 11 15 | 
             
                    = invoice.total
         | 
| 12 16 | 
             
                  %td
         | 
| 13 | 
            -
                    = invoice. | 
| 17 | 
            +
                    = I18n.l invoice.due_date.to_date, format: :short
         | 
| 18 | 
            +
                  %td
         | 
| 19 | 
            +
                    = I18n.t "invoice_status.#{invoice.status}"
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            = link_to I18n.t("iugu.back"), account_view_path(id: params[:account_id]), class: "button no-bottom-margin"
         | 
| @@ -1,59 +1,77 @@ | |
| 1 1 | 
             
            %h2
         | 
| 2 | 
            -
              = I18n.t("iugu.account_domains") | 
| 2 | 
            +
              = I18n.t("iugu.account_domains")
         | 
| 3 | 
            +
             | 
| 3 4 | 
             
            - if flash[:group] == :account_domain
         | 
| 4 | 
            -
               | 
| 5 | 
            +
              .notice.notice-green
         | 
| 6 | 
            +
                = flash[:notice]
         | 
| 5 7 |  | 
| 6 8 | 
             
            - if IuguSDK::enable_account_alias == true
         | 
| 7 9 | 
             
              %div
         | 
| 8 10 | 
             
                = simple_form_for @account, :url => update_subdomain_path(:id => @account.id), :method => :put do |f|
         | 
| 9 11 | 
             
                  - if @account.errors.any?
         | 
| 10 | 
            -
                     | 
| 12 | 
            +
                    .notice.notice-red
         | 
| 11 13 | 
             
                      %ul
         | 
| 12 14 | 
             
                        - @account.errors.full_messages.each do |msg|
         | 
| 13 15 | 
             
                          %li
         | 
| 14 16 | 
             
                            = msg
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                   | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 17 | 
            +
             | 
| 18 | 
            +
                  .clearfix
         | 
| 19 | 
            +
                    .left{ :style => "width:60%;float:left" }
         | 
| 20 | 
            +
                      = f.label :subdomain, "Subdomínio"
         | 
| 21 | 
            +
                      = f.text_field :subdomain
         | 
| 22 | 
            +
                    .right{ :style => "width:40%;float:right;padding-top:30px" }
         | 
| 23 | 
            +
                      %div{ :style => "padding-left:10px" }
         | 
| 24 | 
            +
                        = "." + IuguSDK::application_main_host
         | 
| 25 | 
            +
                  = f.submit I18n.t("iugu.save"), :class => "button full-width"
         | 
| 19 26 |  | 
| 20 27 | 
             
            - if IuguSDK::enable_custom_domain == true
         | 
| 21 28 |  | 
| 22 29 | 
             
              %div
         | 
| 23 30 | 
             
                = simple_form_for @account_domain, :url => create_domain_path(@account.id) do |f|
         | 
| 31 | 
            +
             | 
| 24 32 | 
             
                  - if @account_domain.errors.any?
         | 
| 25 | 
            -
                     | 
| 33 | 
            +
                    .notice.notice-red{ :style => "margin-bottom: 15px" }
         | 
| 26 34 | 
             
                      %ul
         | 
| 27 35 | 
             
                        - @account_domain.errors.full_messages.each do |msg|
         | 
| 28 36 | 
             
                          %li
         | 
| 29 37 | 
             
                            = msg
         | 
| 30 38 |  | 
| 31 | 
            -
                  = f.text_field :url
         | 
| 32 | 
            -
                  = f.submit I18n.t("iugu.add")
         | 
| 33 | 
            -
              %br
         | 
| 34 | 
            -
              %div
         | 
| 35 | 
            -
                - @account_domains.each do |domain|
         | 
| 36 | 
            -
                  %div
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                    = domain.url
         | 
| 39 | 
            +
                  = f.text_field :url, :placeholder => "Domínio"
         | 
| 40 | 
            +
                  = f.submit I18n.t("iugu.add"), :class => "button full-width no-margin-bottom"
         | 
| 39 41 |  | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
                     | 
| 44 | 
            -
                       | 
| 45 | 
            -
                         | 
| 46 | 
            -
             | 
| 42 | 
            +
              - if @account_domains.count > 0
         | 
| 43 | 
            +
                %table.table
         | 
| 44 | 
            +
                  %thead
         | 
| 45 | 
            +
                    %tr
         | 
| 46 | 
            +
                      %th
         | 
| 47 | 
            +
                        Domínio
         | 
| 48 | 
            +
                      %th
         | 
| 47 49 |  | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 50 | 
            +
                  %tbody
         | 
| 51 | 
            +
                  - @account_domains.each do |domain|
         | 
| 52 | 
            +
                    %tr
         | 
| 53 | 
            +
                      %td{ :style => "text-align:center;width:60%" }
         | 
| 54 | 
            +
                        %h4.no-bottom-margin
         | 
| 55 | 
            +
                          = domain.url
         | 
| 56 | 
            +
                        %div{ :style => "color:#090;text-align:center;font-weight:bold;text-transform:uppercase;font-size:10px" }
         | 
| 57 | 
            +
                          - if domain.primary
         | 
| 58 | 
            +
                            = "#{I18n.t("iugu.primary")}"
         | 
| 53 59 |  | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 60 | 
            +
                          - if domain.verified
         | 
| 61 | 
            +
                            = I18n.t("iugu.verified")
         | 
| 62 | 
            +
                        - unless domain.verified
         | 
| 63 | 
            +
                          %div{ :style => "color:#900;text-align:center;font-weight:bold;text-transform:uppercase;font-size:10px" }
         | 
| 64 | 
            +
                            = I18n.t("iugu.not_verified")
         | 
| 65 | 
            +
                      %td{ :style => "width:40%" }
         | 
| 66 | 
            +
                        .group
         | 
| 67 | 
            +
                          - unless domain.primary
         | 
| 68 | 
            +
                            - if domain.verified
         | 
| 69 | 
            +
                              = link_to I18n.t("iugu.set_primary"), primary_domain_path(:account_id => @account.id, :domain_id => domain.id), :method => :post, :class => "button small"
         | 
| 57 70 |  | 
| 71 | 
            +
                          - unless domain.verified
         | 
| 72 | 
            +
                            = link_to I18n.t("iugu.verify_domain"), account_domains_instructions_path(:account_id => @account.id, :domain_id => domain.id), :class => "button small"
         | 
| 58 73 |  | 
| 74 | 
            +
                          - if current_user.is?(:owner, @account)
         | 
| 75 | 
            +
                            = link_to I18n.t("iugu.remove"), account_domains_destroy_path(:account_id => @account.id, :domain_id => domain.id), :method => :delete, :class => "button small"
         | 
| 59 76 |  | 
| 77 | 
            +
            = link_to I18n.t("iugu.back"), account_view_path(id: params[:account_id]), class: "button no-bottom-margin"
         | 
| @@ -1,7 +1,26 @@ | |
| 1 1 | 
             
            %div
         | 
| 2 | 
            -
               | 
| 3 | 
            -
             | 
| 2 | 
            +
              %h3
         | 
| 3 | 
            +
                Confirmar a propriedade do domínio
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              %table
         | 
| 6 | 
            +
                %tr
         | 
| 7 | 
            +
                  %td{ :style => "text-align:center" }
         | 
| 8 | 
            +
                    = @domain.url
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              %p
         | 
| 11 | 
            +
                Para podermos ativar o domínio no #{IuguSDK::application_title}, precisamos confirmar se você é o proprietário. Fazemos isto por meio da confirmação da propriedade do domínio. Isso protege seu domínio, garantindo que somente sua organização possa ativar o uso em nosso sistema.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              %p
         | 
| 14 | 
            +
                Para confirmar seu domínio, você deve criar um registro CNAME em seu painel de gerenciamento de domínios (Consulte seu provedor de serviços DNS). Adicione uma entrada CNAME com token abaixo:
         | 
| 15 | 
            +
              %table
         | 
| 16 | 
            +
                %tr
         | 
| 17 | 
            +
                  %td{ :style => "text-align:center" }
         | 
| 18 | 
            +
                    = @domain.calculate_token
         | 
| 19 | 
            +
              %p
         | 
| 20 | 
            +
                Após inserir o registro em seu painel. Você pode continuar com a verificação do domínio
         | 
| 21 | 
            +
            %div{ :style => "padding-bottom: 5px" }
         | 
| 22 | 
            +
              = link_to I18n.t("iugu.verify_domain"), verify_domain_path(:account_id => @account.id, :domain_id => @domain.id), :method => :post, :class => "button full-width no-bottom-margin"
         | 
| 4 23 | 
             
            %div
         | 
| 5 | 
            -
              = link_to I18n.t("iugu. | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 24 | 
            +
              = link_to I18n.t("iugu.verify_later"), account_domains_index_path(@account.id), :class => "button full-width"
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            = link_to I18n.t("iugu.back"), account_domains_index_path(id: params[:account_id]), class: "button no-bottom-margin"
         | 
| @@ -1,17 +1,29 @@ | |
| 1 1 | 
             
            = form_tag(account_roles_update_path(@account, :user_id => @account_user.user)) do
         | 
| 2 2 |  | 
| 3 | 
            -
               | 
| 4 | 
            -
                 | 
| 5 | 
            -
                  %div
         | 
| 6 | 
            -
                    = check_box_tag "roles[]", role, @account_user.is?(role), :id => "#{role}_checkbox"
         | 
| 7 | 
            -
                    = label_tag "#{role}_checkbox", I18n.t("iugu.#{role}")
         | 
| 3 | 
            +
              %h3
         | 
| 4 | 
            +
                Permissões
         | 
| 8 5 |  | 
| 9 | 
            -
               | 
| 10 | 
            -
                 | 
| 11 | 
            -
                   | 
| 12 | 
            -
                    % | 
| 6 | 
            +
              %table
         | 
| 7 | 
            +
                %tbody
         | 
| 8 | 
            +
                  %tr
         | 
| 9 | 
            +
                    %td
         | 
| 10 | 
            +
                      = @account_user.user.email
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              %div{ :style => "margin-bottom:20px" }
         | 
| 13 | 
            +
                - if current_user.is?(:owner, @account)
         | 
| 14 | 
            +
                  - APP_ROLES['roles'].each do |role|
         | 
| 15 | 
            +
                    %div{ :style => "margin-bottom: 5px" }
         | 
| 13 16 | 
             
                      = check_box_tag "roles[]", role, @account_user.is?(role), :id => "#{role}_checkbox"
         | 
| 14 17 | 
             
                      = label_tag "#{role}_checkbox", I18n.t("iugu.#{role}")
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                - elsif current_user.is?(:admin, @account)
         | 
| 20 | 
            +
                  - APP_ROLES['roles'].each do |role|
         | 
| 21 | 
            +
                    - unless role == APP_ROLES['owner_role'] || role == APP_ROLES['admin_role']
         | 
| 22 | 
            +
                      %div{ :style => "margin-bottom: 5px" }
         | 
| 23 | 
            +
                        = check_box_tag "roles[]", role, @account_user.is?(role), :id => "#{role}_checkbox"
         | 
| 24 | 
            +
                        = label_tag "#{role}_checkbox", I18n.t("iugu.#{role}")
         | 
| 15 25 |  | 
| 16 26 | 
             
              %div
         | 
| 17 | 
            -
                = submit_tag I18n.t("iugu.save")
         | 
| 27 | 
            +
                = submit_tag I18n.t("iugu.save"), :class => "button full-width"
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            = link_to I18n.t("iugu.back"), account_users_index_path(account_id: params[:id]), class: "button no-bottom-margin"
         |