如何为使用SIRD路由的控制器创建绝对URL

时间:2018-08-31 20:37:03

标签: playframework-2.6

我已经创建了一个SIRD路由器

class UserRouter @Inject()(controller:UserController) extends SimpleRouter {

  override def routes:Routes = {
    case GET (p"/signup/$token") =>{  //corresponds to email verification from user after sign up. This was the URL which the server had sent
      println("add user request with token"); //TODOM - print token
      controller.verifyUser(token); //
    }

  }
}

它被称为网址/ws/users/signup/sometokenvalue

我想验证用户的电子邮件ID,并希望通过电子邮件发送一个URL,该URL应与GET映射到domain.com/ws/users/signup/sometokenvalue请求。我该如何在Play / Scala中做到这一点?

目前,我正在手动创建url,但是它显然不可扩展且容易出错。

val url = s"http://localhost:9000/ws/users/signup/${userToken.tokenId}";
val html =s"<a href=${url}>Click here to verify email</a>"
println("html is "+html)
val email = mailerService.sendEmail("welcome","signup@mydomain.com",List(user.profile.externalProfileDetails.email),Some(userToken.toString),Some(html))

0 个答案:

没有答案