Orchard CMS: Sign Out (Log Off) Confirmation Page

霸气de小男生 提交于 2019-12-10 15:17:29

问题


Is there an event that gets fired when a user logs off of the front end and how can I use that event to redirect the user to a particular view or page? I would like the user to receive a message that says, "You have successfully logged off" after they sign out.


回答1:


As always, there is more than one way to do this with Orchard :)

Method 1: Overriding the user shape

When you log off, you are redirected to an action method on Orchard.Users.AccountController called LogOff, which takes a returnUrl argument. The shape that contains the sign out link is under ~/Core/Shapes/Views/User.cshtml but you can override this by creating a copy of it in your theme called Views/User.cshtml (or use the shape tracing module to find this shape and create an alternate).

In your copy all you then have to do is change

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

to

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

Method 2: IUserEventHandler

For a more dynamic requirement, you could implement the Orchard.Users.Events.IUserEventHandler interface, redirecting to your confirmation page when the LoggedOut method is called:

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) { }
}

Hope it helps!



来源:https://stackoverflow.com/questions/11585608/orchard-cms-sign-out-log-off-confirmation-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!