moved logic to update a profile to MembershipHelper.

This commit is contained in:
Shannon
2014-01-28 21:57:00 +11:00
parent cfd0973f00
commit f28ae52ae3
2 changed files with 42 additions and 32 deletions

View File

@@ -25,38 +25,7 @@ namespace Umbraco.Web.Controllers
return CurrentUmbracoPage();
}
if (Members.IsLoggedIn() == 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);
Members.UpdateMemberProfile(model);
//TODO: Why are we redirecting to home again here??
return Redirect("/");

View File

@@ -47,6 +47,47 @@ namespace Umbraco.Web.Security
return Membership.Provider.IsUmbracoMembershipProvider();
}
/// <summary>
/// Updates the currently logged in members profile
/// </summary>
/// <param name="model"></param>
public void UpdateMemberProfile(ProfileModel model)
{
if (IsLoggedIn() == false)
{
throw new NotSupportedException("No member is currently logged in");
}
var member = GetCurrentMember();
if (model.Name != null)
{
member.Name = model.Name;
}
member.Email = model.Email;
member.Username = model.Email;
if (model.MemberProperties != null)
{
foreach (var property in model.MemberProperties
//ensure the property they are posting exists
.Where(p => member.ContentType.PropertyTypeExists(p.Alias))
.Where(property => member.Properties.Contains(property.Alias))
//needs to be editable
.Where(p => member.ContentType.MemberCanEditProperty(p.Alias))
//needs to have a value
.Where(p => p.Value != null))
{
member.Properties[property.Alias].Value = property.Value;
}
}
_applicationContext.Services.MemberService.Save(member);
//reset the FormsAuth cookie since the username might have changed
FormsAuthentication.SetAuthCookie(member.Username, true);
}
/// <summary>
/// Registers a new member
/// </summary>