-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.cfc
248 lines (194 loc) · 7.89 KB
/
Application.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
component extends="framework.one" output="false" accessors=true {
setting showDebugOutput="false";
this.applicationTimeout = createTimeSpan(2, 0, 0, 0);
this.setClientCookies = true;
this.sessionManagement = true;
this.sessionTimeout = createTimeSpan(0, 2, 0, 0);
this.datasource = 'dp_cat';
// Define the debug flag as a property
this.debug = false;
property userService;
property utils;
property botSessionManager;
// FW/1 settings
variables.framework = {
// action = 'action',
// defaultSection = 'main',
// defaultItem = 'default',
generateSES = true,
SESOmitIndex = true,
decodeRequestBody = true,
maxNumContextsPreserved = 1,
missingview= 'main.notfound',
trace = false,
// diEngine = "di1",
// diComponent = "framework.ioc",
// diLocations = "model, controllers",
diConfig = {
loadListener : function( di1 ) { di1.load(); },
exclude: ['/model/base/', ',model/beans/common.cfc']
},
// reloadApplicationOnEveryRequest = false,
routes = [
{ "$GET/login/" = "/login/default" },
{ "$POST/login/" = "/login/login" },
{ "$GET/logout/" = "/login/logout" },
// register
{
// show the register form
"$GET/register/$" = "/register/default" ,
// resend a verify email
"$GET/resendlink/$" = "/register/handleResendLink",
// verify a token clicked on in an email
"$GET/verify/:token/$" = "/register/handleEmailVerification/token/:token/" ,
// verify email ownership to set a password
"$GET/passwordverify/:token/$" = "/register/completeprofile/ptoken/:token/" ,
// redirect from setPassword post action to finish of set up password
"$GET/setpassword/$" = "/register/completeSetPassword",
// submitting a set password action to complete setting up user profile.
"$POST/setpassword/$" = "/register/setPassword",
"$GET/completeautoreg/$" = "/register/completeAutoReg" ,
// reattempt to register with an existing email but not yet verified.
"$GET/completeregistration/emailinuse/:emailinuse/$" = "/register/completeRegistration/emailinuse/:emailinuse" ,
// redirected from register (POST) to show directions for verifying email
// "$GET/completeprofile/$" = "/register/completeprofile" ,
"$GET/completeregistration/$" = "/register/completeRegistration" ,
// submit a registration form
"$POST/register/$" = "/register/register"
} ,
// forgot password routes
{
// complete screen
"$GET/passwordresetcomplete/$" = "/forgotpassword/passwordresetcomplete",
//show screen to enter email to send link to
"$GET/forgotpassword/$" = "/forgotpassword/default",
// email clicked with token to show password manager
"$GET/resetpassword/:token/" = "/forgotpassword/resetpassword/token/:token/",
// submits password manager
"$POST/resetpassword/$" = "/forgotpassword/submitresetpassword",
//sends email if account exists
"$POST/forgotpassword/$" = "/forgotpassword/submitforgotpassword"
},
// my profile actions secured in securelist
{
"$GET/myprofile/$" = "/myprofile/default" ,
"$GET/dealdetails/$" = "/myprofile/dealdetails" ,
"$GET/reply/$" = "/myprofile/sendmessage" ,
"$GET/myoffers/$" = "/myprofile/myoffers" ,
"$GET/myfavorites/$" = "/myprofile/myfavorites" ,
"$POST/changepassword/$" = "/myprofile/changepassword",
"$POST/updatecontactinfo/$" = "/myprofile/updatecontactinfo",
"$POST/updateaddress/$" = "/myprofile/updateaddress",
"$POST/updateCommPref/$" = "/myprofile/updateCommPref"
},
{ "$GET/search/:term/" = "/main/search/term/:term" },
{ "$GET/search/$" = "/main/search" },
{ "$GET/contact/$" = "/main/contact" },
{ "$POST/contact/$" = "/main/submitContact" },
{ "$GET/faq/$" = "/main/faq" },
{ "$GET/about/$" = "/main/about" },
{ "$GET/terms/$" = "/main/terms" },
{ "$GET/privacy/$" = "/main/privacy" },
{ "$POST/locationlookup/$" = "/main/locationlookup" },
{ "$GET/recentlyviewed/items/:items/" = "/main/getrecentlyviewed/items/:items" },
{ "$GET/items/{id:[0-9]+}/" = "/main/showitem/id/:id" },
{ "$POST/offer/$" = "/dealmaking/makedeal" },
{ "$POST/inquiry/$" = "/dealmaking/makedeal" },
{ "$POST/togglefavorite/" = "/main/togglefavorite" },
{ "$GET/getfavorites/" = "/main/getFavorites" },
{ "$GET/IsLoggedIn/" = "/main/IsLoggedIn" },
]
};
variables.framework.environments = {
dev = {
reloadApplicationOnEveryRequest = true
},
prod = {
password = "Pri234Sc"
}
};
public void function setupApplication() {
// Read the contents of the file into a string
var fileContents = trim(fileRead('/data/validmenus.txt'));
// Split the string by commas and convert it to an array
var arValidMenus = listToArray(fileContents, ",");
// Store the list in the application scope for global use
application.arValidMenus = arValidMenus;
}
function setupRequest() {
// Check if the 'action' parameter is present in the URL (traditional method)
if (structKeyExists(url, "action") && len(url.action) > 0) {
// Redirect to the clean, SEO-friendly URL
var actionParts = listToArray(url.action, ".");
if (arrayLen(actionParts) == 2) {
var controller = actionParts[1]; // Extract the controller
var view = actionParts[2]; // Extract the view
// Ensure no special characters (like ":" or "=") are in the controller/view
if (not reFind("^[a-zA-Z0-9_-]+$", controller) || not reFind("^[a-zA-Z0-9_-]+$", view)) {
// Perform a 404 page not found
location(url='/notfound');
}
var cleanUrl = "/" & view;
// Perform a 301 redirect to the friendly URL
location(url=cleanUrl, statusCode=301);
} else {
// Perform a 404 page not found
location(url='/notfound');
}
abort(); // Stop processing after redirect
}
}
public function before( struct rc = {} ) {
request.DSNCat =this.datasource;
// reset the application
if(structKeyExists(rc, 'resetApp')) {
structClear(application);
sessionInvalidate();
writeOutput('<h1>Appplication Reset! click to reload</h1><a href="/">reload</a>');
abort;
}
// check if no user sesssionl; setup default
if(!structKeyExists(session, 'user'))
userService.defaultUserSession();
// user session data
rc["userSession"] = variables.userService.getUserSession();
if (!utils.isAjaxRequest() && getEnvironment() === "dev" && this.debug) {
// Enable debugging for non-AJAX requests
setting showDebugOutput = true;
}
if (getEnvironment() === "prod")
botSessionManager.detectAndManageBotSessions();
}
public function after(string controller, struct rc) {
traceSessionScope(rc);
}
public function setupResponse(struct rc) {
//var isDev = getEnvironment() === "dev" ? true : false;
// botSessionManager.detectAndManageBotSessions();
}
// public string function onMissingView(struct rc = {}) {
// //return "Error 404 - Page not found.";
// return view( 'main/notFound' );
// }
// Function to trace session scope
private function traceSessionScope(rc) {
if (!utils.isAjaxRequest() && getEnvironment() === "dev" && this.debug) {
// Enable debugging for non-AJAX requests
setting showDebugOutput = true;
// Trace the session scope at the end of the request
cftrace(var = "rc.usersession", text = "rc.usersession at request end", type = "information", category = "SessionDebug");
}
}
private function setupEnvironment(string env) {
if(arguments.env eq 'prod')
this.mappings[ "/websnips" ] = "C:\inetpub\Dynaprice\shared\CodeSnips\Web";
else
this.mappings[ "/websnips" ] = "C:\Users\scott\Projects\dynaprice\shared\CodeSnips\Web"
}
private function getEnvironment() {
if ( findNoCase( "sandbox", CGI.SERVER_NAME ) or findNoCase( "capovani", CGI.SERVER_NAME ) )
return "prod";
else
return "dev";
}
}