using System; using System.ComponentModel.DataAnnotations; using System.Web; using Umbraco.Core; using Umbraco.Web.Composing; using Umbraco.Web.Security; namespace Umbraco.Web.Models { /// /// The model representing the status of a logged in member. /// public class LoginStatusModel { /// /// Creates a new empty LoginStatusModel. /// /// public static LoginStatusModel CreateModel() { return new LoginStatusModel(false); } private LoginStatusModel(bool doLookup) { if (doLookup && Current.UmbracoContext != null) { var helper = new MembershipHelper(Current.UmbracoContext); var model = helper.GetCurrentLoginStatus(); if (model != null) { Name = model.Name; Username = model.Username; Email = model.Email; IsLoggedIn = true; } } } /// /// This will construct a new LoginStatusModel and perform a lookup for hte curently logged in member /// [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) { } /// /// The name of the member /// [Required] public string Name { get; set; } /// /// The username of the member /// public string Username { get; set; } /// /// The email of the member /// [Required] public string Email { get; set; } /// /// True, if the member is currently logged in /// public bool IsLoggedIn { get; set; } } }