Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit e9736a8

Browse files
authored
Merge pull request #43 from paiindustries/fix/site-issues
Fix/site issues
2 parents c446a93 + 34c3cc0 commit e9736a8

29 files changed

Lines changed: 83017 additions & 465 deletions

app/controllers/web/AdminController.cfc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ component extends="app.Controllers.Controller" {
1414

1515
function blog() {
1616
blogs = getAllBlogs();
17+
1718
}
1819

1920
function approve() {

app/controllers/web/AuthController.cfc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ component extends="app.Controllers.Controller" {
4343
try {
4444

4545
// Get the full user object (assuming session.user might just have the ID)
46-
var redirectUrl = session.keyExists("redirectAfterLogin") ? session.redirectAfterLogin : urlFor(route="home");
46+
if(user.role.name == 'admin'){
47+
var redirectUrl = urlFor(route="admin-blog");
48+
}else{
49+
var redirectUrl = session.keyExists("redirectAfterLogin") ? session.redirectAfterLogin : urlFor(route="home");
50+
}
4751

4852
// Clear the session variable after use
4953
structDelete(session, "redirectAfterLogin");

app/controllers/web/BlogController.cfc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ component extends="app.Controllers.Controller" {
207207

208208
private function getAllBlogs() {
209209
return model("Blog").findAll(
210-
where='statusid <> 1',
210+
where="statusid <> 1 AND status ='Approved'",
211211
include="User, PostStatus, PostType",
212212
order = "COALESCE(post_created_date, blog_posts.createdat) DESC"
213213
);

app/controllers/web/UserController.cfc

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
component extends="app.Controllers.Controller" {
33

44
function config() {
5-
verifies(except="index,loadUsers,loadRoles,addUser,store,delete,profile,changePassword,updatePassword,uploadProfilePic,updateProfilePic", params="key", paramsTypes="integer", handler="index");
6-
usesLayout("/layout");
5+
verifies(except="index,loadUsers,loadRoles,addUser,store,delete,profile,changePassword,updatePassword,uploadProfilePic,updateProfilePic,checkAdminAccess", params="key", paramsTypes="integer", handler="index");
6+
usesLayout("/web/AdminController/layout");
7+
filters(through="checkAdminAccess");
78
}
89

910
// read user
@@ -41,37 +42,12 @@ component extends="app.Controllers.Controller" {
4142

4243
// Save user logic here
4344
try {
44-
45-
params.profilePicture = "";
46-
var uploadPath = expandPath("/files/"); // Define the upload directory
47-
48-
if (!directoryExists(uploadPath)) {
49-
directoryCreate(uploadPath);
50-
}
51-
52-
// Handle file upload
53-
if (structKeyExists(params, "profilePicture") && isDefined("params.profilePicture")) {
54-
var uploadedFile = fileUpload(uploadPath, "profilePicture");
55-
56-
if (!structIsEmpty(uploadedFile) && structKeyExists(uploadedFile, "serverFile")) {
57-
var originalFileName = uploadedFile.serverFile; // This is the uploaded file name
58-
var fileExtension = listLast(originalFileName, "."); // Extract extension
59-
var uniqueFileName = createUUID() & "." & fileExtension; // Generate unique name
60-
61-
// Rename file to unique name
62-
var newFilePath = uploadPath & "/" & uniqueFileName;
63-
fileMove(uploadedFile.serverDirectory & "/" & originalFileName, newFilePath);
64-
65-
// Store the relative file path
66-
params.profilePicture = "/files/" & uniqueFileName;
67-
}
68-
}
69-
7045
var message = saveUser(params);
71-
redirectTo(action="index");
46+
47+
redirectTo(route="user", success="User successfully added!");
7248
} catch (any e) {
7349
// Handle error
74-
redirectTo(action="error", errorMessage="Failed to save user.");
50+
redirectTo(action="error", error="Failed to save user.");
7551
}
7652
}
7753

@@ -197,6 +173,18 @@ component extends="app.Controllers.Controller" {
197173
}
198174
// Business Logic
199175

176+
private function checkAdminAccess() {
177+
// Ensure only admin users can access these methods
178+
if (!isCurrentUserAdmin()) {
179+
// Save the current URL in session
180+
saveRedirectUrl(cgi.script_name & "?" & cgi.query_string);
181+
// Redirect to login page
182+
redirectTo(controller="AuthController", action="login", route="auth-login");
183+
return false;
184+
}
185+
return true;
186+
}
187+
200188
/**
201189
* Count total number of users
202190
*/
@@ -254,7 +242,7 @@ component extends="app.Controllers.Controller" {
254242
user.firstname = userData.firstName;
255243
user.lastname = userData.lastName;
256244
user.email = userData.email;
257-
user.passwordHash = hash(userData.passwordHash);
245+
user.passwordHash = application.WHEELS.plugins.bcrypt.bCryptHashPW(userData.passwordHash, application.WHEELS.plugins.bcrypt.bCryptGenSalt());
258246
user.status = application.wo.SetActive();
259247
user.roleid = userData.roleid;
260248
user.updatedAt = now();
@@ -276,7 +264,7 @@ component extends="app.Controllers.Controller" {
276264
newUser.firstname = userData.firstName;
277265
newUser.lastname = userData.lastName;
278266
newUser.email = userData.email;
279-
newUser.passwordHash = hash(userData.passwordHash);
267+
newUser.passwordHash = application.WHEELS.plugins.bcrypt.bCryptHashPW(userData.passwordHash, application.WHEELS.plugins.bcrypt.bCryptGenSalt());
280268
newUser.status = application.wo.SetActive();
281269
newUser.roleid = userData.roleid;
282270
newUser.createdAt = now();

app/models/Blog.cfc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ component extends="app.Models.Model" {
5252
var blogs = findAll(
5353
where='statusid <> 1',
5454
include="User",
55+
maxRows=10,
5556
order="COALESCE(post_created_date, blog_posts.createdAt) DESC"
5657
);
5758
return blogs;

app/views/layout.cfm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,21 @@
8181
<link href="/stylesheets/icons/bootstrap-icons.min.css" rel="stylesheet">
8282
<link href="/stylesheets/select2-bootstrap-min.css" rel="stylesheet">
8383
<link href="/stylesheets/notifier.min.css" rel="stylesheet">
84-
84+
<link href="/stylesheets/dataTables.min.css" rel="stylesheet">
85+
8586
<script src="/javascripts/jquery.min.js"></script>
87+
<script src="/javascripts/dataTables.min.js"></script>
8688
<script src="/javascripts/htmx.min.js"></script>
8789
<script src="/javascripts/highlighter.min.js"></script>
8890
<script src="/javascripts/quill.min.js"></script>
8991
<script src="/javascripts/bootstrap.js"></script>
92+
<script src="/javascripts/config.js"></script>
93+
<cfoutput>
94+
#javascriptIncludeTag(source="anchor.min.js")#
95+
#javascriptIncludeTag(source="all.min.js")#
96+
#javascriptIncludeTag(source="lodash.min.js")#
97+
#javascriptIncludeTag(source="phoenix.js")#
98+
</cfoutput>
9099

91100
<script>
92101
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){

app/views/web/AdminController/blog.cfm

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,78 @@
11
<main>
22
<cfoutput>
33
<div class="container py-5">
4-
<div class="row justify-content-center justify-content-lg-between">
5-
<div class="bg-white rounded-5 shadow-sm mt-4 p-4 overflow-x-auto">
6-
<h1 class="text-center fs-24 mb-5 fw-bold">Blogs</h1>
7-
<table id="blogTable" class="table table-hover">
8-
<thead>
9-
<tr>
10-
<th>ID</th>
11-
<th>Title</th>
12-
<th>Status</th>
13-
<th>Post Type</th>
14-
<th>Created By</th>
15-
<th>Approval Status</th>
16-
<th></th>
17-
</tr>
18-
</thead>
19-
<tbody>
20-
<cfloop from="1" to="#blogs.recordCount#" index="i">
21-
<cfset blogId = blogs.id[i]>
22-
<cfset truncatedContent = left(blogs.content[i], 100) & "...">
23-
24-
<tr id="blog-#blogId#">
25-
<td>#i#</td>
26-
<td><a href="blog/#blogs.slug[i]#" class="cursor-pointer text-primary">#blogs.title[i]#</a></td>
27-
<td>#blogs.NAME[i]#</td>
28-
<td>#blogs.POSTTYPENAME[i]#</td>
29-
<td>#blogs.fullName[i]#</td>
30-
<td>
31-
<cfif blogs.status[i] eq 'Approved'>
32-
<span class="badge bg-success">Approved</span>
33-
<cfelseif blogs.status[i] eq 'Rejected'>
34-
<span class="badge bg-danger">Rejected</span>
35-
<cfelse>
36-
<span class="badge bg-warning text-dark">Pending</span>
37-
</cfif>
38-
</td>
39-
<td>
40-
<div class="dropdown">
41-
<div class="fw-bold cursor-pointer" data-bs-toggle="dropdown" aria-expanded="false">
42-
...
43-
</div>
44-
<ul class="dropdown-menu">
45-
<li>
46-
<button
47-
class="dropdown-item text-success"
48-
hx-post="approve"
49-
hx-vals='{"id": "#blogId#"}'
50-
hx-confirm="Are you sure you want to approve this blog?"
51-
>Approve</button>
52-
</li>
53-
<li>
54-
<button
55-
class="dropdown-item text-danger"
56-
hx-post="reject"
57-
hx-vals='{"id": "#blogId#"}'
58-
hx-confirm="Are you sure you want to reject this blog?"
59-
>Reject</button>
60-
</li>
61-
</ul>
62-
</div>
63-
</td>
64-
</tr>
65-
</cfloop>
66-
</tbody>
67-
</table>
68-
</div>
4+
<div class="col-auto">
5+
<h1 class="fs-24 mb-5 fw-bold">Blogs</h1>
696
</div>
7+
<table id="blogTable" class="table table-hover">
8+
<thead>
9+
<tr>
10+
<th>ID</th>
11+
<th>Title</th>
12+
<th>Status</th>
13+
<th>Categories</th>
14+
<th>Created By</th>
15+
<th>Approval Status</th>
16+
<th></th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<cfloop from="1" to="#blogs.recordCount#" index="i">
21+
<cfset blogId = blogs.id[i]>
22+
<cfset truncatedContent = left(blogs.content[i], 100) & "...">
23+
24+
<tr id="blog-#blogId#">
25+
<td>#i#</td>
26+
<td><a href="blog/#blogs.slug[i]#" class="cursor-pointer text-primary">#blogs.title[i]#</a></td>
27+
<td>#blogs.NAME[i]#</td>
28+
<cfscript>
29+
var categories = model("BlogCategory").findAll(
30+
select = "name",
31+
where = "blogId = #blogs.id[i]#",
32+
include = "Blog,Category"
33+
);
34+
var categoryNames = valueList(categories.name);
35+
</cfscript>
36+
<td>#categoryNames#</td>
37+
<td>#blogs.fullName[i]#</td>
38+
<td>
39+
<cfif blogs.status[i] eq 'Approved'>
40+
<span class="badge bg-success">Approved</span>
41+
<cfelseif blogs.status[i] eq 'Rejected'>
42+
<span class="badge bg-danger">Rejected</span>
43+
<cfelse>
44+
<span class="badge bg-warning text-dark">Pending</span>
45+
</cfif>
46+
</td>
47+
<td>
48+
<div class="dropdown">
49+
<div class="fw-bold cursor-pointer" data-bs-toggle="dropdown" aria-expanded="false">
50+
...
51+
</div>
52+
<ul class="dropdown-menu">
53+
<li>
54+
<button
55+
class="dropdown-item text-success fs-16"
56+
hx-post="approve"
57+
hx-vals='{"id": "#blogId#"}'
58+
hx-confirm="Are you sure you want to approve this blog?"
59+
>Approve</button>
60+
</li>
61+
<li>
62+
<button
63+
class="dropdown-item text-danger fs-16"
64+
hx-post="reject"
65+
hx-vals='{"id": "#blogId#"}'
66+
hx-confirm="Are you sure you want to reject this blog?"
67+
>Reject</button>
68+
</li>
69+
</ul>
70+
</div>
71+
</td>
72+
</tr>
73+
</cfloop>
74+
</tbody>
75+
</table>
7076
</div>
7177
</cfoutput>
7278
<script>

0 commit comments

Comments
 (0)