2016-04-29 13 views
0

私はgrails 3インターセプタを使って最初のログイン時にユーザメールをキャプチャしようとしていましたが、彼らはログインして、設定されたホームページではなく電子メールキャプチャフォームにリダイレクトされます。私は春のセキュリティを使用している場合は、関連情報です。私のコードスニペットは、私がこれまで行ってきたことを示しています。私の目標を達成するための簡単な方法や私が間違ったことがあるかどうか、私に助言してください。grails 3インターセプタを使用してフォームを実行し、grailsアプリケーションの通常の流れを再開する方法

class HomeInterceptor { 

public HomeInterceptor() { 
    // match all requests except requests 
    // to the auth controller 
    matchAll().excludes(controller: 'logout') 
      .excludes(controller: 'login') 
      .excludes(controller: 'home') 
      .excludes(controller: 'user', action: 'userProfile') 
      .excludes(controller: 'user', action: 'showUserProfile') 
} 

boolean before() { 
    // if the user's email has not been captured, 
    // redirect to the user profile 

    def springSecurityService = AppHolder.bean(SpringSecurityService) 
    def loggedInUser = springSecurityService.currentUser as User 

    if (loggedInUser?.email == null){ 
     flash.message = "Please enter your email before you can proceed" 
     redirect(controller: 'user', action: 'userProfile') 
     return false 
    }else { 
     return true 
    } 
} 

boolean after() { true } 

void afterView() { 
    // no-op 
} 

}

答えて

1

役立ちました。この

import grails.web.mapping.LinkGenerator 

class HomeInterceptor { 

def springSecurityService 
LinkGenerator grailsLinkGenerator 

public HomeInterceptor() { 
// match all requests except requests 
// to the auth controller 
matchAll().excludes(controller: 'logout') 
     .excludes(controller: 'login') 
     .excludes(controller: 'home') 
     .excludes(controller: 'user', action: 'userProfile') 
     .excludes(controller: 'user', action: 'showUserProfile') 
} 

boolean before() { 

if (!springSecurityService.principal.email){ 
    flash.message = "Please enter your email before you can proceed" 
    response.sendRedirect("${grailsLinkGenerator.link(controller:'user',action:'userProfile')}") 
    return false 
}else { 
    return true 
} 
} 
} 
+0

おかげで、同じようにそれを試してみてください –

関連する問題