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

原文地址:http://javaz.cn/site/javaz/site_study/info/2016/44988.html

 

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

在模板中增加会员登录功能

 

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

<span id="memberSpan">

<@ajaxLoad targetid="memberSpan" url="/site/${site.sourcepath}/member.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_loginMember??>

<!-- 已登录 -->

${session_loginMember.loginname}

  <a href="${contextPath}mlogout.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}mlogin.do",data,loginComplete,"text");

                     return false;

            }

                            function loginComplete(data){

                                     if(""==data){

                                                        $.get('/site/demo/member.fhtml',{},ajaxLoadCompleteMember,'text');function ajaxLoadCompleteMember (data){$('# memberSpan').html(data);}

                                     }else{

                                               alert(data);

                                     }

                            }

</script>

<form  action="${contextPath}mlogin.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商业版在模板中增加会员登录功能)