2010-12-31 5 views
1

symfony 기반 응용 프로그램에서 webservice를 개발하려고합니다. sfguarduser 플러그인을 사용하고 있으며, 사용자 권한을 확인하고 실행하기 위해 단일 샷 요청으로 인증 된 사용자 자격 증명을 얻고 싶습니다. webservice 조치, html 양식 로그인없이 로그인 작업을 수행 할 수있는 방법이 있습니까? 액션에서http 로그인없이 sfguarduser로 인증합니다.

답변

5

는 다음을 수행하십시오

$this->getUser()->signin($sfGuardUserObject); 

당신은 sfGuardUser의 객체로 호출해야한다. 이 코드를 모듈의 preExecute() 메소드에 넣어 각 요청을 확인할 수 있습니다.

나는 "계정 활성화"작업을 수행 할 때 비슷한 작업을 수행했습니다. 계정 생성 후 토큰이있는 전자 메일은 사이트로 다시 연결됩니다. 토큰은 URL로 전송되고 액션 경로와 일치합니다. 그런 다음 사용자가 해당 토큰을 가지고 있는지 확인한 다음 사용자를 기록합니다. 내가 한 일입니다.

public function executeActivate(sfWebRequest $request) 
{ 
    // if token is not present, forward to 404 
    $this->forward404Unless($request->getParameter('token'), 'page', 'index'); 

    $this->profile = sfGuardUserProfilePeer::activateProfileByToken($request->getParameter('token')); 

    // if someone was activated, return the mobile activation form and success page 
    if (!$this->profile) 
    { 
    $this->redirect404(); 
    } 

    // sign the user in 
    $this->getUser()->signin($this->profile->getsfGuardUser()); 

    // set the $user variable for the template 
    $this->user = $this->profile->getsfGuardUser(); 

} 

희망이 있습니다.

+1

좋은 답변입니다. BTW,'sfAction :: forward404If'는 당신이 그것에 대해 모른다면 편리한 방법입니다. –

+0

미안하지만 대답하지 않고서는이 모든 시간 동안 미안 해요, 조금 바빴습니다. 요즘 내가했던 것을 기억하지 못합니다.하지만 정답으로 답을 표시 할 것입니다. 합법적 인 소리, 감사합니다 .-) – markcial

관련 문제