alts, admin page, login
This commit is contained in:
parent
2d85fdb5cd
commit
5c0d9e9435
90
.idea/gambosite.iml
generated
90
.idea/gambosite.iml
generated
@ -154,76 +154,78 @@
|
|||||||
<component name="RailsGeneratorsCache">
|
<component name="RailsGeneratorsCache">
|
||||||
<option name="generators">
|
<option name="generators">
|
||||||
<list>
|
<list>
|
||||||
<option value="active_record:migration" />
|
<option value="active_record:application_record" />
|
||||||
<option value="active_record:model" />
|
<option value="active_record:multi_db" />
|
||||||
<option value="active_record:observer" />
|
<option value="application_record" />
|
||||||
<option value="active_record:session_migration" />
|
<option value="authentication" />
|
||||||
|
<option value="benchmark" />
|
||||||
|
<option value="channel" />
|
||||||
<option value="controller" />
|
<option value="controller" />
|
||||||
<option value="erb:controller" />
|
<option value="erb:authentication" />
|
||||||
<option value="erb:mailer" />
|
|
||||||
<option value="erb:scaffold" />
|
|
||||||
<option value="generator" />
|
<option value="generator" />
|
||||||
<option value="helper" />
|
<option value="helper" />
|
||||||
<option value="integration_test" />
|
<option value="integration_test" />
|
||||||
|
<option value="jbuilder" />
|
||||||
|
<option value="job" />
|
||||||
|
<option value="mailbox" />
|
||||||
<option value="mailer" />
|
<option value="mailer" />
|
||||||
<option value="metal" />
|
|
||||||
<option value="migration" />
|
<option value="migration" />
|
||||||
<option value="model" />
|
<option value="model" />
|
||||||
<option value="model_subclass" />
|
|
||||||
<option value="observer" />
|
|
||||||
<option value="performance_test" />
|
|
||||||
<option value="plugin" />
|
|
||||||
<option value="resource" />
|
<option value="resource" />
|
||||||
<option value="scaffold" />
|
<option value="scaffold" />
|
||||||
<option value="scaffold_controller" />
|
<option value="scaffold_controller" />
|
||||||
<option value="session_migration" />
|
<option value="script" />
|
||||||
<option value="stylesheets" />
|
<option value="solid_cable:install" />
|
||||||
<option value="test_unit:controller" />
|
<option value="solid_cable:update" />
|
||||||
<option value="test_unit:helper" />
|
<option value="solid_cache:install" />
|
||||||
<option value="test_unit:integration" />
|
<option value="solid_queue:install" />
|
||||||
<option value="test_unit:mailer" />
|
<option value="stimulus" />
|
||||||
<option value="test_unit:model" />
|
<option value="system_test" />
|
||||||
<option value="test_unit:observer" />
|
<option value="task" />
|
||||||
<option value="test_unit:performance" />
|
<option value="test_unit:authentication" />
|
||||||
|
<option value="test_unit:channel" />
|
||||||
|
<option value="test_unit:generator" />
|
||||||
|
<option value="test_unit:install" />
|
||||||
|
<option value="test_unit:mailbox" />
|
||||||
<option value="test_unit:plugin" />
|
<option value="test_unit:plugin" />
|
||||||
<option value="test_unit:scaffold" />
|
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="myGenerators">
|
<option name="myGenerators">
|
||||||
<list>
|
<list>
|
||||||
<option value="active_record:migration" />
|
<option value="active_record:application_record" />
|
||||||
<option value="active_record:model" />
|
<option value="active_record:multi_db" />
|
||||||
<option value="active_record:observer" />
|
<option value="application_record" />
|
||||||
<option value="active_record:session_migration" />
|
<option value="authentication" />
|
||||||
|
<option value="benchmark" />
|
||||||
|
<option value="channel" />
|
||||||
<option value="controller" />
|
<option value="controller" />
|
||||||
<option value="erb:controller" />
|
<option value="erb:authentication" />
|
||||||
<option value="erb:mailer" />
|
|
||||||
<option value="erb:scaffold" />
|
|
||||||
<option value="generator" />
|
<option value="generator" />
|
||||||
<option value="helper" />
|
<option value="helper" />
|
||||||
<option value="integration_test" />
|
<option value="integration_test" />
|
||||||
|
<option value="jbuilder" />
|
||||||
|
<option value="job" />
|
||||||
|
<option value="mailbox" />
|
||||||
<option value="mailer" />
|
<option value="mailer" />
|
||||||
<option value="metal" />
|
|
||||||
<option value="migration" />
|
<option value="migration" />
|
||||||
<option value="model" />
|
<option value="model" />
|
||||||
<option value="model_subclass" />
|
|
||||||
<option value="observer" />
|
|
||||||
<option value="performance_test" />
|
|
||||||
<option value="plugin" />
|
|
||||||
<option value="resource" />
|
<option value="resource" />
|
||||||
<option value="scaffold" />
|
<option value="scaffold" />
|
||||||
<option value="scaffold_controller" />
|
<option value="scaffold_controller" />
|
||||||
<option value="session_migration" />
|
<option value="script" />
|
||||||
<option value="stylesheets" />
|
<option value="solid_cable:install" />
|
||||||
<option value="test_unit:controller" />
|
<option value="solid_cable:update" />
|
||||||
<option value="test_unit:helper" />
|
<option value="solid_cache:install" />
|
||||||
<option value="test_unit:integration" />
|
<option value="solid_queue:install" />
|
||||||
<option value="test_unit:mailer" />
|
<option value="stimulus" />
|
||||||
<option value="test_unit:model" />
|
<option value="system_test" />
|
||||||
<option value="test_unit:observer" />
|
<option value="task" />
|
||||||
<option value="test_unit:performance" />
|
<option value="test_unit:authentication" />
|
||||||
|
<option value="test_unit:channel" />
|
||||||
|
<option value="test_unit:generator" />
|
||||||
|
<option value="test_unit:install" />
|
||||||
|
<option value="test_unit:mailbox" />
|
||||||
<option value="test_unit:plugin" />
|
<option value="test_unit:plugin" />
|
||||||
<option value="test_unit:scaffold" />
|
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
@ -105,11 +105,33 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
color: #fe8019;
|
|
||||||
margin: auto;
|
margin: auto;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
padding-bottom: 1em;
|
padding-bottom: 1em;
|
||||||
|
color: #fe8019;
|
||||||
|
}
|
||||||
|
|
||||||
|
.left-just {
|
||||||
|
text-align: left;
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 800px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
color: #fabd2f;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
color: #689d6a;
|
||||||
|
}
|
||||||
|
|
||||||
|
p, label {
|
||||||
|
color: #ebdbb2;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
@ -191,3 +213,12 @@ a:visited {
|
|||||||
transform: translateY(0) rotate(-5deg);
|
transform: translateY(0) rotate(-5deg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
margin-right: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#set-alt-button {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
55
app/controllers/admin_controller.rb
Normal file
55
app/controllers/admin_controller.rb
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
class AdminController < ApplicationController
|
||||||
|
PASSWORD = "butts"
|
||||||
|
before_action :authenticate_admin, only: [:index, :set_alt, :clear_alt ]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@mains = Player.joins(:alternate_players).distinct
|
||||||
|
@player_names = Player.all.map(&:name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_alt
|
||||||
|
main = Player.find_by(name: params[:main_selected])
|
||||||
|
alt = Player.find_by(name: params[:alt_selected])
|
||||||
|
|
||||||
|
if main && alt && main.id != alt.id
|
||||||
|
main.alternate_players << alt
|
||||||
|
alt.main_player_id = main.id
|
||||||
|
|
||||||
|
main.save
|
||||||
|
alt.save
|
||||||
|
end
|
||||||
|
|
||||||
|
refresh_or_redirect_to admin_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_alt
|
||||||
|
main = Player.find_by(id: params[:main_id])
|
||||||
|
alt = Player.find_by(id: params[:alt_id])
|
||||||
|
|
||||||
|
if main && alt && main.alternate_players.include?(alt)
|
||||||
|
main.alternate_players.delete(alt)
|
||||||
|
main.save
|
||||||
|
end
|
||||||
|
|
||||||
|
refresh_or_redirect_to admin_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def login
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def login_submit
|
||||||
|
pw = params[:password]
|
||||||
|
if pw == PASSWORD
|
||||||
|
session[:user_id] = 1
|
||||||
|
redirect_to admin_path, notice: "Logged in!"
|
||||||
|
else
|
||||||
|
refresh_or_redirect_to admin_login_path, notice: "Login failed!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
session.delete(:user_id)
|
||||||
|
redirect_to root_path, notice: "Logged out!"
|
||||||
|
end
|
||||||
|
end
|
@ -20,4 +20,10 @@ class ApplicationController < ActionController::Base
|
|||||||
def unauthorized_response
|
def unauthorized_response
|
||||||
render json: { error: "API key is missing or empty" }, status: :unauthorized
|
render json: { error: "API key is missing or empty" }, status: :unauthorized
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def authenticate_admin
|
||||||
|
unless session[:user_id]
|
||||||
|
redirect_to admin_login_path, alert: "Login first"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
2
app/helpers/admin_helper.rb
Normal file
2
app/helpers/admin_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module AdminHelper
|
||||||
|
end
|
@ -35,6 +35,10 @@ class Player < ApplicationRecord
|
|||||||
self.main_player
|
self.main_player
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def alts_concat
|
||||||
|
self.alternate_players.map(&:name).join(", ")
|
||||||
|
end
|
||||||
|
|
||||||
def no_circular_references
|
def no_circular_references
|
||||||
if main_player_id.present? && (main_player.main_player== self)
|
if main_player_id.present? && (main_player.main_player== self)
|
||||||
errors.add(:main_account, "circular reference")
|
errors.add(:main_account, "circular reference")
|
||||||
|
45
app/views/admin/index.html.erb
Normal file
45
app/views/admin/index.html.erb
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<h1>Admin</h1>
|
||||||
|
|
||||||
|
<h2 class="left-just">Alt List</h2>
|
||||||
|
<div class="wrapper">
|
||||||
|
<div class="table">
|
||||||
|
<div class="row header">
|
||||||
|
<div class="cell">Main</div>
|
||||||
|
<div class="cell">Alts</div>
|
||||||
|
<div class="cell">Remove</div>
|
||||||
|
</div>
|
||||||
|
<% @mains.each do |main| %>
|
||||||
|
<% main.alternate_players.each do |alt| %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="cell" data-title="Main"><%= main.name %></div>
|
||||||
|
<div class="cell" data-title="Alts"><%= alt.name %></div>
|
||||||
|
<div class="cell" data-title="Remove"><%= button_to "Clear Alt",
|
||||||
|
"/admin/clear_alt",
|
||||||
|
method: :post,
|
||||||
|
params: { main_id: main.id, alt_id: alt.id } %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= form_with(url: "/admin/set_alt", method: :post, local: true) do %>
|
||||||
|
<h2>Set Alt</h2>
|
||||||
|
<label for="main-selector">Main: </label>
|
||||||
|
<select id="main-selector" name="main_selected">
|
||||||
|
<% @player_names.each do |name| %>
|
||||||
|
<option value="<%= name %>"><%= name %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
<label for="alt-selector">Alt: </label>
|
||||||
|
<select id="alt-selector" name="alt_selected">
|
||||||
|
<% @player_names.each do |name| %>
|
||||||
|
<option value="<%= name %>"><%= name %></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<%= submit_tag "Set Alt", id: "set-alt-button" %>
|
||||||
|
<% end %>
|
||||||
|
<a href="/">Leaderboard</a>
|
||||||
|
<a href="/admin/destroy">Logout</a>
|
||||||
|
</div>
|
8
app/views/admin/login.html.erb
Normal file
8
app/views/admin/login.html.erb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<h1>Admin Login</h1>
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<%= form_with(url: "/admin/login_submit", method: :post, local: true) do %>
|
||||||
|
<label for="password">Password: </label>
|
||||||
|
<input id="password" type="text" name="password">
|
||||||
|
<input type="submit" value="password">
|
||||||
|
<% end %>
|
||||||
|
</div>
|
1
config/initializers/session_store.rb
Normal file
1
config/initializers/session_store.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
Rails.application.config.session_store :cookie_store, key: "forcek.in", expire_after: 30.minutes
|
@ -27,4 +27,12 @@ Rails.application.routes.draw do
|
|||||||
get "bot/players" => "bot#players"
|
get "bot/players" => "bot#players"
|
||||||
get "bot/player/:id" => "bot#player_name"
|
get "bot/player/:id" => "bot#player_name"
|
||||||
get "bot/summary" => "bot#summary"
|
get "bot/summary" => "bot#summary"
|
||||||
|
|
||||||
|
# Admin
|
||||||
|
get "admin", to: "admin#index"
|
||||||
|
post "admin/set_alt", to: "admin#set_alt"
|
||||||
|
post "admin/clear_alt", to: "admin#clear_alt"
|
||||||
|
get "admin/login", to: "admin#login"
|
||||||
|
post "admin/login_submit", to: "admin#login_submit"
|
||||||
|
get "admin/destroy", to: "admin#destroy"
|
||||||
end
|
end
|
||||||
|
7
test/controllers/admin_controller_test.rb
Normal file
7
test/controllers/admin_controller_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class AdminControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user