Skip to content

Commit e3d085b

Browse files
committed
Add login page, align styles with other admin panels, allow only sending of approved puzzles
1 parent 191a6ea commit e3d085b

File tree

6 files changed

+73
-17
lines changed

6 files changed

+73
-17
lines changed

app/assets/stylesheets/application.css

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@
99
* Consider organizing styles into separate files for maintainability.
1010
*/
1111

12+
/* General styles */
13+
body {
14+
font-family: 'Open Sans', sans-serif;
15+
padding: 20px;
16+
}
17+
18+
body.login {
19+
display: flex;
20+
justify-content: center;
21+
align-items: center;
22+
height: 100vh;
23+
margin: 0;
24+
}
25+
.container {
26+
text-align: center;
27+
padding: 20px;
28+
border: 2px solid #FFD633;
29+
border-radius: 5px;
30+
max-width: 400px;
31+
}
32+
33+
.logout-container {
34+
text-align: right;
35+
margin-bottom: 20px;
36+
}
37+
1238
table {
1339
border-collapse: collapse;
1440
width: 100%;
@@ -27,14 +53,20 @@ th {
2753

2854
/* Reusable button base style */
2955
.btn {
30-
color: white;
31-
border: none;
32-
padding: 6px 12px;
33-
margin-left: 4px;
56+
display: inline-block;
57+
padding: 8px 16px;
58+
background-color: #FFC000;
59+
color: black;
60+
text-decoration: none;
3461
border-radius: 4px;
62+
border: none;
3563
cursor: pointer;
3664
}
3765

66+
.btn:hover {
67+
background-color: #FFD633;
68+
}
69+
3870
/* Specific button variants */
3971
.approve-btn {
4072
background-color: #4CAF50;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
class ApplicationController < ActionController::Base
22
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
33
allow_browser versions: :modern
4+
before_action :check_session_expiry
5+
6+
private
7+
8+
def check_session_expiry
9+
if session[:expires_at].present? && Time.current > session[:expires_at]
10+
reset_session
11+
render "puzzles/login"
12+
else
13+
session[:expires_at] = 1.hour.from_now
14+
end
15+
end
416
end

app/controllers/puzzles_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class PuzzlesController < ApplicationController
22
def index
3+
unless session[:user_token]
4+
render "login"
5+
end
6+
37
@pending_puzzles = Puzzle.pending
48
@approved_puzzles = Puzzle.approved
59
@rejected_puzzles = Puzzle.rejected

app/jobs/daily_puzzle_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class DailyPuzzleJob < ApplicationJob
33
retry_on StandardError, attempts: 3
44

55
def perform
6-
puzzle = Puzzle.where(sent_at: nil).order("RANDOM()").first
6+
puzzle = Puzzle.where(sent_at: nil, state: 0).order("RANDOM()").first
77
return unless puzzle
88

99
Server.where(active: true).each do |server|

app/views/puzzles/index.html.erb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
<% if session[:user_token] %>
2-
<%= link_to 'Logout', session_path(1), data: { turbo_method: :delete } %>
1+
<div class="logout-container">
2+
<%= button_to 'Logout', session_path(1), method: :delete, class: "btn" %>
3+
</div>
34

4-
<h1>Pending Puzzles</h1>
5-
<%= render partial: 'puzzles_table', locals: { puzzles: @pending_puzzles, actions: :pending } %>
5+
<h1>Pending Puzzles</h1>
6+
<%= render partial: 'puzzles_table', locals: { puzzles: @pending_puzzles, actions: :pending } %>
67

7-
<h1>Approved Puzzles</h1>
8-
<%= render partial: 'puzzles_table', locals: { puzzles: @approved_puzzles, actions: :approved } %>
9-
10-
<h1>Rejected Puzzles</h1>
11-
<%= render partial: 'puzzles_table', locals: { puzzles: @rejected_puzzles, actions: :rejected } %>
12-
<% else %>
13-
<%= link_to 'Login with Google', '/auth/google_oauth2' %>
14-
<% end %>
8+
<h1>Approved Puzzles</h1>
9+
<%= render partial: 'puzzles_table', locals: { puzzles: @approved_puzzles, actions: :approved } %>
1510

11+
<h1>Rejected Puzzles</h1>
12+
<%= render partial: 'puzzles_table', locals: { puzzles: @rejected_puzzles, actions: :rejected } %>

app/views/puzzles/login.html.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<% @title = "Ruby or Rails Login" %>
2+
3+
<body class="login">
4+
<div class="container">
5+
<h2>Log In</h2>
6+
<div>
7+
<p>Log in to access the Ruby or Rails admin panel.</p>
8+
<a href="/auth/google_oauth2" class="btn">Login with Google</a>
9+
</div>
10+
</div>
11+
</body>

0 commit comments

Comments
 (0)