webdav portal password change page added
This commit is contained in:
parent
dd15673752
commit
4bae47e17f
35 changed files with 2010 additions and 93 deletions
|
@ -0,0 +1,124 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
using WebsitePanel.WebDav.Core;
|
||||
|
||||
namespace WebsitePanel.WebDavPortal.CustomAttributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
|
||||
public class OrganizationPasswordPolicyAttribute : ValidationAttribute, IClientValidatable
|
||||
{
|
||||
public OrganizationPasswordSettings Settings { get; private set; }
|
||||
|
||||
public OrganizationPasswordPolicyAttribute()
|
||||
{
|
||||
Settings = WspContext.Services.Organizations.GetOrganizationPasswordSettings(WspContext.User.ItemId);
|
||||
}
|
||||
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
if (value != null && WspContext.User != null)
|
||||
{
|
||||
|
||||
var resultMessages = new List<string>();
|
||||
|
||||
if (Settings != null)
|
||||
{
|
||||
var valueString = value.ToString();
|
||||
|
||||
if (valueString.Length < Settings.MinimumLength)
|
||||
{
|
||||
resultMessages.Add(string.Format(Resources.Messages.PasswordMinLengthFormat,
|
||||
Settings.MinimumLength));
|
||||
}
|
||||
|
||||
if (valueString.Length > Settings.MaximumLength)
|
||||
{
|
||||
resultMessages.Add(string.Format(Resources.Messages.PasswordMaxLengthFormat,
|
||||
Settings.MaximumLength));
|
||||
}
|
||||
|
||||
if (Settings.PasswordComplexityEnabled)
|
||||
{
|
||||
var symbolsCount = valueString.Count(Char.IsSymbol);
|
||||
var numbersCount = valueString.Count(Char.IsDigit);
|
||||
var upperLetterCount = valueString.Count(Char.IsUpper);
|
||||
|
||||
if (upperLetterCount < Settings.UppercaseLettersCount)
|
||||
{
|
||||
resultMessages.Add(string.Format(Resources.Messages.PasswordUppercaseCountFormat,
|
||||
Settings.UppercaseLettersCount));
|
||||
}
|
||||
|
||||
if (numbersCount < Settings.NumbersCount)
|
||||
{
|
||||
resultMessages.Add(string.Format(Resources.Messages.PasswordNumbersCountFormat,
|
||||
Settings.NumbersCount));
|
||||
}
|
||||
|
||||
if (symbolsCount < Settings.SymbolsCount)
|
||||
{
|
||||
resultMessages.Add(string.Format(Resources.Messages.PasswordSymbolsCountFormat,
|
||||
Settings.SymbolsCount));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resultMessages.Any()? new ValidationResult(string.Join("<br>", resultMessages)) : ValidationResult.Success;
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
|
||||
{
|
||||
var rule = new ModelClientValidationRule();
|
||||
|
||||
rule.ErrorMessage = string.Format(Resources.Messages.PasswordMinLengthFormat, Settings.MinimumLength);
|
||||
rule.ValidationParameters.Add("count", Settings.MinimumLength);
|
||||
rule.ValidationType = "minimumlength";
|
||||
|
||||
yield return rule;
|
||||
|
||||
rule = new ModelClientValidationRule();
|
||||
|
||||
rule.ErrorMessage = string.Format(Resources.Messages.PasswordMaxLengthFormat, Settings.MaximumLength);
|
||||
rule.ValidationParameters.Add("count", Settings.MaximumLength);
|
||||
rule.ValidationType = "maximumlength";
|
||||
|
||||
yield return rule;
|
||||
|
||||
if (Settings.PasswordComplexityEnabled)
|
||||
{
|
||||
rule = new ModelClientValidationRule();
|
||||
|
||||
rule.ErrorMessage = string.Format(Resources.Messages.PasswordUppercaseCountFormat, Settings.UppercaseLettersCount);
|
||||
rule.ValidationParameters.Add("count", Settings.UppercaseLettersCount);
|
||||
rule.ValidationType = "uppercasecount";
|
||||
|
||||
yield return rule;
|
||||
|
||||
rule = new ModelClientValidationRule();
|
||||
|
||||
rule.ErrorMessage = string.Format(Resources.Messages.PasswordNumbersCountFormat, Settings.NumbersCount);
|
||||
rule.ValidationParameters.Add("count", Settings.NumbersCount);
|
||||
rule.ValidationType = "numberscount";
|
||||
|
||||
yield return rule;
|
||||
|
||||
rule = new ModelClientValidationRule();
|
||||
|
||||
rule.ErrorMessage = string.Format(Resources.Messages.PasswordSymbolsCountFormat, Settings.SymbolsCount);
|
||||
rule.ValidationParameters.Add("count", Settings.SymbolsCount);
|
||||
rule.ValidationType = "symbolscount";
|
||||
|
||||
yield return rule;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace WebsitePanel.WebDavPortal.CustomAttributes
|
||||
{
|
||||
public class PhoneNumberAttribute : RegularExpressionAttribute, IClientValidatable
|
||||
{
|
||||
public const string PhonePattern = @"^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d$";
|
||||
|
||||
public PhoneNumberAttribute()
|
||||
: base(PhonePattern)
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
|
||||
{
|
||||
yield return new ModelClientValidationRegexRule(FormatErrorMessage(metadata.GetDisplayName()), Pattern);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue