--HG--
branch : contributions
This commit is contained in:
Suha Can
2011-03-21 15:20:14 -07:00
2 changed files with 68 additions and 6 deletions

View File

@@ -14,6 +14,8 @@ using Orchard.Users.Services;
using Orchard.ContentManagement;
using Orchard.Users.Models;
using Orchard.UI.Notify;
using Orchard.Users.Events;
using System.Collections.Generic;
namespace Orchard.Users.Controllers {
[HandleError, Themed]
@@ -22,17 +24,19 @@ namespace Orchard.Users.Controllers {
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) {
IOrchardServices orchardServices,
IEnumerable<IUserEventHandler> userEventHandlers) {
_authenticationService = authenticationService;
_membershipService = membershipService;
_userService = userService;
_orchardServices = orchardServices;
_userEventHandlers = userEventHandlers;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
@@ -51,8 +55,13 @@ namespace Orchard.Users.Controllers {
}
//TODO: (erikpo) Add a setting for whether or not to log access denieds since these can fill up a database pretty fast from bots on a high traffic site
//Suggestion: Could instead use the new AccessDenined IUserEventHandler method and let modules decide if they want to log this event?
Logger.Information("Access denied to user #{0} '{1}' on {2}", currentUser.Id, currentUser.UserName, returnUrl);
foreach (var userEventHandler in _userEventHandlers) {
userEventHandler.AccessDenied(currentUser);
}
return View();
}
@@ -75,13 +84,20 @@ namespace Orchard.Users.Controllers {
}
_authenticationService.SignIn(user, false);
foreach (var userEventHandler in _userEventHandlers) {
userEventHandler.LoggedIn(user);
}
return this.RedirectLocal(returnUrl);
}
public ActionResult LogOff(string returnUrl) {
IUser wasLoggedInUser = _authenticationService.GetAuthenticatedUser();
_authenticationService.SignOut();
if (wasLoggedInUser != null)
foreach (var userEventHandler in _userEventHandlers) {
userEventHandler.LoggedOut(wasLoggedInUser);
}
return this.RedirectLocal(returnUrl);
}
@@ -116,12 +132,16 @@ namespace Orchard.Users.Controllers {
if (ValidateRegistration(userName, email, password, confirmPassword)) {
// Attempt to register the user
// No need to report this to IUserEventHandler because _membershipService does that for us
var user = _membershipService.CreateUser(new CreateUserParams(userName, password, email, null, null, false));
if (user != null) {
if ( user.As<UserPart>().EmailStatus == UserStatus.Pending ) {
_userService.SendChallengeEmail(user.As<UserPart>(), nonce => Url.AbsoluteAction(() => Url.Action("ChallengeEmail", "Account", new { Area = "Orchard.Users", nonce = nonce })));
foreach (var userEventHandler in _userEventHandlers) {
userEventHandler.SentChallengeEmail(user);
}
return RedirectToAction("ChallengeEmailSent");
}
@@ -194,6 +214,9 @@ namespace Orchard.Users.Controllers {
if ( validated != null ) {
_membershipService.SetPassword(validated, newPassword);
foreach (var userEventHandler in _userEventHandlers) {
userEventHandler.ChangedPassword(validated);
}
return RedirectToAction("ChangePasswordSuccess");
}
@@ -265,6 +288,10 @@ namespace Orchard.Users.Controllers {
var user = _userService.ValidateChallenge(nonce);
if ( user != null ) {
foreach (var userEventHandler in _userEventHandlers) {
userEventHandler.ConfirmedEmail(user);
}
return RedirectToAction("ChallengeEmailSuccess");
}

View File

@@ -1,16 +1,51 @@
using Orchard.Events;
using Orchard.Security;
namespace Orchard.Users.Events {
public interface IUserEventHandler : IEventHandler {
namespace Orchard.Users.Events
{
public interface IUserEventHandler : IEventHandler
{
/// <summary>
/// Called before a User is created
/// </summary>
void Creating(UserContext context);
/// <summary>
/// Called once a user has been created
/// Called after a user has been created
/// </summary>
void Created(UserContext context);
// NEW BELOW HERE
/// <summary>
/// Called after a user has logged in
/// </summary>
void LoggedIn(IUser user);
/// <summary>
/// Called when a user explicitly logs out (as opposed to one whos session cookie simply expires)
/// </summary>
void LoggedOut(IUser user);
/// <summary>
/// Called when access is denied to a user
/// </summary>
void AccessDenied(IUser user);
/// <summary>
/// Called after a user has changed password
/// </summary>
void ChangedPassword(IUser user);
/// <summary>
/// Called after a user has confirmed their email address
/// </summary>
void SentChallengeEmail(IUser user);
/// <summary>
/// Called after a user has confirmed their email address
/// </summary>
void ConfirmedEmail(IUser user);
}
}