首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ColdFusion 9中的登录系统

ColdFusion 9中的登录系统
EN

Stack Overflow用户
提问于 2013-01-19 05:35:00
回答 1查看 1.9K关注 0票数 1

我正在使用一个非常旧的登录系统,我的公司以前在一个使用框架的网站上使用。以前,当有人尝试错误的用户/通行证组合时,框架会加载一个简单的cfinclude文件,其中包含登录表单和一条错误消息。现在,我在一个弹出窗口中使用一个表单,该表单调用application.cfc,但是页面将cfinclude文件从应用程序组件加载到一个新页面,而不是在弹出窗口中返回错误消息。

所以我需要为这个应用程序做一些事情。首先,我需要初始弹出窗口保持向上,如果用户/通行证的组合是错误的,页面不应该提交,最后我需要错误信息出现在弹出窗口的某个地方。

如果有人以前做过这样的事情,我将非常感谢您的反馈。

这是我的代码的一部分:

登录表单:

代码语言:javascript
运行
复制
<!--- 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>

Application.cfc代码:

代码语言:javascript
运行
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-19 12:03:51

我正在使用一个非常旧的登录系统,我的公司以前在一个使用框架的网站上使用过它。

如果这是一个新网站,不要使用它。登录表单一毛钱一打,可以在睡眠中完成。重新开始,做正确的事情。

所以我需要为这个应用程序做一些事情。,

。首先,我需要初始弹出窗口保持向上,如果用户/通行证的组合是错误的,页面不应该提交,最后我需要错误信息出现在弹出窗口的某个地方。

在这里,您将需要使用AJAX解决方案,要么编写自己的解决方案,要么使用像jQuery这样的好库。一旦检查了登录值,就可以使用jQuery或simple javascript取消隐藏或更新空元素的innerHTML以显示错误消息。

代码语言:javascript
运行
复制
<cflogin ...>
...
</cflogin>

CFLogin让我很难过。ColdFusion的另一个标签旨在简化一些通常做的事情,这些事情实际上没有太多帮助,并牺牲了灵活性。您可以在没有它的情况下对应用程序进行更多的控制。尝试如下伪代码,而不是CFLogin

代码语言:javascript
运行
复制
<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>
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14408020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档