Class: Spree::Admin::SolidusMe::AccountsController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Admin::SolidusMe::AccountsController
- Defined in:
- app/controller/spree/admin/solidus_me/accounts_controller.rb
Instance Method Summary collapse
- #authorize ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#authorize ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 44 def code = params[:code] me_account = ::SolidusMe::Account.first = MeApi::Client.new.( client_id: me_account.client_id, client_secret: me_account.client_secret, code: code, redirect_url: me_account.redirect_url ).json me_account.update( access_token: ["access_token"], refresh_token: ["refresh_token"], token_expires_in: (DateTime.now + ["expires_in"].seconds).to_s ) redirect_to edit_admin_solidus_me_account_path me_account end |
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 19 def create me_account = ::SolidusMe::Account.new account_params if me_account.save flash[:success] = "Conta criada com sucesso" redirect_to admin_solidus_me_accounts_path else flash[:error] = me_account.errors..join("\n") redirect_to new_admin_solidus_me_account_path end end |
#destroy ⇒ Object
39 40 41 42 |
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 39 def destroy @me_account.delete redirect_to admin_solidus_me_accounts_path end |
#edit ⇒ Object
30 31 |
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 30 def edit end |
#index ⇒ Object
7 8 9 |
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 7 def index @accounts = ::SolidusMe::Account.all end |
#new ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 11 def new if ::SolidusMe::Account.any? flash[:error] = "Você só pode ter uma conta Melhor Envio cadastrada" redirect_to admin_solidus_me_accounts_path end @me_account = ::SolidusMe::Account.new end |
#update ⇒ Object
33 34 35 36 37 |
# File 'app/controller/spree/admin/solidus_me/accounts_controller.rb', line 33 def update @me_account.update account_params flash[:success] = "Conta atualizada com sucesso" redirect_to edit_admin_solidus_me_account_path(@me_account.id) end |