public async Task <IActionResult> Register(UserModel userModel) { try { BusFacCore busFacCore = new BusFacCore(_settings); UtilsValidation utilsValidation = new UtilsValidation(); BusUser busUser = new BusUser(); if ((!string.IsNullOrEmpty(userModel.Username)) && (!string.IsNullOrEmpty(userModel.Password)) && (utilsValidation.IsValidEmail(userModel.Username)) && (busUser.IsValidPasswd(userModel.Password))) { if (!(userModel.Password.Equals(userModel.ConfirmPassword, StringComparison.Ordinal))) { ViewData["PasswordMatch"] = true; } else { bool UserExist = busFacCore.Exist(userModel.Username); if (!UserExist) { User user = busFacCore.UserCreate(userModel.Username, userModel.Password); if ((user != null) && (user.UserID > 0)) { var claims = new[] { new Claim("name", userModel.Username) }; var principal = new ClaimsPrincipal( new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme)); await HttpContext.Authentication.SignInAsync("MyCookieMiddlewareInstance", principal); return(RedirectToAction("Index", "Dashboard")); } else { ViewData["HasError"] = true; } } else { ViewData["UserExist"] = true; } } } else { ViewData["InvalidCredentials"] = true; } } catch (Exception ex) { ViewData["HasError"] = true; } return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Register(UserModel userModel) { try { BusFacCore busFacCore = new BusFacCore(_settings); UtilsValidation utilsValidation = new UtilsValidation(); BusUser busUser = new BusUser(); if ((!string.IsNullOrEmpty(userModel.Username)) && (!string.IsNullOrEmpty(userModel.Password)) && (utilsValidation.IsValidEmail(userModel.Username)) && (busUser.IsValidPasswd(userModel.Password))) { if (!(userModel.Password.Equals(userModel.ConfirmPassword, StringComparison.Ordinal))) { ViewData["PasswordMatch"] = true; } else { bool UserExist = busFacCore.Exist(userModel.Username); if (!UserExist) { User user = busFacCore.UserCreate(userModel.Username, userModel.Password); if ((user != null) && (user.UserID > 0)) { return(RedirectToAction("Login", userModel)); } else { ViewData["HasError"] = true; } } else { ViewData["UserExist"] = true; } } } else { ViewData["InvalidCredentials"] = true; } } catch (Exception ex) { ViewData["HasError"] = true; } return(RedirectToAction("Index")); }