我正在认真考虑放弃CF8 cflogin,因为它与产生登录名的服务器绑定在一起。在负载平衡的环境中,如果不执行自定义实现,则将陷入粘性会话。

是否有人有模仿CFLogin的源,该源写入并通过客户端作用域进行管理?甚至一个与isuserin [any] role上的重命名替换匹配得很好的设计。

当我考虑为CFLogin编写替代实现时应该考虑什么?

最佳答案

这是使用CLIENT范围中存储的变量的基本非cflogin方法。对于负载均衡器后面的服务器群集中的非粘性会话,我们使用类似的方法。

此代码应存在于Application.cfc-> onRequestStart()方法中:

<!--- handle login *post* --->
<cfif structKeyExists(FORM, "pageaction") and FORM.pageAction eq "adminlogin">

<!--- attempt to log user in --->

    <cfif loginSuccessful>

        <!--- Set client variables for session management --->
        <cfset CLIENT.lastHit = now() />
        <cfset CLIENT.loggedIn = 1 />

        <!--- redirect to home page --->

    <cfelse>

        <!--- redirect to login page with message --->

    </cfif>

<!--- all other requests, except for the login page --->
<cfelseif structKeyExists(CLIENT, "lasthit") and structKeyExists(COOKIE, "cfid") and structKeyExists(CLIENT, "cfid") and listLast(CGI.SCRIPT_NAME, "/") neq "login.cfm">

    <!--- Check for timeout --->
    <cfif (datediff("n", CLIENT.lastHit, now()) lte 10) and (CLIENT.loggedIn is 1) and (CLIENT.cfid is COOKIE.cfid)>

        <!--- record last hit --->
        <cfset CLIENT.lastHit = now() />

    <cfelse>

        <!--- timeout! redirect to login page --->
        <cflocation URL="http://mydomain/login.cfm" addtoken="false" />

    </cfif>

</cfif>


有一些用户角色的内容,但是我希望这可以作为一个起点。

关于coldfusion - 是否需要更换CFLogin或我缺少什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4094132/

10-13 05:31