admin_resources 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3be67639f99785b3922b74d53915eb671d2bd18e9f9f29e2f4b176229b8ec37e
4
- data.tar.gz: 581deeb6b0c2202bf2db8bddb021606aa804ed9eb44f386958480c5d56c84e1d
3
+ metadata.gz: d1345b7115de46f15fff470050fb1396405caeb9a4cc30db081d70e0382de20e
4
+ data.tar.gz: c763bee96e36d45cfa9aad86ae74bc08f945208a08b41cb92866d3b70900168c
5
5
  SHA512:
6
- metadata.gz: b27b897928284a64a6d8f5e4bf733feea84508d72f41235187e45fa048004d6ea1ac4b0f2732cbf64fc86a179ba6776b785cda9db3b2d7cf600a1f9255a9360a
7
- data.tar.gz: a469f701fde5346d425bea3fa7a8fa4dff3a656006abdb4a822cc0747488f617655c8bf46d7b7143e1eb00acd39383c3b007cbb96781dbcd4866695e1a1f4d1c
6
+ metadata.gz: 6435a8351eac087a9a22b1e8e9170f5d68b03d345cbde12a174c63912ab0e73b6cd859ac57b8ef17d04c1996617a5d910f9dcf43513a4926d24017b9090c0b70
7
+ data.tar.gz: d9922df8e862e81ec09fa306b9c43c6c048754fbcd482e19b9f25c6aec5209d58720fc360a0ea696c0ee8fa4bf4c0130a12e74cf605e4484d52ac500d4ec129f
@@ -0,0 +1,53 @@
1
+ module AdminResources
2
+ class AdminUsersController < ApplicationController
3
+ def index
4
+ @admin_users = AdminUser.order(:email)
5
+ end
6
+
7
+ def new
8
+ @admin_user = AdminUser.new
9
+ end
10
+
11
+ def create
12
+ @admin_user = AdminUser.new(admin_user_params)
13
+ if @admin_user.save
14
+ redirect_to admin_resources.admin_users_path, notice: "Admin user created."
15
+ else
16
+ render :new, status: :unprocessable_entity
17
+ end
18
+ end
19
+
20
+ def edit
21
+ @admin_user = AdminUser.find(params[:id])
22
+ end
23
+
24
+ def update
25
+ @admin_user = AdminUser.find(params[:id])
26
+ params_to_update = admin_user_params
27
+ params_to_update.delete(:password) if params_to_update[:password].blank?
28
+ params_to_update.delete(:password_confirmation) if params_to_update[:password].blank?
29
+
30
+ if @admin_user.update(params_to_update)
31
+ redirect_to admin_resources.admin_users_path, notice: "Admin user updated."
32
+ else
33
+ render :edit, status: :unprocessable_entity
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ @admin_user = AdminUser.find(params[:id])
39
+ if @admin_user == current_admin_user
40
+ redirect_to admin_resources.admin_users_path, alert: "You cannot delete your own account."
41
+ else
42
+ @admin_user.destroy
43
+ redirect_to admin_resources.admin_users_path, notice: "Admin user deleted."
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def admin_user_params
50
+ params.require(:admin_user).permit(:email, :password, :password_confirmation)
51
+ end
52
+ end
53
+ end
@@ -1,8 +1,16 @@
1
1
  module AdminResources
2
2
  class ApplicationController < ActionController::Base
3
- before_action :authenticate_admin_resources_admin_user!
3
+ before_action :authenticate_admin_user!
4
4
  layout "admin_resources/admin"
5
5
 
6
+ def after_sign_in_path_for(resource)
7
+ admin_resources.root_path
8
+ end
9
+
10
+ def after_sign_out_path_for(resource_or_scope)
11
+ admin_resources.new_admin_user_session_path
12
+ end
13
+
6
14
  helper_method :admin_models, :admin_path_for
7
15
 
8
16
  def admin_models
@@ -0,0 +1,19 @@
1
+ module AdminResources
2
+ class DeviseFailureApp < Devise::FailureApp
3
+ def redirect_url
4
+ if scope == :admin_user
5
+ "/admin/login"
6
+ else
7
+ super
8
+ end
9
+ end
10
+
11
+ def respond
12
+ if http_auth?
13
+ http_auth
14
+ else
15
+ redirect
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module AdminResources
2
+ class SessionsController < Devise::SessionsController
3
+ layout "admin_resources/admin_login"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ <%= form_for admin_user, url: admin_user.new_record? ? admin_resources.admin_users_path : admin_resources.admin_user_path(admin_user), html: { class: "admin-form" } do |f| %>
2
+ <% if admin_user.errors.any? %>
3
+ <div class="admin-flash alert">
4
+ <% admin_user.errors.full_messages.each do |msg| %>
5
+ <div><%= msg %></div>
6
+ <% end %>
7
+ </div>
8
+ <% end %>
9
+
10
+ <div class="field">
11
+ <%= f.label :email %>
12
+ <%= f.email_field :email, autocomplete: "off" %>
13
+ </div>
14
+
15
+ <div class="field">
16
+ <%= f.label :password %>
17
+ <%= f.password_field :password, autocomplete: "new-password" %>
18
+ <% if admin_user.persisted? %>
19
+ <small style="color:#666">Leave blank to keep current password</small>
20
+ <% end %>
21
+ </div>
22
+
23
+ <div class="field">
24
+ <%= f.label :password_confirmation %>
25
+ <%= f.password_field :password_confirmation, autocomplete: "new-password" %>
26
+ </div>
27
+
28
+ <div class="admin-actions" style="margin-top:1rem">
29
+ <%= f.submit admin_user.new_record? ? "Create Admin User" : "Update Admin User", class: "admin-btn admin-btn-primary" %>
30
+ <%= link_to "Cancel", admin_resources.admin_users_path, class: "admin-btn admin-btn-secondary" %>
31
+ </div>
32
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <div class="admin-header">
2
+ <h1>Edit Admin User</h1>
3
+ </div>
4
+
5
+ <%= render "form", admin_user: @admin_user %>
@@ -0,0 +1,30 @@
1
+ <div class="admin-header">
2
+ <h1>Admin Users</h1>
3
+ <%= link_to "New Admin User", admin_resources.new_admin_user_path, class: "admin-btn admin-btn-primary" %>
4
+ </div>
5
+
6
+ <table class="admin-table">
7
+ <thead>
8
+ <tr>
9
+ <th>ID</th>
10
+ <th>Email</th>
11
+ <th>Created At</th>
12
+ <th>Actions</th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% @admin_users.each do |admin_user| %>
17
+ <tr>
18
+ <td><%= admin_user.id %></td>
19
+ <td><%= admin_user.email %></td>
20
+ <td><%= admin_user.created_at.strftime("%Y-%m-%d %H:%M:%S") %></td>
21
+ <td class="admin-actions">
22
+ <%= link_to "Edit", admin_resources.edit_admin_user_path(admin_user), class: "admin-btn admin-btn-secondary" %>
23
+ <% if admin_user != current_admin_user %>
24
+ <%= button_to "Delete", admin_resources.admin_user_path(admin_user), method: :delete, class: "admin-btn admin-btn-danger", data: { turbo_confirm: "Delete #{admin_user.email}?" } %>
25
+ <% end %>
26
+ </td>
27
+ </tr>
28
+ <% end %>
29
+ </tbody>
30
+ </table>
@@ -0,0 +1,5 @@
1
+ <div class="admin-header">
2
+ <h1>New Admin User</h1>
3
+ </div>
4
+
5
+ <%= render "form", admin_user: @admin_user %>
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Admin Login</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <%= csrf_meta_tags %>
7
+ <style>
8
+ body { margin: 0; background: #1a1a2e; display: flex; align-items: center; justify-content: center; min-height: 100vh; font-family: sans-serif; }
9
+ .login-box { background: #fff; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.3); width: 100%; max-width: 360px; }
10
+ h2 { margin: 0 0 1.5rem; color: #1a1a2e; font-size: 1.5rem; }
11
+ .field { margin-bottom: 1rem; }
12
+ label { display: block; margin-bottom: 0.25rem; font-weight: 500; color: #333; font-size: 0.875rem; }
13
+ input[type="email"], input[type="password"] { width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem; box-sizing: border-box; }
14
+ .actions { margin-top: 1.5rem; }
15
+ input[type="submit"] { width: 100%; padding: 0.625rem; background: #0f3460; color: #fff; border: none; border-radius: 4px; font-size: 1rem; cursor: pointer; }
16
+ input[type="submit"]:hover { background: #16213e; }
17
+ .alert { background: #f8d7da; color: #721c24; padding: 0.75rem; border-radius: 4px; margin-bottom: 1rem; font-size: 0.875rem; }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div class="login-box">
22
+ <h2>Admin Login</h2>
23
+ <% if alert %>
24
+ <div class="alert"><%= alert %></div>
25
+ <% end %>
26
+ <%= form_for(resource, as: resource_name, url: admin_resources.admin_user_session_path) do |f| %>
27
+ <div class="field">
28
+ <%= f.label :email %>
29
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
30
+ </div>
31
+ <div class="field">
32
+ <%= f.label :password %>
33
+ <%= f.password_field :password, autocomplete: "current-password" %>
34
+ </div>
35
+ <div class="actions">
36
+ <%= f.submit "Sign in" %>
37
+ </div>
38
+ <% end %>
39
+ </div>
40
+ </body>
41
+ </html>
@@ -0,0 +1,19 @@
1
+ <h2>Admin Login</h2>
2
+
3
+ <% if alert %>
4
+ <div class="alert"><%= alert %></div>
5
+ <% end %>
6
+
7
+ <%= form_for(resource, as: resource_name, url: admin_resources.admin_user_session_path) do |f| %>
8
+ <div class="field">
9
+ <%= f.label :email %>
10
+ <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
11
+ </div>
12
+ <div class="field">
13
+ <%= f.label :password %>
14
+ <%= f.password_field :password, autocomplete: "current-password" %>
15
+ </div>
16
+ <div class="actions">
17
+ <%= f.submit "Sign in" %>
18
+ </div>
19
+ <% end %>
@@ -57,6 +57,8 @@
57
57
  <% end %>
58
58
 
59
59
  <h3>Account</h3>
60
+ <%= link_to "Admin Users", admin_resources.admin_users_path,
61
+ class: (controller_path == 'admin_resources/admin_users' ? 'active' : '') %>
60
62
  <%= link_to "Sign Out", admin_resources.destroy_admin_user_session_path, data: { turbo_method: :delete } %>
61
63
  </nav>
62
64
 
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Admin Login</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <%= csrf_meta_tags %>
7
+ <style>
8
+ body { margin: 0; background: #1a1a2e; display: flex; align-items: center; justify-content: center; min-height: 100vh; font-family: sans-serif; }
9
+ .login-box { background: #fff; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.3); width: 100%; max-width: 360px; }
10
+ h2 { margin: 0 0 1.5rem; color: #1a1a2e; font-size: 1.5rem; }
11
+ .field { margin-bottom: 1rem; }
12
+ label { display: block; margin-bottom: 0.25rem; font-weight: 500; color: #333; font-size: 0.875rem; }
13
+ input[type="email"], input[type="password"] { width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem; box-sizing: border-box; }
14
+ .actions { margin-top: 1.5rem; }
15
+ input[type="submit"] { width: 100%; padding: 0.625rem; background: #0f3460; color: #fff; border: none; border-radius: 4px; font-size: 1rem; cursor: pointer; }
16
+ input[type="submit"]:hover { background: #16213e; }
17
+ .alert { background: #f8d7da; color: #721c24; padding: 0.75rem; border-radius: 4px; margin-bottom: 1rem; font-size: 0.875rem; }
18
+ </style>
19
+ </head>
20
+ <body>
21
+ <div class="login-box">
22
+ <%= yield %>
23
+ </div>
24
+ </body>
25
+ </html>
data/config/routes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  AdminResources::Engine.routes.draw do
2
2
  devise_for :admin_users,
3
3
  class_name: "AdminResources::AdminUser",
4
+ controllers: { sessions: "admin_resources/sessions" },
4
5
  module: :devise,
5
6
  path: "",
6
7
  path_names: { sign_in: "login", sign_out: "logout" }
@@ -12,5 +13,7 @@ AdminResources::Engine.routes.draw do
12
13
  defaults: { model: model_name }
13
14
  end
14
15
 
16
+ resources :admin_users, only: [:index, :new, :create, :edit, :update, :destroy]
17
+
15
18
  root to: "dashboard#index"
16
19
  end
@@ -7,6 +7,14 @@ module AdminResources
7
7
  class Engine < ::Rails::Engine
8
8
  isolate_namespace AdminResources
9
9
 
10
+ initializer "admin_resources.warden_failure_app" do
11
+ Devise.setup do |config|
12
+ config.warden do |manager|
13
+ manager.failure_app = AdminResources::DeviseFailureApp
14
+ end
15
+ end
16
+ end
17
+
10
18
  initializer "admin_resources.load_admin_user_migration" do |app|
11
19
  # Add our migrations to the host app's migration path
12
20
  config.paths["db/migrate"].expanded.each do |expanded_path|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdminResources
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mark rosenberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-03-21 00:00:00.000000000 Z
11
+ date: 2026-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -49,17 +49,27 @@ files:
49
49
  - LICENSE
50
50
  - README.md
51
51
  - Rakefile
52
+ - app/controllers/admin_resources/admin_users_controller.rb
52
53
  - app/controllers/admin_resources/application_controller.rb
53
54
  - app/controllers/admin_resources/dashboard_controller.rb
55
+ - app/controllers/admin_resources/devise_failure_app.rb
54
56
  - app/controllers/admin_resources/resources_controller.rb
57
+ - app/controllers/admin_resources/sessions_controller.rb
55
58
  - app/models/admin_resources/admin_user.rb
59
+ - app/views/admin_resources/admin_users/_form.html.erb
60
+ - app/views/admin_resources/admin_users/edit.html.erb
61
+ - app/views/admin_resources/admin_users/index.html.erb
62
+ - app/views/admin_resources/admin_users/new.html.erb
56
63
  - app/views/admin_resources/dashboard/index.html.erb
64
+ - app/views/admin_resources/devise/sessions/new.html.erb
57
65
  - app/views/admin_resources/resources/_form.html.erb
58
66
  - app/views/admin_resources/resources/edit.html.erb
59
67
  - app/views/admin_resources/resources/index.html.erb
60
68
  - app/views/admin_resources/resources/new.html.erb
61
69
  - app/views/admin_resources/resources/show.html.erb
70
+ - app/views/admin_resources/sessions/new.html.erb
62
71
  - app/views/layouts/admin_resources/admin.html.erb
72
+ - app/views/layouts/admin_resources/admin_login.html.erb
63
73
  - config/routes.rb
64
74
  - db/migrate/20240101000000_create_admin_resources_admin_users.rb
65
75
  - lib/admin_resources.rb