1
votes

I have an Orchard CMS for my website and need help redirecting users after they log in, log out and create new profiles. I am using the "Profile" Module within Orchard Admin page.

Currently I think the code sends users to whatever the last page was they were on before they hit the link "sign in." Same with "Sign Out." I want people to be redirected to the home page after sign in, sign out and create a new registration.

I am fairly certain it lives within the following file Core\Shapes\Views\User.cshtml. Can someone explain how to edit it (if this is in fact the right thing to edit) to re-direct users to the home page? Thanks for the help.

1

1 Answers

2
votes

I guess easy way to do it would be by implementing IUserEventHandler inside your module. Create a class LogInRedirect and implement a method LoggedIn. Like so:

using System.Web.Mvc;
using Orchard.Mvc;
using Orchard.Security;
using Orchard.Users.Events;

namespace Orchard.Users {
    public class LogInRedirect : IUserEventHandler
    {
        private readonly IHttpContextAccessor _httpContext;
        public LoggedOutRedirect( IHttpContextAccessor httpContext )
        {
            _httpContext = httpContext;
        }

        public void LoggedIn( IUser user )
        {
            UrlHelper urlHelper = new UrlHelper( _httpContext.Current().Request.RequestContext );
            _httpContext.Current().Response.Redirect( urlHelper.RequestContext.HttpContext.Request.ApplicationPath + "/yourController/yourAction" );
        }

        public void Creating( UserContext context ) { }
        public void Created( UserContext context ) { }
        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 ) { }
        public void LoggedOut( IUser user ){ }
    }
}