-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.cfc
More file actions
89 lines (70 loc) · 3.4 KB
/
auth.cfc
File metadata and controls
89 lines (70 loc) · 3.4 KB
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
<cfcomponent hint="Slate REST authentication integration" output="false">
<!--- Built by Jason Quatrino on 8/25/2017 based on Slate REST Authentication Documentation found at:
https://technolutions.zendesk.com/hc/en-us/articles/216174348-Slate-authentication-service#article-comments
--->
<cfset requestURL = "https://admission.hamilton.edu/" />
<cffunction name="authUser" returntype="struct" output="false">
<cfargument name="username" type="string" required="true" />
<cfargument name="password" type="string" required="true" />
<cfset local.results = {} />
<cfset local.results.msg = "" />
<cfset local.results.isAuth = false />
<cfset local.results.slateData = {} />
<cfif Len(arguments.username)>
<cfif Len(arguments.password)>
<cftry>
<cfhttp url="#requestURL#account/rest/login" method="post" result="local.httpResult">
<cfhttpparam type="url" name="user" value="#arguments.username#" />
<cfhttpparam type="url" name="password" value="#arguments.password#" />
</cfhttp>
<cfcatch type="any">
<cfset local.results.msg &= "AuthUser HTTP ERROR: #cfcatch.message#" />
<cfreturn local.results />
</cfcatch>
</cftry>
<cfif structKeyExists(local.httpResult,"errordetail") AND Len(local.httpResult.errordetail)>
<cfset local.results.msg &= "AuthUser HTTP ERROR: #local.httpResult.errordetail#" />
<cfelse>
<cfif structKeyExists(local.httpResult,"filecontent") AND Len(local.httpResult.filecontent)>
<cfif isValid("xml",local.httpResult.filecontent)>
<!--- parse results --->
<cfset local.results.slateData = parseSlateXML(XMLParse(local.httpResult.filecontent)) />
<!--- expected xml results:
status = "SUCCESS" - (id/ref/status/user)
status = "ERROR" - (message,status)
--->
<cfset local.results.isAuth = isSuccessfulLogin(local.results.slateData.status) />
<cfset local.results.msg &= local.results.slateData.status />
<cfif StructKeyExists(local.results.slateData,"message")>
<cfset local.results.msg &= ": #local.results.slateData.message#" />
</cfif>
<cfelse>
<cfset local.results.msg &= " AuthUser File Content ERROR: Invalid XML." />
</cfif>
<cfelse>
<cfset local.results.msg &= " AuthUser File Content ERROR: Unexpected result." />
</cfif>
</cfif>
<cfelse>
<cfset local.results.msg &= " AuthUser Argument ERROR: password is required." />
</cfif>
<cfelse>
<cfset local.results.msg &= " AuthUser Argument ERROR: username is required." />
</cfif>
<cfreturn local.results />
</cffunction>
<cffunction name="parseSlateXML" returntype="struct" output="false">
<cfargument name="slateXML" type="xml" required="true" />
<cfset local.slateResults = {} />
<cfset local.slateResults.status = "" /><!--- ensure that results always have a status. referenced to determine successful authentication --->
<cfset local.resultNodes = arguments.slateXML.result />
<cfloop array="#local.resultNodes.XMLChildren#" item="i">
<cfset local.slateResults[i.xmlName] = i.xmlText />
</cfloop>
<cfreturn local.slateResults />
</cffunction>
<cffunction name="isSuccessfulLogin" returntype="boolean" output="false">
<cfargument name="slatestatus" type="string" required="true" /><!--- success/error flag from Slate --->
<cfreturn (arguments.slatestatus == "SUCCESS" ? true : false) />
</cffunction>
</cfcomponent>