Fixes ProfileController to use normal .Net APIs and the new members service - also removes the Response.Redirect that was in there, why was it like that?

This commit is contained in:
Shannon
2014-01-28 13:35:43 +11:00
parent 3fa5c4e0b2
commit 677cc8c8fd
2 changed files with 49 additions and 31 deletions

View File

@@ -1,48 +1,66 @@
using System.Linq;
using System;
using System.Linq;
using System.Web.Mvc;
using System.Web.Security;
using System.Xml;
using umbraco.cms.businesslogic.member;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
using Umbraco.Core.Security;
namespace Umbraco.Web.Controllers
{
public class ProfileController : SurfaceController
{
[HttpPost]
public ActionResult HandleUpdateProfile([Bind(Prefix="profileModel")]ProfileModel model)
public ActionResult HandleUpdateProfile([Bind(Prefix = "profileModel")] ProfileModel model)
{
//TODO: Use new Member API
if (ModelState.IsValid)
if (Membership.Provider.IsUmbracoMembershipProvider() == false)
{
var member = Member.GetCurrentMember();
if (member != null)
{
if (model.Name != null)
{
member.Text = model.Name;
}
member.Email = model.Email;
member.LoginName = model.Email;
if (model.MemberProperties != null)
{
foreach (var property in model.MemberProperties.Where(p => p.Value != null))
{
member.getProperty(property.Alias).Value = property.Value;
}
}
member.Save();
Member.AddMemberToCache(member);
Response.Redirect("/");
}
throw new NotSupportedException("Profile editing with the " + typeof (ProfileController) + " is not supported when not using the default Umbraco membership provider");
}
return CurrentUmbracoPage();
if (ModelState.IsValid == false)
{
return CurrentUmbracoPage();
}
if (HttpContext.User == null || HttpContext.User.Identity.IsAuthenticated == false)
{
throw new NotSupportedException("No member is currently logged in");
}
var member = Services.MemberService.GetByUsername(HttpContext.User.Identity.Name);
if (member == null)
{
//this should never happen
throw new InvalidOperationException("No member found with username: " + HttpContext.User.Identity.Name);
}
if (model.Name != null)
{
member.Name = model.Name;
}
member.Email = model.Email;
member.Username = model.Email;
if (model.MemberProperties != null)
{
//TODO: Shouldn't we ensure that none of these properties are flagged as non-editable to the member??
foreach (var property in model.MemberProperties.Where(p => p.Value != null))
{
if (member.Properties.Contains(property.Alias))
{
member.Properties[property.Alias].Value = property.Value;
}
}
}
Services.MemberService.Save(member);
//reset the FormsAuth cookie since the username might have changed
FormsAuthentication.SetAuthCookie(member.Username, true);
//TODO: Why are we redirecting to home again here??
return Redirect("/");
}
}
}

View File

@@ -57,7 +57,7 @@ namespace Umbraco.Web.Controllers
case MembershipCreateStatus.InvalidQuestion:
case MembershipCreateStatus.InvalidAnswer:
//TODO: Support q/a http://issues.umbraco.org/issue/U4-3213
throw new NotImplementedException();
throw new NotImplementedException(status.ToString());
case MembershipCreateStatus.InvalidEmail:
ModelState.AddModelError("registerModel.Email", "Email is invalid");
break;