Files
Orchard/src/Orchard.Web/Modules/Orchard.Users/Services/UsernameValidationError.cs
Alessandro Agostini c515ce1917 Added Username policies (#8638)
* Added Username policies

* Added newline at the end of files

# Conflicts:
#	src/Orchard.Web/Modules/Orchard.Users/Services/AccountValidationService.cs

* Added check for username length that must be under 255 characters (even if username policies are disabled).
If username isn't modified, policies are not enforced when saving the user inside backoffice.
Default length limits are 1 and 255.

* Added UsernameValidationError.cs
Added a setting to bypass non fatal errors and show them as warning when creating/editing users from the backoffice
Added the relative checkbox in RegistrationSettings.cshtml
Modified the UsernameMeetsPolicies method to use the new class
Modified AdminController (CreatePOST, EditPOST) and AccountController (Register)

* If username is an email check that it matches the specified email

* Added hints to UserRegistrationSettings view
Changed the severity of some custom policies errors

* Removed UsernameValidLengthAttribute.cs, if MinimumUsernameLength and MaximumUsernameLength settings don't make sense these settings are ignored

* bugfix. The admin could change the a username setting an already existing username.

Co-authored-by: Andrea Piovanelli <andrea.piovanelli@laser-group.com>
2023-01-27 11:23:22 +01:00

33 lines
840 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Localization;
namespace Orchard.Users.Services {
public enum Severity {
Warning,
Fatal
}
public class UsernameValidationError {
private Severity _severity;
private string _key;
private LocalizedString _errorMessage;
public UsernameValidationError(Severity severity, string key, LocalizedString errorMessage) {
Severity = severity;
Key = key;
ErrorMessage = errorMessage;
}
public Severity Severity { get => _severity; set => _severity = value; }
public string Key { get => _key; set => _key = value; }
public LocalizedString ErrorMessage { get => _errorMessage; set => _errorMessage = value; }
}
}