开源 java CMS - FreeCMS商业版在模板中增加后台管理员登录功能

项目地址:http://www.freeteam.cn/

 

在需要添加登录功能页面模板中添加以下代码

<span id="adminSpan">

<@ajaxLoad targetid="adminSpan" url="/site/${site.sourcepath}/admin.fhtml" ;code>${code}</@ajaxLoad>

</span>

 

此方法用到了ajax需要引入jquery.js

引入方法

<script type="text/javascript" src="${contextPath}js/jquery-1.5.1.min.js"></script>

 

在模板目录下创建admin.html模板文件,代码如下

 

<!-- 这是基本的功能,需要其它的可以自己添加 -->

<#if session_loginAdmin??>

<!-- 已登录 -->

${session_loginAdmin.loginname}

<a href="${contextPath}logout.do">退出</a>

<#else>

<!-- 未登录 -->

<script>

 

            function formSubmit(){

                                     if($.trim($("#username").val())==""){

                                               alert("请输入用户名!");

                                               return false;

                                     }

                                     if($.trim($("#password").val())==""){

                                               alert("请输入密码!");

                                               return false;

                                     }

                                     if($.trim($("#ValidateCode").val())==""){

                                               alert("请输入验证码!");

                                               return false;

                                     }

                                               var data="loginname="+$("#username").val()+"&pwd="+$("#password").val()

                                               +"&ValidateCode="+$("#ValidateCode").val();

                                               $.post("${contextPath}login.do",data,loginComplete,"text");

                     return false;

            }

                            function loginComplete(data){

                                     if(""==data){

                                    

                       $.get('/site/demo/admin.fhtml',{},ajaxLoadCompleteAdmin,'text');function ajaxLoadCompleteAdmin(data){$('#adminSpan').html(data);}

                                     }else{

                                               alert(data);

                                     }

                            }

</script>

<form  action="${contextPath}login.do" method="post" onSubmit="return formSubmit();">

         用户名<input type="text" id="username" name="loginname" placeholder="用户名">

密码<input type="password" id="password" name="pwd" placeholder="密码">

验证码<input type="text" id="ValidateCode" name="ValidateCode" style="width:50px" maxlength="4" placeholder="验证码">

      <img src="${contextPath}image.jsp" title="点击重新获取验证码" style="cursor:hand" onclick="this.src='${contextPath}image.jsp?date='+new Date();"/>

    

        <button class="btn btn-block btn-large btn-primary"  type="submit"  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</button>

  </form>

 

</#if>

你可能感兴趣的:(开源 java CMS - FreeCMS商业版在模板中增加后台管理员登录功能)