public async Task <IActionResult> RegistrationAsync([FromServices] ICaptchaGenratorBase captchaGenratorBase, [FromServices] ISequenceMaster sequenceMaster, [FromServices] IConsolidatorProfile consolidatorProfile, [FromServices] RoleManager <IdentityRole> RoleManager, [FromForm] mdlRegistration mdl) { if (mdl.CaptchaData == null) { ModelState.AddModelError(mdl.CaptchaData.CaptchaCode, "Invalid Captcha"); } else if (!captchaGenratorBase.verifyCaptch(mdl.CaptchaData.SaltId, mdl.CaptchaData.CaptchaCode)) { ModelState.AddModelError(mdl.CaptchaData.CaptchaCode, "Invalid Captcha"); } if (ModelState.IsValid) { using var transaction = _context.Database.BeginTransaction(); try { mdl.GenrateRegistration(sequenceMaster, consolidatorProfile, _context); ApplicationUser appuser = new ApplicationUser() { UserName = mdl.TcId, Email = mdl.EmailAddress, TcNid = mdl.TcNId, PhoneNumber = mdl.PhoneNo, UserType = enmUserType.Consolidator }; var result = await _userManager.CreateAsync(appuser, mdl.Password); if (result.Succeeded) { var role = await RoleManager.FindByNameAsync("TC"); if (role != null) { await _userManager.AddToRoleAsync(appuser, "TC"); } await _signInManager.SignInAsync(appuser, isPersistent : false); transaction.Commit(); return(RedirectToAction("Index", "Home")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } transaction.Rollback(); } catch (Exception ex) { transaction.Rollback(); ModelState.AddModelError("", ex.Message); } } mdl.CaptchaData.GenrateCaptcha(captchaGenratorBase); return(View(mdl)); }
public void GenrateCaptcha(ICaptchaGenratorBase icgb) { var temp = icgb.getCaptcha(); this.SaltId = temp.SaltId; this.CaptchaCode = temp.CaptchaCode; CaptchaImage = icgb.textToImageConversion(this.CaptchaCode); this.CaptchaCode = string.Empty; }
public IActionResult Registration([FromServices] ICaptchaGenratorBase captchaGenratorBase) { mdlCaptcha mdC = new mdlCaptcha(); mdC.GenrateCaptcha(captchaGenratorBase); mdlRegistration mdl = new mdlRegistration() { CaptchaData = mdC }; return(View(mdl)); }
public async Task <IActionResult> LoginAsync([FromServices] ICaptchaGenratorBase captchaGenratorBase, mdlLogin mdl, string?ReturnUrl) { mdlCaptcha mdC = new mdlCaptcha(); if (!captchaGenratorBase.verifyCaptch(mdl.CaptchaData.SaltId, mdl.CaptchaData.CaptchaCode)) { ModelState.AddModelError(mdl.CaptchaData.CaptchaCode, "Invalid Captcha"); } if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(mdl.Username, mdl.Password, mdl.RememberMe, true); if (result.Succeeded) { var user = await _signInManager.UserManager.FindByNameAsync(mdl.Username); if (user != null) { if (user.UserType == enmUserType.Consolidator) { if (!string.IsNullOrEmpty(ReturnUrl)) { return(LocalRedirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { if (ReturnUrl == "/") { return(RedirectToAction("Index", "Wing")); } if (!string.IsNullOrEmpty(ReturnUrl)) { return(LocalRedirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Wing")); } } } } ModelState.AddModelError("", "Invalid login attempts"); } mdl.CaptchaData.GenrateCaptcha(captchaGenratorBase); return(View(mdl)); }
public IActionResult Login([FromServices] ICaptchaGenratorBase captchaGenratorBase, string ReturnUrl) { ViewBag.ReturnUrl = ReturnUrl; mdlCaptcha mdC = new mdlCaptcha(); mdC.GenrateCaptcha(captchaGenratorBase); mdlLogin mdl = new mdlLogin() { CaptchaData = mdC }; return(View(mdl)); }
public bool ValidateCaptcha(ICaptchaGenratorBase icgb) { return(icgb.verifyCaptch(this.SaltId, this.CaptchaCode)); }