Compare commits

...
Sign in to create a new pull request.

28 commits

Author SHA1 Message Date
spengreb
bb4c4e52c4 Flatten user login json response 2020-04-24 17:10:55 +02:00
spengreb
4e3d8c4d57 Add admin to user 2020-01-12 21:34:05 +01:00
spengreb
685b28714b Readd authorization 2020-01-12 18:59:46 +01:00
conor
afe097aac8 Remove running debug message 2019-10-21 11:25:12 +02:00
conor
dd1a5c6f85 Add whitelist add command 2019-10-21 11:24:16 +02:00
conor
6849e16491 Add extra output 2019-10-21 11:12:32 +02:00
conor
c82d26b905 Change rails executor 2019-10-21 11:10:47 +02:00
conor
7eca69b4a6 Replace mcrcon command with system command 2019-10-21 11:05:59 +02:00
spengreb
e8fb72653d Change how ruby executes commands 2019-10-08 22:35:26 +02:00
spengreb
2981d737a9 Change how ruby executes commands 2019-10-08 22:20:34 +02:00
spengreb
c893e37a65 Change how ruby executes commands 2019-10-08 22:14:42 +02:00
spengreb
f2738686d5 Change how ruby executes commands 2019-10-08 22:07:00 +02:00
spengreb
359656bdd6 Change how ruby executes commands 2019-10-08 21:57:37 +02:00
spengreb
be7a275629 General fixes 2019-10-08 21:54:32 +02:00
spengreb
46f3314738 Add json output of mcrcon from index of vouchers 2019-10-08 21:51:34 +02:00
spengreb
25bd47bf12 Fix color output on mcrcon 2019-10-08 21:49:05 +02:00
spengreb
8861ac7ac0 Fixes for vouchers 2019-10-08 21:47:01 +02:00
spengreb
9f5ee2f9db Types 2019-10-08 20:16:28 +02:00
spengreb
93e1dfb923 Move verbose 2019-10-08 20:15:15 +02:00
spengreb
b544201186 Move verbose 2019-10-08 20:12:26 +02:00
spengreb
7c394d03ef Remove -r flag from mcrcon 2019-10-08 20:10:00 +02:00
spengreb
028007c03a Spit out whitelist 2019-10-08 20:05:07 +02:00
spengreb
2a876d60e6 Remove debug message anyway 2019-10-08 20:00:17 +02:00
spengreb
019521dc38 Ruby is not python 2019-10-08 19:59:28 +02:00
spengreb
1b27ed2f22 Fix voucher not valid error message type 2019-10-08 19:57:48 +02:00
spengreb
52b8bf488b Add assets precompile job 2019-10-07 12:58:56 +02:00
spengreb
c546896dc7 Update cap, rails and ruby version 2019-10-07 12:46:17 +02:00
spengreb
2eaf740299 Update gemlock file 2019-09-30 17:55:11 +02:00
12 changed files with 33 additions and 1893 deletions

1
.gitignore vendored
View file

@ -14,6 +14,7 @@
/test/tmp/ /test/tmp/
/test/version_tmp/ /test/version_tmp/
/tmp/ /tmp/
/log/
# Used by dotenv library to load environment variables. # Used by dotenv library to load environment variables.
# .env # .env

View file

@ -10,7 +10,7 @@ require "capistrano/rbenv"
require "capistrano/bundler" require "capistrano/bundler"
set :rbenv_type, :user set :rbenv_type, :user
set :rbenv_ruby, '2.4.0' set :rbenv_ruby, '2.6.4'
set :ssh_options, {:forward_agent => true} set :ssh_options, {:forward_agent => true}
# Load the SCM plugin appropriate to your project: # Load the SCM plugin appropriate to your project:
# #

View file

@ -25,10 +25,12 @@ gem 'rack-cors', :require => 'rack/cors'
gem 'fast_jsonapi' gem 'fast_jsonapi'
gem 'will_paginate' gem 'will_paginate'
gem 'capistrano', '3.10.1' gem 'capistrano', '3.10.1'
gem 'capistrano-rails', '~> 1.2' gem 'capistrano-rails', '~> 1.4'
gem 'capistrano-passenger', '~> 0.2.0' gem 'capistrano-passenger', '~> 0.2.0'
gem 'capistrano-rbenv' gem 'capistrano-rbenv'
gem 'capistrano-bundler' gem 'capistrano-bundler'
gem 'ed25519'
gem 'bcrypt_pbkdf'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development

View file

@ -59,6 +59,7 @@ GEM
airbrussh (1.3.4) airbrussh (1.3.4)
sshkit (>= 1.6.1, != 1.7.0) sshkit (>= 1.6.1, != 1.7.0)
bcrypt (3.1.13) bcrypt (3.1.13)
bcrypt_pbkdf (1.0.1)
bootsnap (1.4.5) bootsnap (1.4.5)
msgpack (~> 1.0) msgpack (~> 1.0)
builder (3.2.3) builder (3.2.3)
@ -82,6 +83,7 @@ GEM
crass (1.0.4) crass (1.0.4)
database_cleaner (1.7.0) database_cleaner (1.7.0)
diff-lcs (1.3) diff-lcs (1.3)
ed25519 (1.2.4)
erubi (1.9.0) erubi (1.9.0)
factory_girl (4.9.0) factory_girl (4.9.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
@ -206,14 +208,16 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
bcrypt (~> 3.1.7) bcrypt (~> 3.1.7)
bcrypt_pbkdf
bootsnap bootsnap
byebug byebug
capistrano (= 3.10.1) capistrano (= 3.10.1)
capistrano-bundler capistrano-bundler
capistrano-passenger (~> 0.2.0) capistrano-passenger (~> 0.2.0)
capistrano-rails (~> 1.2) capistrano-rails (~> 1.4)
capistrano-rbenv capistrano-rbenv
database_cleaner database_cleaner
ed25519
factory_girl_rails (~> 4.0) factory_girl_rails (~> 4.0)
faker faker
fast_jsonapi fast_jsonapi

View file

@ -5,7 +5,10 @@ class AuthenticationController < ApplicationController
auth_token = auth_token =
AuthenticateUser.new(auth_params[:email], auth_params[:password]).call AuthenticateUser.new(auth_params[:email], auth_params[:password]).call
user = User.find_by(email: auth_params[:email]) user = User.find_by(email: auth_params[:email])
json_response(auth_token: auth_token, user: user)
response = user.as_json
response[:auth_token] = auth_token
json_response(response)
end end
private private

View file

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

View file

@ -10,7 +10,7 @@ require "action_controller/railtie"
require "action_mailer/railtie" require "action_mailer/railtie"
require "action_view/railtie" require "action_view/railtie"
require "action_cable/engine" require "action_cable/engine"
# require "sprockets/railtie" require "sprockets/railtie"
# require "rails/test_unit/railtie" # require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems # Require the gems listed in Gemfile, including any gems

View file

@ -2,7 +2,7 @@
lock "3.10.1" lock "3.10.1"
set :application, "vereto-api" set :application, "vereto-api"
set :repo_url, "git@gogs.vereto.tech:PromoStarr/vereto-api.git" set :repo_url, "https://gitlab.com/spengreb/vereto-api.git"
# Default branch is :master # Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

View file

@ -16,12 +16,8 @@ Rails.application.routes.draw do
resources :users resources :users
# ** TO DO ** # resources :user_profiles
# Pls activate again when you've made this more secure post 'login', to: 'authentication#authenticate'
# I dont think its a good idea to send passwords over plaintext post 'register', to: 'users#create'
# resources :user_profiles
# post 'login', to: 'authentication#authenticate'
# post 'register', to: 'users#create'
# ** TODO ** #
end end

View file

@ -0,0 +1,5 @@
class AddAdminToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :admin, :boolean
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_09_27_154659) do ActiveRecord::Schema.define(version: 2020_01_12_200527) do
create_table "articles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "articles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "title" t.string "title"
@ -48,6 +48,7 @@ ActiveRecord::Schema.define(version: 2019_09_27_154659) do
t.string "password_digest" t.string "password_digest"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.boolean "admin"
end end
create_table "vouchers", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| create_table "vouchers", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|

File diff suppressed because it is too large Load diff