public async Task <IActionResult> Login(LoginViewModel model) { try { if (ModelState.IsValid) { ViewBag.MailPasswordNotExist = "Exist"; ViewBag.MailExist = 0; ViewBag.PlayerNotActive = 0; ViewBag.HomeForgetPassword = "******"; ViewBag.PlayerNotExistMsg = "Exist"; ViewBag.ResetPasswordMsg = "NotResetPasswordMsg"; var plainText = EncHelper.Encryptdata(model.Password); var isValid = iplayerBusiness.IsValidPlayer(model.EmailId, plainText); Player playerdb = iplayerBusiness.GetPlayerByEmail(model.EmailId); if (!isValid) { var valid = iplayerBusiness.IsAccountValidated(model.EmailId.ToLower(), plainText); if (valid == 3) { ModelState.AddModelError("", "User is invalid"); ViewBag.MailExist = 3; return(View("ForgotPassword")); } if (valid == 1) { ModelState.AddModelError("", "User is invalid"); ViewBag.MailPasswordNotExist = "NotExist"; return(View("ForgotPassword")); } if (valid == 2) { ModelState.AddModelError("", "User is invalid"); ViewBag.PlayerNotActive = 2; return(View("ForgotPassword")); } ModelState.AddModelError("", "User is invalid"); ViewBag.MailNotExist = true; return(View("ForgotPassword")); } var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, playerdb.ScreenName)); identity.AddClaim(new Claim(ClaimTypes.Name, playerdb.ScreenName)); identity.AddClaim(new Claim("PlayerId", playerdb.PLayerId.ToString())); // identity.AddClaim(new Claim(ClaimTypes.Role, playerdb.Role.RoleName)); var principal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = model.RememberMe }); //Send Email string subject = "Login"; string body = "<p>Hello Sir/Mam,</p><b>Login Succesfull</b><br/>"; EmailHelper.SendEmail(model.EmailId, body, subject); //return RedirectToAction("Index", "Admin"); return(RedirectToAction("Index", "PlayerAccount")); } else { ModelState.AddModelError("", "Username or Password is blank"); return(View("ForgotPassword")); } } catch (Exception ex) { return(ErrorView(ex)); } }