<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    asdtiang的博客 感謝blogjava提供的博客交流平臺

    grails acegi ajax登錄

    Posted on 2011-01-07 14:47 asdtiang 閱讀(749) 評論(2)  編輯  收藏 所屬分類: grails study
    js代碼如下:

    <script type='text/javascript'>
    /////ajax登錄js
        function showLogin() {
            $('ajaxLogin').style.display 
    = 'block';
        }

        
    function onSuccessfulLogin(url) {
            
    //alert(url);
            document.form1.action=url;
            document.form1.submit();
        }


        
    function authAjax() {
            
    var form = document.ajaxLoginForm;
            
    var params = Form.serialize(form)
                    
    + '&spring-security-redirect=/login/ajaxSuccess';
            
    //Form.disable(form);
            new Ajax.Request(form.action, {
                method : 'POST',
                postBody : params,
                onSuccess : 
    function(response) {
                    
    var responseText = response.responseText || '[]';
                    
    var json = responseText.evalJSON();
                    
    if (json.success) {
                        
    //alert("ok");
                        onSuccessfulLogin(json.url);
                    }
     else if (json.error) {
                        alert(json.error);
                        Form.enable(document.ajaxLoginForm);
                    }
     else {
                        Element.update('loginMessage', responseText);
                        Form.enable(document.ajaxLoginForm);
                    }

                }

            }
    );
        }

    </script>

    login代碼示例:

    def ajaxSuccess = {
            nocache(response)
            def config 
    = authenticateService.securityConfig.security
            def postUrl 
    = "${request.contextPath}${config.defaultTargetUrl}"
            render 
    "{success: true,url:'${postUrl}'}"http://這里返回的是json
        }




    def authfail 
    = {

            def username 
    = session[AuthenticationProcessingFilter.SPRING_SECURITY_LAST_USERNAME_KEY]
            def msg 
    = ''
            def exception 
    = session[AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY]
            
    if (exception) {
                
    if (exception instanceof DisabledException) {
                    msg 
    = "[$username] 用戶被禁用."
                }

                
    else {
                    msg 
    = "[$username] 錯誤的用戶名或密碼."
                }

            }


            
    if (isAjax()) {
                render 
    "{error: '${msg}'}"
            }

            
    else {
                flash.message 
    = msg
                redirect action: auth, params: params
            }

        }






    頁面:
     

    <form id="form1" name="form1" target="_blank"></form>

    <form action='${request.contextPath}/j_spring_security_check'

        method='POST' id='ajaxLoginForm' name='ajaxLoginForm' target="_blank">

    用戶名<input id="j_username" name="j_username" type="text" />   

    &nbsp;&nbsp;&nbsp;&nbsp;<input name="j_password" id="j_password" type="password" /><input onclick='authAjax(); return false;'type="image" src="login.jpg" />

    </form>


    暫時想不起來為什么用兩個form呢,最后引入js:<g:javascript library="prototype" />



    天蒼蒼,野茫茫,風吹草底見牛羊

    Feedback

    # re: grails acegi ajax登錄[未登錄]  回復  更多評論   

    2011-05-14 19:24 by oksonic
    你好,看了這篇文章,實際了登錄跳轉,非常感謝。
    但我不能明白的是authfail為什么實現不了?

    # re: grails acegi ajax登錄  回復  更多評論   

    2011-05-18 21:59 by asdtiang
    代碼貼出來看下,不過,我想應該解決了吧

    posts - 80, comments - 24, trackbacks - 0, articles - 32

    Copyright © asdtiang

    asdtiang的博客 PaidMailz
    點擊廣告網賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
    主站蜘蛛池模板: 亚洲日韩精品无码专区| 99在线视频免费观看视频| 一本色道久久综合亚洲精品蜜桃冫| 毛茸茸bbw亚洲人| 在线看片无码永久免费aⅴ | 亚洲成人高清在线观看| 伊人亚洲综合青草青草久热| 日本免费一区二区三区最新vr| h视频在线观看免费完整版| 国产一二三四区乱码免费| 国产成人亚洲毛片| 亚洲中文字幕无码久久2020| 亚洲精品自拍视频| 国产精品国产自线拍免费软件| 午夜国产精品免费观看| 16女性下面无遮挡免费| 日本在线免费观看| 久爱免费观看在线网站| 国产免费网站看v片在线| 一级特黄录像免费播放肥| 美女黄色毛片免费看| 国产亚洲精彩视频| 精品亚洲国产成人av| 国产亚洲视频在线观看| 理论亚洲区美一区二区三区 | 永久久久免费浮力影院| 成人免费视频77777| aa级一级天堂片免费观看| 一个人免费观看www视频在线| 国产精品免费观看| 午夜福利不卡片在线播放免费| 男女做羞羞的事视频免费观看无遮挡| 免费观看激色视频网站(性色)| 1000部拍拍拍18勿入免费视频下载 | 久久精品免费一区二区| 亚洲免费观看网站| 色窝窝免费一区二区三区| 成人无码区免费A片视频WWW| 天天干在线免费视频| 国产免费变态视频网址网站| 亚洲国产精品成人|