General fixes

This commit is contained in:
spengreb 2019-10-08 21:54:32 +02:00
parent 46f3314738
commit be7a275629
2 changed files with 32 additions and 5 deletions

View file

@ -5,7 +5,7 @@ class VouchersController < ApplicationController
# GET /vouchers
def index
@vouchers = Voucher.all
whitelist = `mcrcon -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} 'whitelist list' | sed 's/There are*.*whitelisted players: //g'`.split(", ")
whitelist = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} 'whitelist list' | sed 's/There are*.*whitelisted players: //g'`.gsub("\n", "").split(", ")
render json: { :vouchers => @vouchers, :whitelist => whitelist }.to_json
end
@ -19,7 +19,7 @@ class VouchersController < ApplicationController
def create
# Logic for creating a voucher
output = ""
whitelist = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist list" | sed 's/There are*.*whitelisted players: //g'`.split(", ")
whitelist = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist list" | sed 's/There are*.*whitelisted players: //g'`.gsub("\n", "").split(", ")
if Voucher.exists?(vouchee: params[:voucher]) && params[:voucher].in?(whitelist)
@voucher = Voucher.new(voucher_params)
@ -35,9 +35,6 @@ class VouchersController < ApplicationController
render json: { :message => "Voucher is not valid.", :whitelisted => params[:voucher].in?(whitelist), :exists => Voucher.exists?(vouchee: params[:voucher]), :list => whitelist }.to_json, status: :unprocessable_entity
end
end
# PATCH/PUT /vouchers/1

View file

@ -2299,3 +2299,33 @@ DEPRECATION WARNING: Uniqueness validator will no longer enforce case sensitive
Completed 422 Unprocessable Entity in 274ms (Views: 0.1ms | ActiveRecord: 2.3ms | Allocations: 182961)
Started GET "/vouchers" for ::1 at 2019-10-08 21:52:20 +0200
 (0.3ms) SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
 (0.3ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC
Processing by VouchersController#index as */*
Voucher Load (0.3ms) SELECT `vouchers`.* FROM `vouchers`
↳ app/controllers/vouchers_controller.rb:10:in `index'
Completed 200 OK in 134ms (Views: 0.1ms | ActiveRecord: 1.0ms | Allocations: 6053)
Started GET "/vouchers" for ::1 at 2019-10-08 21:52:27 +0200
Processing by VouchersController#index as */*
Voucher Load (0.4ms) SELECT `vouchers`.* FROM `vouchers`
↳ app/controllers/vouchers_controller.rb:10:in `index'
Completed 200 OK in 111ms (Views: 0.2ms | ActiveRecord: 1.3ms | Allocations: 5490)
Started GET "/vouchers" for ::1 at 2019-10-08 21:52:51 +0200
Processing by VouchersController#index as */*
Voucher Load (0.3ms) SELECT `vouchers`.* FROM `vouchers`
↳ app/controllers/vouchers_controller.rb:10:in `index'
Completed 200 OK in 130ms (Views: 0.2ms | ActiveRecord: 1.4ms | Allocations: 5528)
Started GET "/vouchers" for ::1 at 2019-10-08 21:53:04 +0200
Processing by VouchersController#index as */*
Voucher Load (0.3ms) SELECT `vouchers`.* FROM `vouchers`
↳ app/controllers/vouchers_controller.rb:10:in `index'
Completed 200 OK in 102ms (Views: 0.1ms | ActiveRecord: 1.1ms | Allocations: 5483)