EnVisageOnline/Main/Source/EnVisage/Models/AccountViewModels.cs

162 lines
5.3 KiB
C#

using EnVisage.Code;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace EnVisage.Models
{
public class ExternalLoginConfirmationViewModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
}
public class ManageUserViewModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Current password")]
public string OldPassword { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm new password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
[EmailAddress(ErrorMessage = "Invalid Email Address")]
[Display(Name="Email")]
[StringLength(512)]
public string Email { get; set; }
[DataType(DataType.PhoneNumber)]
[Display(Name="Phone number")]
[StringLength(80)]
public string Phone { get; set; }
[Display(Name = "Quantity as")]
public bool PreferredResourceAllocation { get; set; }
[Display(Name = "Totals as")]
public bool PreferredTotalsDisplaying { get; set; }
[Display(Name = "Over-Under Coefficient")]
public double OverUnderCoefficient { get; set; }
[Display(Name = "First Name")]
[StringLength(40)]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Display(Name = "User ID")]
public string UserName { get; set; }
public bool DomainUser { get; set; }
[Display(Name = "Automatic Views for My Business Units")]
public bool ShowAutomaticViews { get; set; }
public ManageUserViewModel()
{
OverUnderCoefficient = 1;
}
}
public class LoginViewModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
public class RegisterViewModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
public class ForgotPasswordModel
{
[DataType(DataType.EmailAddress)]
[Display(Name = "Email")]
[Required]
public string Email { get; set; }
public bool Sent { get; set; }
}
public class RestorePasswordModel : IValidatableObject
{
public enum PageState
{
Initial = 0, // initial page load, expected to receive token in QS
Restored = 1, // new password submitted and accepted
TokenDoesNotExist = 2, // token from QS does not exist
TokenExpired = 3, // token from QS is expired
TokenIsEmpty = 4, // there are no token
TokenResent = 5, // token has been resent
}
public Guid Token { get; set; }
public string Email { get; set; }
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public PageState State { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
switch (State)
{
case PageState.Initial:
if (string.IsNullOrWhiteSpace(this.Password) || string.IsNullOrWhiteSpace(this.Password.Trim()))
yield return new ValidationResult(string.Format(Constants.ERROR_TEMPLATE_REQUIRED, "Password"), new[] { "Password" });
else if (string.IsNullOrWhiteSpace(this.ConfirmPassword) || string.IsNullOrWhiteSpace(this.ConfirmPassword.Trim()))
yield return new ValidationResult(string.Format(Constants.ERROR_TEMPLATE_REQUIRED, "Confirm Password"), new[] { "ConfirmPassword" });
yield break;
default:
yield break;
}
}
}
public class ReturnUrlModel
{
public string Action { get; set; }
public string ReturnUrl { get; set; }
}
}