-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add shop registration * Update version * Update controller template * Update engine.rb * Fix some offenses * Update error handling in authentications controller. Rename files * Delete unused files. Update install generator * Add mounting_path config * Rename functions and variables * Fix rubocop offenses * Fix rubocop offenses * Fix rubocop offenses * Fix rubocop todo
- Loading branch information
Showing
28 changed files
with
647 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/controllers/beyond_canvas/authentications_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require_dependency 'beyond_canvas/application_controller' | ||
|
||
module BeyondCanvas | ||
class AuthenticationsController < ApplicationController # :nodoc: | ||
layout 'beyond_canvas/public' | ||
|
||
include ::BeyondCanvas::Authentication | ||
include ::BeyondCanvas::ResourceManagement | ||
|
||
before_action :validate_app_installation_request!, only: :new | ||
|
||
def new | ||
self.resource = resource_class.new | ||
end | ||
|
||
def create | ||
# Search for the api url. If there is no record it creates a new record. | ||
resource_params = new_resource_params | ||
self.resource = resource_class.find_or_create_by(beyond_api_url: resource_params[:api_url]) | ||
# Assign the attributes to the record | ||
raise ActiveRecord::RecordNotSaved unless resource.update(resource_params) | ||
# Get and save access_token and refresh_token using the authentication code | ||
raise BeyondApi::Error if resource.authenticate.is_a?(BeyondApi::Error) | ||
|
||
redirect_to after_create_path | ||
rescue ActiveRecord::RecordNotSaved, BeyondApi::Error, StandardError => e | ||
logger.error "[BeyondCanvas] #{e.message}".red | ||
send "handle_#{e.class.name.split('::').first.underscore}_exception", e | ||
end | ||
|
||
def update | ||
create | ||
end | ||
|
||
private | ||
|
||
def new_resource_params | ||
send "new_#{resource_name}_params" | ||
end | ||
|
||
def after_create_path | ||
new_resource_params[:return_url] | ||
end | ||
|
||
def handle_active_record_exception(_exception) | ||
flash[:error] = t('beyond_canvas.authentications.failure') | ||
render :new | ||
end | ||
|
||
def handle_beyond_api_exception(_exception) | ||
flash[:error] = t('beyond_canvas.authentications.failure') | ||
render :new | ||
end | ||
|
||
def handle_standard_error_exception(_exception) | ||
flash[:error] = t('beyond_canvas.authentications.failure') | ||
render :new | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module BeyondCanvas | ||
module Authentication # :nodoc: | ||
extend ActiveSupport::Concern | ||
AUTH_RESOURCE = BeyondCanvas.auth_model | ||
|
||
class_eval <<-METHODS, __FILE__, __LINE__ + 1 | ||
def current_#{AUTH_RESOURCE} | ||
instance_variable_get("@#{AUTH_RESOURCE}") | ||
end | ||
def new_#{AUTH_RESOURCE}_params | ||
beyond_canvas_parameter_sanitizer.sanitize | ||
end | ||
METHODS | ||
|
||
private | ||
|
||
def beyond_canvas_parameter_sanitizer | ||
@beyond_canvas_parameter_sanitizer ||= BeyondCanvas::ParameterSanitizer.new(AUTH_RESOURCE, params) | ||
end | ||
end | ||
end |
33 changes: 33 additions & 0 deletions
33
app/controllers/concerns/beyond_canvas/resource_management.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module BeyondCanvas | ||
module ResourceManagement # :nodoc: | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# Share some methods defined in the controller to make them available for the view | ||
if respond_to?(:helper_method) | ||
helpers = %w[resource resource_name resource_class] | ||
helper_method(*helpers) | ||
end | ||
end | ||
|
||
protected | ||
|
||
def resource_name | ||
BeyondCanvas.auth_model | ||
end | ||
|
||
def resource | ||
instance_variable_get(:"@#{resource_name}") | ||
end | ||
|
||
def resource=(new_resource) | ||
instance_variable_set(:"@#{resource_name}", new_resource) | ||
end | ||
|
||
def resource_class | ||
resource_name.classify.constantize | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class='card card--padding'> | ||
|
||
<%= form_for(resource, as: resource_name) do |f| %> | ||
|
||
<h2 class='card__headline'>Install <%= BeyondCanvas.configuration.site_title %> in your shop</h2> | ||
|
||
<%= f.hidden_field :code, value: params[:code] || resource.code %> | ||
<%= f.hidden_field :signature, value: params[:signature] || resource.signature %> | ||
<%= f.hidden_field :return_url, value: params[:return_url] || resource.return_url %> | ||
<%= f.hidden_field :api_url, value: params[:api_url] || resource.api_url %> | ||
<%= f.hidden_field :access_token_url, value: params[:access_token_url] || resource.access_token_url %> | ||
|
||
<div class='form__actions--spaced'> | ||
<%= f.button 'Save', type: :submit, class: 'button__solid--primary' %> | ||
</div> | ||
|
||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
en: | ||
beyond_canvas: | ||
authentications: | ||
failure: Shop could not be saved |
Oops, something went wrong.