-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApplication.cfc
122 lines (83 loc) · 3.24 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
<cfcomponent output="false">
<cfscript>
this.name = "CFCluster";
this.datasource = "CFCluster";
this.mappings['/root'] = GetDirectoryFromPath(GetCurrentTemplatePath());
this.mappings['/lib'] = this.mappings['/root'] & 'cf/lib/';
this.mappings['/core'] = this.mappings['/root'] & 'cf/core/';
this.mappings['/svc'] = this.mappings['/root'] & 'cf/serviceBus/';
this.customtagpaths = this.mappings['/root'] & 'cf/customTags';
</cfscript>
<cffunction name="onApplicationStart">
<cflog file="CFCluster" application="no" text="[onApplicationStart] #CGI.REMOTE_ADDR#">
<cfscript>
sleep(2000);
Application.svc = {};
Application.reg = {};
Application.reg = {
mongodb = "sms",
mongohost = "localhost",
mongoport = "27017"
};
Application.svc = {
SessionManager = new core.SessionManager(),
Util = new core.Util(),
User = new svc.User()
};
Application.initialized = true;
</cfscript>
</cffunction>
<cffunction name="onRequestStart" returnType="void">
<cfargument name="request" required="true" />
<cfscript>
// explicit call onApplicationStart via url.reloadApp
if(StructKeyExists(url, 'reloadApp')){
lock name="reloadApp" timeout="120" type="exclusive" {
onApplicationStart();
}
}
// force lock to queue all request when somebody hit reloadApp
lock name="reloadApp" timeout="120" type="readOnly" {}
if(StructKeyExists(url, 'logout') OR StructKeyExists(form, 'logout')){
Application.svc.SessionManager.logout();
}
// check session status
var sessionStatus = Application.svc.SessionManager.sessionStatus();
if(NOT sessionStatus.loggedIn){
// redirect if request not come from login.cfm, else process login request
if(Not IsDefined('form.login')){
include "login.cfm";
abort;
}
else {
// check user credential
var authorization = Application.svc.User.checkCredential(form.j_username,form.j_password);
if(authorization.valid){
// if authorized, create user session and update user info
var credential = Application.svc.SessionManager.login(authorization);
var sessionData = Application.svc.User.getUserData(credential);
Application.svc.SessionManager.setSession(sessionData);
}
else {
// if user not authorized, redirect to login.cfm and display error message
var loginError = true;
include "login.cfm";
abort;
}
}
}
else {
// if user already logged in, update timeactive and check session timeout
Application.svc.SessionManager.setSession({"lastactive"=Now()});
}
</cfscript>
<cflog file="CFCluster" application="no" text="[onRequestStart]">
</cffunction>
<cffunction name="onApplicationEnd" returnType="void">
<cfargument name="ApplicationScope" required=true/>
<!--- close mongodb connection --->
<cfscript>
ApplicationScope.svc.SessionManager.closeConnection();
</cfscript>
</cffunction>
</cfcomponent>