2014-01-28 13:35:43 +11:00
using System ;
using System.Linq ;
2013-08-28 17:52:06 +02:00
using System.Web.Mvc ;
2014-01-28 13:35:43 +11:00
using System.Web.Security ;
2013-08-28 17:52:06 +02:00
using System.Xml ;
using umbraco.cms.businesslogic.member ;
using Umbraco.Web.Models ;
using Umbraco.Web.Mvc ;
2014-01-28 13:35:43 +11:00
using Umbraco.Core.Security ;
2014-02-10 16:46:45 +11:00
using Umbraco.Core ;
2013-08-28 17:52:06 +02:00
namespace Umbraco.Web.Controllers
{
2014-01-28 13:47:16 +11:00
public class UmbProfileController : SurfaceController
2013-08-28 17:52:06 +02:00
{
[HttpPost]
2014-01-28 13:35:43 +11:00
public ActionResult HandleUpdateProfile ( [ Bind ( Prefix = "profileModel" ) ] ProfileModel model )
2013-08-28 17:52:06 +02:00
{
2014-01-28 13:35:43 +11:00
if ( Membership . Provider . IsUmbracoMembershipProvider ( ) = = false )
2013-08-28 17:52:06 +02:00
{
2014-01-28 13:47:16 +11:00
throw new NotSupportedException ( "Profile editing with the " + typeof ( UmbProfileController ) + " is not supported when not using the default Umbraco membership provider" ) ;
2014-01-28 13:35:43 +11:00
}
2013-08-28 17:52:06 +02:00
2014-01-28 13:35:43 +11:00
if ( ModelState . IsValid = = false )
{
return CurrentUmbracoPage ( ) ;
}
2013-08-28 17:52:06 +02:00
2014-02-10 16:22:15 +11:00
var updateAttempt = Members . UpdateMemberProfile ( model ) ;
if ( updateAttempt . Success = = false )
{
2014-02-10 18:34:12 +11:00
//don't add a field level error, just model level
ModelState . AddModelError ( "profileModel" , updateAttempt . Exception . Message ) ;
2014-02-10 16:22:15 +11:00
return CurrentUmbracoPage ( ) ;
}
2014-02-10 16:46:45 +11:00
//if there is a specified path to redirect to then use it
if ( model . RedirectUrl . IsNullOrWhiteSpace ( ) = = false )
{
return Redirect ( model . RedirectUrl ) ;
}
2013-08-28 17:52:06 +02:00
2014-02-10 16:46:45 +11:00
//redirect to current page by default
TempData . Add ( "ProfileUpdateSuccess" , true ) ;
return RedirectToCurrentUmbracoPage ( ) ;
2013-08-28 17:52:06 +02:00
}
}
}