2014-03-07 19:39:31 +11:00
using System ;
using System.Linq ;
2013-11-07 17:16:22 +01:00
using System.Web.Mvc ;
2014-03-07 19:39:31 +11:00
using System.Web.Security ;
2013-11-07 17:16:22 +01:00
using System.Xml ;
using umbraco.cms.businesslogic.member ;
using Umbraco.Web.Models ;
using Umbraco.Web.Mvc ;
2014-03-07 19:39:31 +11:00
using Umbraco.Core.Security ;
using Umbraco.Core ;
2013-11-07 17:16:22 +01:00
namespace Umbraco.Web.Controllers
{
2015-08-21 12:15:45 +02:00
[MemberAuthorize]
2013-11-07 17:16:22 +01:00
public class UmbProfileController : SurfaceController
{
[HttpPost]
2014-03-07 19:39:31 +11:00
public ActionResult HandleUpdateProfile ( [ Bind ( Prefix = "profileModel" ) ] ProfileModel model )
2013-11-07 17:16:22 +01:00
{
2014-03-18 19:05:07 +11:00
var provider = global :: Umbraco . Core . Security . MembershipProviderExtensions . GetMembersMembershipProvider ( ) ;
2014-03-18 18:47:49 +11:00
if ( provider . IsUmbracoMembershipProvider ( ) = = false )
2013-11-07 17:16:22 +01:00
{
2014-03-07 19:39:31 +11:00
throw new NotSupportedException ( "Profile editing with the " + typeof ( UmbProfileController ) + " is not supported when not using the default Umbraco membership provider" ) ;
}
2013-11-07 17:16:22 +01:00
2014-03-07 19:39:31 +11:00
if ( ModelState . IsValid = = false )
{
return CurrentUmbracoPage ( ) ;
}
2013-11-07 17:16:22 +01:00
2014-03-07 19:39:31 +11:00
var updateAttempt = Members . UpdateMemberProfile ( model ) ;
if ( updateAttempt . Success = = false )
{
//don't add a field level error, just model level
ModelState . AddModelError ( "profileModel" , updateAttempt . Exception . Message ) ;
return CurrentUmbracoPage ( ) ;
}
2013-11-07 17:16:22 +01:00
2015-08-27 14:56:42 +02:00
TempData [ "ProfileUpdateSuccess" ] = true ;
2014-03-07 19:39:31 +11:00
//if there is a specified path to redirect to then use it
if ( model . RedirectUrl . IsNullOrWhiteSpace ( ) = = false )
{
return Redirect ( model . RedirectUrl ) ;
2013-11-07 17:16:22 +01:00
}
2015-08-27 14:56:42 +02:00
//redirect to current page by default
2014-03-07 19:39:31 +11:00
return RedirectToCurrentUmbracoPage ( ) ;
2013-11-07 17:16:22 +01:00
}
}
}