2014-02-13 16:22:51 +11:00
using System ;
using System.ComponentModel.DataAnnotations ;
using System.Web ;
using Umbraco.Core ;
2017-09-19 15:51:47 +02:00
using Umbraco.Web.Composing ;
2014-02-13 16:22:51 +11:00
using Umbraco.Web.Security ;
2013-09-02 15:40:14 +02:00
namespace Umbraco.Web.Models
{
2014-02-13 16:22:51 +11:00
/// <summary>
2016-09-01 19:06:08 +02:00
/// The model representing the status of a logged in member.
2014-02-13 16:22:51 +11:00
/// </summary>
2013-09-02 15:40:14 +02:00
public class LoginStatusModel
{
2014-02-13 16:22:51 +11:00
/// <summary>
2016-09-01 19:06:08 +02:00
/// Creates a new empty LoginStatusModel.
2014-02-13 16:22:51 +11:00
/// </summary>
/// <returns></returns>
public static LoginStatusModel CreateModel ()
2013-09-02 15:40:14 +02:00
{
2016-09-01 19:06:08 +02:00
return new LoginStatusModel ( false );
2014-02-13 16:22:51 +11:00
}
private LoginStatusModel ( bool doLookup )
{
2017-09-19 15:51:47 +02:00
if ( doLookup && Current . UmbracoContext != null )
2013-09-02 15:40:14 +02:00
{
2017-09-19 15:51:47 +02:00
var helper = new MembershipHelper ( Current . UmbracoContext );
2014-02-13 16:22:51 +11:00
var model = helper . GetCurrentLoginStatus ();
if ( model != null )
2013-09-02 15:40:14 +02:00
{
2014-02-13 16:22:51 +11:00
Name = model . Name ;
Username = model . Username ;
Email = model . Email ;
IsLoggedIn = true ;
2013-09-02 15:40:14 +02:00
}
}
}
2014-02-13 16:22:51 +11:00
/// <summary>
/// This will construct a new LoginStatusModel and perform a lookup for hte curently logged in member
/// </summary>
[Obsolete("Do not use this ctor as it will perform business logic lookups. Use the MembershipHelper.GetCurrentLoginStatus or the static LoginStatusModel.CreateModel() to create an empty model.")]
public LoginStatusModel ()
: this ( true )
2016-09-01 19:06:08 +02:00
{ }
2014-02-13 16:22:51 +11:00
/// <summary>
/// The name of the member
/// </summary>
[Required]
2013-09-02 15:40:14 +02:00
public string Name { get ; set ; }
2014-02-13 16:22:51 +11:00
/// <summary>
/// The username of the member
/// </summary>
2013-09-02 15:40:14 +02:00
public string Username { get ; set ; }
2014-02-13 16:22:51 +11:00
/// <summary>
/// The email of the member
/// </summary>
[Required]
2013-09-02 15:40:14 +02:00
public string Email { get ; set ; }
2014-02-13 16:22:51 +11:00
/// <summary>
/// True, if the member is currently logged in
/// </summary>
2013-09-02 15:40:14 +02:00
public bool IsLoggedIn { get ; set ; }
}
2017-07-20 11:21:28 +02:00
}