private List <string> ValidateRegistrationStep2Inner(AccountRegisterModel accountModel) { List <string> errors = new List <string>(); if (!string.IsNullOrWhiteSpace(accountModel.LoginEmail)) { var regExp = @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z"; if (!Regex.IsMatch(accountModel.LoginEmail, regExp, RegexOptions.IgnoreCase)) { errors.Add("Email format is not valid"); } if (_SecurityAdapter.UserExists(accountModel.LoginEmail)) { errors.Add("An account is already registered with this email address."); } } else { errors.Add("LoginEmail is required"); } if (String.IsNullOrWhiteSpace(accountModel.Password) || accountModel.Password.Length < 6) { errors.Add("Invalid Password"); } if (String.IsNullOrWhiteSpace(accountModel.PasswordConfirm) || accountModel.Password != accountModel.PasswordConfirm) { errors.Add("Passwords do not match"); } return(errors); }
//[ValidateAntiForgeryToken] public ActionResult Login(AccountLoginModel viewModel) { _SecurityAdapter.Initialize(); // Ensure we have a valid viewModel to work with if (!ModelState.IsValid) { return(View(viewModel)); } // Verify if a user exists with the provided identity information var exist = _SecurityAdapter.UserExists(viewModel.LoginID); // If a user was found if (exist) { // Then create an identity for it and sign it in var success = _SecurityAdapter.Login(viewModel.LoginID, viewModel.Password, viewModel.RememberMe); if (success) { // If the user came from a specific page, redirect back to it return(RedirectToLocal(viewModel.ReturnUrl)); } } // No existing user was found that matched the given criteria ModelState.AddModelError("", "Invalid username or password."); // If we got this far, something failed, redisplay form return(View(viewModel)); }
public async Task <ActionResult> RegisterValidation2(RegisterModel model) { ActionResult response = null; var errors = new List <string>(); if (string.IsNullOrWhiteSpace(model.LoginEmail)) { errors.Add("Login email is invalid"); } if (await _securityAdapter.UserExists(model.LoginEmail)) { errors.Add("User with same 'Login Email' exist"); } if (!Regex.IsMatch(model.LoginEmail, @".*@.*\..*")) { errors.Add("Login email must contains \'@\', \'.\', symbols successively"); } if (model.Password.Length < 1) { errors.Add("Password must be at least 1 symbol"); } if (model.Password != model.ConfirmPassword) { errors.Add("Passwords do not match"); } if (errors.Any()) { response = StatusCode((int)HttpStatusCode.BadRequest, errors); } else { response = StatusCode((int)HttpStatusCode.OK); } return(response); }
public HttpResponseMessage ValidateRegistrationStep2(HttpRequestMessage request, [FromBody] AccountRegisterModel accountModel) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; if (!_SecurityAdapter.UserExists(accountModel.LoginEmail)) { response = request.CreateResponse(HttpStatusCode.OK); } else { response = request.CreateResponse <string[]>(HttpStatusCode.BadRequest, new string[] { "An account is already registered with that email." }); } return response; })); }
public HttpResponseMessage ValidateRegistrationStep2(HttpRequestMessage request, [FromBody] AccountRegisterModel accountModel) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; if (!_securityAdapter.UserExists(accountModel.LoginEmail)) { response = request.CreateResponse(HttpStatusCode.OK); } else { response = request.CreateResponse <string[]>(HttpStatusCode.BadRequest, new List <string>() { "Account with this login email already exists" }.ToArray()); } return response; })); }
public HttpResponseMessage UserExists(HttpRequestMessage request, string loginId) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; //var resluts; bool success = _SecurityAdapter.UserExists(loginId); if (success) { //resluts='1'; response = request.CreateResponse(HttpStatusCode.OK); } else { response = request.CreateErrorResponse(HttpStatusCode.Unauthorized, "User does not exist."); } return response; })); }
public HttpResponseMessage ValidateRegistrationStep2(HttpRequestMessage request, [FromBody] AccountRegisterModel accountModel) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; // TODO: validate other fields here in case smart-ass user tries to access this API outside of the site if (!_SecurityAdapter.UserExists(accountModel.LoginEmail)) { response = request.CreateResponse(HttpStatusCode.OK); } else { response = request.CreateResponse <string[]>(HttpStatusCode.BadRequest, new List <string>() { "An account is already registered with this email address." }.ToArray()); } return response; })); }