Compare commits

..

No commits in common. "master" and "vouch" have entirely different histories.

12 changed files with 1893 additions and 33 deletions

1
.gitignore vendored
View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +0,0 @@
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.
ActiveRecord::Schema.define(version: 2020_01_12_200527) do
ActiveRecord::Schema.define(version: 2019_09_27_154659) do
create_table "articles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
t.string "title"
@ -48,7 +48,6 @@ ActiveRecord::Schema.define(version: 2020_01_12_200527) do
t.string "password_digest"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "admin"
end
create_table "vouchers", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|

1870
log/development.log Normal file

File diff suppressed because it is too large Load diff