【发布时间】:2014-09-22 12:35:00
【问题描述】:
我正在使用 SecureSocial(主版本)编写一个 Play 2.3 应用程序。 我在我的系统中创建了一个代表用户数据的 LoginUser。
/**
* Class representing a User in the system.
* @constructor Create a new LoginUser instance from a BasicProfile object.
* @param profile represents the BasicProfile object associated with the user.
*/
case class LoginUser(val profile: BasicProfile)
现在我正在尝试实现(SecureSocial 的)UserService[T] 特征,但我遇到了麻烦。
/**
* Class tha handle all the request for read/write user data in/from the database.
*/
class InMemoryUserService extends UserService[LoginUser] {
private var tokens = Map[String, MailToken]()
/**
* Finds a user by provider id and user id.
* @param providerId - the user provider id.
* @param userId - the user user id.
* @return an optional user
*/
def find(providerId: String, userId: String): Future[Option[BasicProfile]] = {
val future: Future[Option[LoginUser]] = UserServiceLogin.find(Json.obj("providerId" -> providerId, "userId" -> userId)).one
future onComplete {
case Success(Some(x)) => return x.profile
case _ => None
}
}
find 方法返回一个 Future[Option[BasicProfile]] 对象,但编译器告诉我代码不正确。 这里是编译器的输出:
[error] /Users/alberto/git/recommendation-system/app/security/UserService.scala:68: type mismatch;
[error] found : securesocial.core.BasicProfile
[error] required: scala.concurrent.Future[Option[securesocial.core.BasicProfile]]
[error] case Success(Some(x)) => return x.profile
怎么了?? 我该如何解决我的问题??
【问题讨论】:
标签: scala securesocial