2012-10-23 2 views
0

양식 도우미에 어려움이 있습니다. 내가보기에 전달하기 전에 양식에 오류를 추가 할 수 있지만 다음과 같은 오류 얻을 :Play Framework : Form withGlobalError

value withGlobalError is not a member of play.api.data.Form[(String, String)] 

다음과 내가 가진 코드가 될 때 :

def loginForm = Form(
      tuple (
       "email" -> nonEmptyText, 
       "password" -> nonEmptyText 
      ) 
    ) 


def asignIn = Action { 
     implicit request => 
     loginForm.bindFromRequest.fold (
       formWithErrors => Ok(views.html.login(formWithErrors.withGlobalError("Invalid username or password")), 
       user => authenticationStep(user)(request) 
    ) 
    } 

답변

1

이메일의 검증 및 비밀 번호는 다음과 같은 형식으로 이루어져야합니다 :

val loginForm = Form(
    tuple(
    "email" -> nonEmptyText, 
    "password" -> text 
) verifying("Invalid user name or password", fields => fields match { 
     case (email, pwd) => User.authenticate(email,pwd).isDefined 
    }) 
) 
+0

왜냐하면 내가'authent'가 반환하는 객체에서'id'를 반환 할 수 없기 때문입니다. – Andrew

+0

글쎄,'id'를 원하면'loginForm'에서 얻은 값을 사용하여'asignIn' 함수에서 얻을 수 있습니다. –

+0

'asignIn'의'user'는 제 객체를 포함하고 있습니까? 내가 테스트 한 내용에는 터플 (이메일, 비밀번호)이 포함되어 있습니다. 당신이 나에게 그것을 제안하는 방식은 동일한 요청을 두 번해야합니다. – Andrew