Corrected resolution of username

- Using IRepository was also looking at removed content items

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-09-01 18:18:53 -07:00
parent 98d11e81f0
commit 257cb4682a
6 changed files with 40 additions and 17 deletions

View File

@@ -183,15 +183,23 @@ namespace Orchard.Users.Controllers {
return View(new BaseViewModel());
}
public ActionResult ChallengeEmailSuccess() {
return View(new BaseViewModel());
}
public ActionResult ChallengeEmailFail() {
return View(new BaseViewModel());
}
public ActionResult ChallengeEmail(string token) {
var user = _membershipService.ValidateChallengeToken(token);
if ( user != null ) {
_authenticationService.SignIn(user, false /* createPersistentCookie */);
return View("ChallengeEmailSuccess");
return RedirectToAction("ChallengeEmailSuccess");
}
return View("ChallengeEmailFail");
return RedirectToAction("ChallengeEmailFail");
}
protected override void OnActionExecuting(ActionExecutingContext filterContext) {

View File

@@ -149,6 +149,22 @@ namespace Orchard.Users.Controllers {
return RedirectToAction("Index");
}
public ActionResult SendChallengeEmail(int id) {
if ( !Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")) )
return new HttpUnauthorizedResult();
var user = Services.ContentManager.Get(id);
if ( user != null ) {
string challengeToken = _membershipService.GetEncryptedChallengeToken(user.As<UserPart>());
_membershipService.SendChallengeEmail(user.As<UserPart>(), Url.AbsoluteAction(() => Url.Action("ChallengeEmail", "Account", new {Area = "Orchard.Users", token = challengeToken})));
}
Services.Notifier.Information(T("Challenge email sent"));
return RedirectToAction("Index");
}
public ActionResult Approve(int id) {
if ( !Services.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")) )
return new HttpUnauthorizedResult();

View File

@@ -134,31 +134,27 @@ namespace Orchard.Users.Services {
public IUser GetUser(string username) {
var lowerName = username == null ? "" : username.ToLower();
var userRecord = _userRepository.Get(x => x.NormalizedUserName == lowerName);
if (userRecord == null) {
return null;
}
return _contentManager.Get<IUser>(userRecord.Id);
return _contentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
}
public IUser ValidateUser(string userNameOrEmail, string password) {
var lowerName = userNameOrEmail == null ? "" : userNameOrEmail.ToLower();
var userRecord = _userRepository.Get(x => x.NormalizedUserName == lowerName);
var user = _contentManager.Query<UserPart, UserPartRecord>().Where(u => u.NormalizedUserName == lowerName).List().FirstOrDefault();
if(userRecord == null)
userRecord = _userRepository.Get(x => x.Email == lowerName);
if(user == null)
user = _contentManager.Query<UserPart, UserPartRecord>().Where(u => u.Email == lowerName).List().FirstOrDefault();
if (userRecord == null || ValidatePassword(userRecord, password) == false)
if ( user == null || ValidatePassword(user.As<UserPart>().Record, password) == false )
return null;
if ( userRecord.EmailStatus != UserStatus.Approved )
if ( user.EmailStatus != UserStatus.Approved )
return null;
if ( userRecord.RegistrationStatus != UserStatus.Approved )
if ( user.RegistrationStatus != UserStatus.Approved )
return null;
return _contentManager.Get<IUser>(userRecord.Id);
return user;
}
public void SetPassword(IUser user, string password) {

View File

@@ -1,3 +1,3 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<bool>" %>
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<object>" %>
<h1><%: Html.TitleForPage(T("Challenge Email").ToString()) %></h1>
<p><%: T("Your email address could not be validated.") %></p>

View File

@@ -1,3 +1,3 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<bool>" %>
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<object>" %>
<h1><%: Html.TitleForPage(T("Challenge Email").ToString()) %></h1>
<p><%: T("Your email address has been validated.") %></p>

View File

@@ -37,7 +37,10 @@
<td>
<%: Html.ActionLink(T("Edit").ToString(), "Edit", new { row.UserPart.Id })%> |
<%: Html.ActionLink(T("Remove").ToString(), "Delete", new { row.UserPart.Id })%> |
<%: row.UserPart.RegistrationStatus == UserStatus.Pending ? Html.ActionLink(T("Approve").ToString(), "Approve", new { row.UserPart.Id }) : Html.ActionLink(T("Moderate").ToString(), "Moderate", new { row.UserPart.Id })%>
<%: row.UserPart.RegistrationStatus == UserStatus.Pending ? Html.ActionLink(T("Approve").ToString(), "Approve", new { row.UserPart.Id }) : Html.ActionLink(T("Disable").ToString(), "Moderate", new { row.UserPart.Id })%>
<% if ( row.UserPart.EmailStatus == UserStatus.Pending ) { %> |
<%: Html.ActionLink(T("Challenge Email").ToString(), "SendChallengeEmail", new { row.UserPart.Id })%>
<% } %>
</td>
</tr>
<%}%>