|
|
I know this question has been asked before, just want to know exactly how.
So the answer would be: Create a custom module override to MembershipService ?
But imagine I will create a custom module call "MyModule", so I will then create MVC views/controllers in my module, correct?
However where should I override the MembershipService class?
In this case, do I need to create a custom Register/Login Views and Controllers in my module?
How to replace the default Orchard Register/Login pages?
Sorry too many questions...
Thanks!
|
|
Developer
Jan 26 at 11:52 AM
|
Create a custom module override to MembershipService ?
Yes, then use OrchardSuppressDependency
You can replace them with your own like how I have done with the Shapes Class in my Open authentication module.
builder.Describe("LogOn") .OnDisplaying(displaying => {
var shape = displaying.Shape; var metadata = displaying.ShapeMetadata;
shape.ClientsData = clientsData;
metadata.Type = "OpenAuthLogOn"; });
builder.Describe("Register") .OnDisplaying(displaying => {
var shape = displaying.Shape; var metadata = displaying.ShapeMetadata;
shape.ClientsData = clientsData;
metadata.Type = "OpenAuthRegister"; });
|
|
|
|
Hi,
Is this what you mean?
1. Create and register a new module call MyModule;
2. Create a controller call: AccountModule.cs, and add following code (copied from src\Modules\Orchard.Users\Controllers\AccountController.cs)
3. Note it has been modified by adding a OrchardSuppressDependency.
However it doesn't work, the LogOn class hasn't been triggered at all (when debugging it).
namespace MyModule.Controllers
{
[OrchardSuppressDependency("Orchard.Users.Controllers.AccountController")]
public class AccountController : Controller
{
private readonly IAuthenticationService _authenticationService;
private readonly IMembershipService _membershipService;
private readonly IUserService _userService;
private readonly IOrchardServices _orchardServices;
private readonly IEnumerable<IUserEventHandler> _userEventHandlers;
public AccountController(
IAuthenticationService authenticationService,
IMembershipService membershipService,
IUserService userService,
IOrchardServices orchardServices,
IEnumerable<IUserEventHandler> userEventHandlers)
{
_authenticationService = authenticationService;
_membershipService = membershipService;
_userService = userService;
_orchardServices = orchardServices;
_userEventHandlers = userEventHandlers;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public ILogger Logger { get; set; }
public Localizer T { get; set; }
[AlwaysAccessible]
public ActionResult LogOn()
{
if (_authenticationService.GetAuthenticatedUser() != null)
return Redirect("~/");
var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
return new ShapeResult(this, shape);
}
[HttpPost]
[AlwaysAccessible]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
Justification = "Needs to take same parameter type as Controller.Redirect()")]
public ActionResult LogOn(string userNameOrEmail, string password, string returnUrl, bool rememberMe = false)
{
var user = ValidateLogOn(userNameOrEmail, password);
if (!ModelState.IsValid)
{
var shape = _orchardServices.New.LogOn().Title(T("Log On").Text);
return new ShapeResult(this, shape);
}
_authenticationService.SignIn(user, rememberMe);
foreach (var userEventHandler in _userEventHandlers)
{
userEventHandler.LoggedIn(user);
}
return this.RedirectLocal(returnUrl);
}
private IUser ValidateLogOn(string userNameOrEmail, string password)
{
bool validate = true;
if (String.IsNullOrEmpty(userNameOrEmail))
{
ModelState.AddModelError("userNameOrEmail", T("You must specify a username or e-mail."));
validate = false;
}
if (String.IsNullOrEmpty(password))
{
ModelState.AddModelError("password", T("You must specify a password."));
validate = false;
}
if (!validate)
return null;
var user = _membershipService.ValidateUser(userNameOrEmail, password);
if (user == null)
{
ModelState.AddModelError("_FORM", T("The username or e-mail or password provided is incorrect."));
}
return user;
}
}
}
|
|
|
|
OK, after "Enable" my module, once click the "Sign In" link on the portal homepage, I got this error in VS:
The controller for path '/Orchard.Web/Users/Account/LogOn' was not found or does not implement IController.
|
|