4

当用户从前端注销时是否会触发事件,我如何使用该事件将用户重定向到特定视图或页面?我希望用户在注销后收到一条消息,上面写着“您已成功注销”。

4

1 回答 1

7

与往常一样,Orchard 有不止一种方法可以做到这一点:)

方法一:覆盖用户形状

当您注销时,您将被重定向到Orchard.Users.AccountController被调用的操作方法LogOff,该方法接受一个returnUrl参数。包含退出链接的形状在下方,~/Core/Shapes/Views/User.cshtml但您可以通过在名为的主题中创建它的副本来覆盖它Views/User.cshtml(或使用形状跟踪模块来查找此形状并创建替代)。

在你的副本中,你所要做的就是改变

@Html.ActionLink(T("Sign Out").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl }, new { rel = "nofollow" })

@Html.ActionLink(T("Sign Out").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = "/My/LogOff/Confirmation/Page" }, new { rel = "nofollow" })

方法二:IUserEventHandler

对于更动态的需求,您可以实现接口,在调用该方法Orchard.Users.Events.IUserEventHandler时重定向到您的确认页面:LoggedOut

public class LoggedOutRedirect : IUserEventHandler
{
    private readonly IHttpContextAccessor _httpContext;
    public LoggedOutRedirect(IHttpContextAccessor httpContext)
    {
        _httpContext = httpContext;
    }

    public void LoggedOut(IUser user)
    {
        _httpContext.Current().Response.Redirect("http://www.google.com/");
    }

    public void Creating(UserContext context) { }
    public void Created(UserContext context) { }
    public void LoggedIn(IUser user) { }
    public void AccessDenied(IUser user) { }
    public void ChangedPassword(IUser user) { }
    public void SentChallengeEmail(IUser user) { }
    public void ConfirmedEmail(IUser user) { }
    public void Approved(IUser user) { }
}

希望能帮助到你!

于 2012-07-21T11:03:29.920 回答