This repository has been archived on 2025-07-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mopk-dashboard/server.rb

88 lines
2 KiB
Ruby
Raw Normal View History

2019-11-10 20:29:35 +02:00
#!/bin/env ruby
# frozen_string_literal: true
Bundler.require(:default, :development)
require 'slim/include'
2019-11-10 22:18:14 +02:00
require './functions'
2019-11-10 20:29:35 +02:00
use BetterErrors::Middleware
DB = Sequel.connect('sqlite://database.db')
set :port, 8091
2019-11-10 22:18:14 +02:00
set :nav, [
2019-11-10 22:42:28 +02:00
{ title: 'Χρήστες', href: '/users' },
2019-11-10 23:04:38 +02:00
{ title: 'Συνέλευση', href: '/input' },
{ title: 'Ρυθμίσεις', href: '/settings' }
2019-11-10 22:18:14 +02:00
]
get '/users' do
l = {}
l[:users] = DB[:user].all
slim :users, locals: l
end
2019-11-10 22:27:32 +02:00
get '/user' do
l = {}
l[:user] = DB[:user].where(id: params['uid']).first
l[:logs] = DB[:log_entry].where(id: params['uid']).reverse(:timestamp).all
slim :user, locals: l
end
post '/user' do
DB[:user].where(id: params['uid']).update(
name: params['name'],
email: params['email'],
phone: params['phone'],
card_number: params['card-number'],
apousies: params['apousies'],
balance: params['balance'],
telegram_id: params['telegram-id']
)
redirect '/user?uid=' + params['uid']
end
2019-11-10 22:42:28 +02:00
get '/' do
redirect '/input'
end
get '/input' do
l = {}
l[:users] = DB[:user].all
slim :input, locals: l
end
post '/save' do
DB[:log_entry].insert(
timestamp: DateTime.now,
id: params['user'].to_i,
amount_paid: params['amount_paid'].to_f,
amount_donated: params['amount_donated'].to_f,
comments: params['comments'].to_s,
ban: params['ban'] == 'on',
apousia: params['apousia'] == 'on',
asylia: params['asylia'] == 'on',
proedreio: params['proedreio'] == 'on'
)
DB[:user].where(id: params['user']).update(
# TODO: wtf why integer
balance: Sequel[:balance] - params[:amount_paid].to_i,
asylia: params['asylia'] == 'on',
proedreio: params['proedreio'] == 'on',
banned: params['ban'] == 'on',
active: params['ban'] != 'on'
)
redirect '/input'
end
2019-11-10 23:04:38 +02:00
get '/settings' do
l = {}
l[:user_settings] = DB[:settings].first
slim :settings, locals: l
end
post '/settings' do
DB[:settings].update(max_apousies: params['max_apousies'],
prova_cost: params['prova_cost'])
redirect '/settings'
end