Orchard CMS:注销(注销)确认页面 [英] Orchard CMS: Sign Out (Log Off) Confirmation Page

查看:95
本文介绍了Orchard CMS:注销(注销)确认页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户注销前端时是否会触发一个事件,并且如何使用该事件将用户重定向到特定的视图或页面?我希望用户注销后收到一条消息,说您已成功注销".

解决方案

与往常一样,使用Orchard可以使用多种方法:)

方法1:覆盖用户形状

注销时,将重定向到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" })

方法2: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) { }
}

希望有帮助!

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.

解决方案

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!

这篇关于Orchard CMS:注销(注销)确认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆