Make user validate a bit more robust

This commit is contained in:
Renaud Paquay
2010-05-13 16:31:40 -07:00
parent edb1867e25
commit 641e3833cd
2 changed files with 23 additions and 6 deletions

View File

@@ -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));