Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active April 14, 2022 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/11192d6be09b3d3c97c3392bea21b8e1 to your computer and use it in GitHub Desktop.
Save JamoCA/11192d6be09b3d3c97c3392bea21b8e1 to your computer and use it in GitHub Desktop.
Simple one-page ColdFusion CFLogin demo #cfml
<!--- 20220414 Simple one-page ColdFusion CFLogin demo #cfml
Responding to https://tracker.adobe.com/#/view/CF-4213180
A CFLogin object with "name" & "password" doesn't exist, but ACF documentation references it.
CFLogin Documentation:
https://cfdocs.org/cflogin
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-j-l/cflogin.html
https://docs.lucee.org/reference/tags/login.html
--->
<cfif form.keyExists("logout")>
<cflogout>
<p style="color:red;">You have been logged out.</p>
</cfif>
<cfoutput>
<p>PRE: isDefined("cflogin") = #isDefined("cflogin")#</p>
</cfoutput>
<cflogin>
<cfif form.keyExists("logout")>
<cfelseif form.keyExists("j_username") and form.keyExists("j_password")>
<cfloginuser name="#form.j_username#" Password="#form.j_password#" roles="myRole">
</cfif>
</cflogin>
<cfoutput>
<p>POST: isDefined("cflogin") = #isDefined("cflogin")#</p>
</cfoutput>
<cfif not isUserLoggedIn()>
<cfoutput>
<form action="#CGI.script_name#<cfif len(CGI.query_string)>?#CGI.query_string#</cfif>" method="post">
<input name="j_username" value="me" required placeholder="Username" autocomplete="username"><br>
<input name="j_password" value="myPW" required placeholder="password" autocomplete="current-password"><br>
<button type="submit">Log on</button>
</form>
</cfoutput>
<cfexit>
</cfif>
<cfoutput>
<h2>Welcome "#GetAuthUser()#"!</h2>
<p><b>Roles:</b> #replace(getUserRoles(),",", ", ","all")#</p>
<form action="#CGI.script_name#<cfif len(CGI.query_string)>?#CGI.query_string#</cfif>" method="post">
<button type="submit" name="logout">Log out</button>
</form>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment