better signature validation
This commit is contained in:
@@ -10,10 +10,21 @@ module Api
|
|||||||
def create
|
def create
|
||||||
submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
||||||
|
|
||||||
if params[:type].in?(%w[initials signature]) && ImageUtils.blank?(Vips::Image.new_from_file(params[:file].path))
|
if params[:type].in?(%w[initials signature])
|
||||||
Rollbar.error("Empty signature: #{submitter.id}") if defined?(Rollbar)
|
image = Vips::Image.new_from_file(params[:file].path)
|
||||||
|
|
||||||
return render json: { error: "#{params[:type]} is empty" }, status: :unprocessable_entity
|
if ImageUtils.blank?(image)
|
||||||
|
Rollbar.error("Empty signature: #{submitter.id}") if defined?(Rollbar)
|
||||||
|
|
||||||
|
return render json: { error: "#{params[:type]} is empty" }, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
|
if ImageUtils.error?(image)
|
||||||
|
Rollbar.error("Error signature: #{submitter.id}") if defined?(Rollbar)
|
||||||
|
|
||||||
|
return render json: { error: "#{params[:type]} error, try to sign on another device" },
|
||||||
|
status: :unprocessable_entity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attachment = Submitters.create_attachment!(submitter, params)
|
attachment = Submitters.create_attachment!(submitter, params)
|
||||||
|
|||||||
@@ -14,4 +14,12 @@ module ImageUtils
|
|||||||
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def error?(image)
|
||||||
|
image = image.crop(0, 0, image.width / 4, 2)
|
||||||
|
|
||||||
|
row1, row2 = image.to_a
|
||||||
|
|
||||||
|
row1[3..] == row2[..-4] && row1.each_cons(2).none? { |a, b| a == b }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user