Geo*_*Geo 1 coldfusion cflogin coldfusion-9
我正在使用我公司之前在使用框架的网站上使用的非常旧的登录系统.之前,当有人尝试错误的用户/传递组合时,框架会加载一个简单的cfinclude文件,其中包含登录表单和错误消息.现在我在弹出窗口中使用一个调用application.cfc的表单,但是不是在弹出窗口中返回错误消息,页面将cfinclude文件从应用程序组件加载到新页面.
所以我需要为这个应用程序做一些事情.首先,我需要初始弹出窗口保持不动,如果用户/传递的组合错误,页面不应该提交,最后我需要在弹出窗口的某处出现错误消息.
如果有人做过这样的事情之前我真的很感激你的意见.
这是我的代码的一部分:
登录表格:
<!--- loginErrMsg display - to tell why login is denied --->
<cfif isdefined("loginErrMsg")><span style="color:red">#loginErrMsg#</span><br /></cfif>
<form name="LoginForm" id="LoginForm" action="<cfif test is false>https://secure.example.com</cfif>#loginFormAction#" method="post" target="_top">
</cfoutput>
<input type="hidden" name="loginPost" value="true">
<p>
Login below to take advantage of the great services we offer:
</p>
E-mail:<input name="j_username" class="loginform" type="text" size="30" maxlength="50" id="j_username">
Password: <input name="j_password" type="password" size="30" maxlength="16" class="loginform">
<br />
<input type="submit" name="btn" value="Submit" class="bluebuttonnormal">
</form>
Run Code Online (Sandbox Code Playgroud)
Application.cfc代码:
<cflogin applicationtoken="swmadmin">
<cfif NOT IsDefined("cflogin")>
<cfinclude template="login.cfm">
<cfabort>
<cfelse>
<cfquery name="userlookup" datasource="#ds#">
SELECT clientadminID, roles, isFaxOnly, acctEnabled FROM clientadmin
WHERE
username=<cfqueryparam value="#cflogin.name#" CFSQLTYPE="CF_SQL_VARCHAR" maxlength="50">
and password=<cfqueryparam value="#cflogin.password#" CFSQLTYPE="CF_SQL_VARCHAR" maxlength="16">
</cfquery>
<cfif userlookup.recordcount eq 0>
<cfset loginErrMsg = "Invalid login.">
<cfinclude template="login.cfm">
<cfabort>
</cflogin>
Run Code Online (Sandbox Code Playgroud)
我正在使用我公司之前在使用框架的网站上使用的非常旧的登录系统.
如果这是一个新网站,请不要使用它.登录表格是一打一打,可以在你睡觉时完成.重新开始并正确行事.
所以我需要为这个应用程序做一些事情.首先,我需要初始弹出窗口保持不动,如果用户/传递的组合错误,页面不应该提交,最后我需要在弹出窗口的某处出现错误消息.
你可能想在这里使用AJAX解决方案,要么自己编写,要么使用像jQuery这样的好库.检查登录值后,您可以使用jQuery或简单的javascript来取消隐藏或更新空元素的innerHTML以显示您的错误消息.
<cflogin ...>
...
</cflogin>
Run Code Online (Sandbox Code Playgroud)
CFLogin让我难过.ColdFusion的另一个标签旨在简化通常所做的事情,这些事情并没有真正帮助太多并且牺牲了灵活性.没有它,您可以更好地控制您的应用程序.而不是CFLogin,尝试类似这样的伪代码
<cfcomponent>
<cffunction name = "onRequest" ...>
<cfargument name="targetPage" type="String" required = "true" />
<cfif !structKeyExists(session, "roles") and !findNoCase("loginHandler.cfm",cgi.script_name)>
<!--- notice I prevent the redirect on the form handler, otherwise the ajax will get redirected to the login.cfm page --->
<cfinclude template = "login.cfm">
<cfelse>
<cfinclude template = "#arguments.targetPage#">
</cfif>
</cffunction>
</cfcomponent>
Run Code Online (Sandbox Code Playgroud)
然后你的login.cfm会包含你的表单,但你的按钮会激活jQuery.post()到"loginHandler.cfm",然后根据登录结果,你的回调函数可能会使用jQuery.html()来显示如果登录成功,则返回error或window.location.replace/window.location.href.当然,如果成功登录,您的ColdFusion页面必须创建会话变量,并在将结果发送回AJAX调用之前执行您希望它执行的任何操作.