mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Make user validate a bit more robust
This commit is contained in:
@@ -173,12 +173,20 @@ namespace Orchard.Users.Controllers {
|
||||
}
|
||||
|
||||
private IUser ValidateLogOn(string userNameOrEmail, string password) {
|
||||
bool validate = true;
|
||||
|
||||
if (String.IsNullOrEmpty(userNameOrEmail)) {
|
||||
ModelState.AddModelError("userNameOrEmail", T("You must specify a username or e-mail."));
|
||||
validate = false;
|
||||
}
|
||||
if (String.IsNullOrEmpty(password)) {
|
||||
ModelState.AddModelError("password", T("You must specify a password."));
|
||||
validate = false;
|
||||
}
|
||||
|
||||
if (!validate)
|
||||
return null;
|
||||
|
||||
var user = _membershipService.ValidateUser(userNameOrEmail, password);
|
||||
if (user == null) {
|
||||
ModelState.AddModelError("_FORM", T("The username or e-mail or password provided is incorrect."));
|
||||
@@ -188,12 +196,20 @@ namespace Orchard.Users.Controllers {
|
||||
}
|
||||
|
||||
private bool ValidateRegistration(string userName, string email, string password, string confirmPassword) {
|
||||
bool validate = true;
|
||||
|
||||
if (String.IsNullOrEmpty(userName)) {
|
||||
ModelState.AddModelError("username", T("You must specify a username."));
|
||||
validate = false;
|
||||
}
|
||||
if (String.IsNullOrEmpty(email)) {
|
||||
ModelState.AddModelError("email", T("You must specify an email address."));
|
||||
validate = false;
|
||||
}
|
||||
|
||||
if (!validate)
|
||||
return false;
|
||||
|
||||
string userUnicityMessage = _userService.VerifyUserUnicity(userName, email);
|
||||
if (userUnicityMessage != null) {
|
||||
ModelState.AddModelError("userExists", T(userUnicityMessage));
|
||||
|
@@ -44,10 +44,9 @@ namespace Orchard.Users.Services {
|
||||
}
|
||||
|
||||
public IUser GetUser(string username) {
|
||||
if(username == null) {
|
||||
throw new ArgumentNullException("username");
|
||||
}
|
||||
var userRecord = _userRepository.Get(x => x.NormalizedUserName == username.ToLower());
|
||||
var lowerName = username == null ? "" : username.ToLower();
|
||||
|
||||
var userRecord = _userRepository.Get(x => x.NormalizedUserName == lowerName);
|
||||
if (userRecord == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -55,9 +54,11 @@ namespace Orchard.Users.Services {
|
||||
}
|
||||
|
||||
public IUser ValidateUser(string userNameOrEmail, string password) {
|
||||
var userRecord = _userRepository.Get(x => x.NormalizedUserName == userNameOrEmail.ToLower());
|
||||
var lowerName = userNameOrEmail == null ? "" : userNameOrEmail.ToLower();
|
||||
|
||||
var userRecord = _userRepository.Get(x => x.NormalizedUserName == lowerName);
|
||||
if(userRecord == null)
|
||||
userRecord = _userRepository.Get(x => x.Email == userNameOrEmail.ToLower());
|
||||
userRecord = _userRepository.Get(x => x.Email == lowerName);
|
||||
if (userRecord == null || ValidatePassword(userRecord, password) == false)
|
||||
return null;
|
||||
|
||||
|
Reference in New Issue
Block a user