【发布时间】:2020-07-15 11:34:16
【问题描述】:
我想在这部分代码中添加当前 URL(returnTo - 字符串类型):href="@routes.AuthenticationController.login(**returnTo**)"。我想在登录后使用它重定向到请求的 URL。现在,如果用户未登录,则会在页面上收到未经授权的 403 消息,并且必须使用登录按钮将他们重定向到登录页面。
例如,如果我在 http://localhost:9000/getByProductId/43,登录后我想进入这个页面。
登录功能如下:
public static Result login(String returnTo) {
return ok(views.html.forms.loginForm.render(form(Login.class), returnTo));
}
限制消息的页面如下所示
<div class="hero-unit center">
<h1>Access Restricted <small><font face="Tahoma" color="red">Unauthorized 403</font></small></h1>
<br />
@if(User.findCurrentUser() == null || User.findCurrentUser().getIdentifier() == null) {
<p>You have to login first to access this functionality.</p>
<p>
<a href="@routes.AuthenticationController.login(**returnTo**)" class="btn btn-large btn-info" ><i class="icon-home icon-white"></i> Log in</a>
}
【问题讨论】:
-
应用使用的是哪个播放版本?它是否在进行重定向以呈现该页面?
标签: java playframework