public IActionResult Register(RegistrationViewModel playerModel) { try { var countryList = icountryBusiness.GetCountries(); ViewBag.country = new SelectList(countryList, "CountryId", "CountryName"); if (ModelState.IsValid) { if (iplayerBusiness.IsPlayerExist(playerModel.EmailId.ToLower())) { ModelState.AddModelError("EmailId", "Email id already exist."); return(View()); } var plainText = EncHelper.Encryptdata(playerModel.Password); if (string.IsNullOrWhiteSpace(plainText)) { ModelState.AddModelError("", "Username or Password is invalid."); return(View()); } playerModel.EmailId = playerModel.EmailId.ToLower(); playerModel.CreatedDate = DateTime.Now; playerModel.Password = plainText; PlayerModel model = new PlayerModel(); Mapper.Map(playerModel, model); iplayerBusiness.AddNewPlayer(model); var lnkHref = "<a href='" + Url.Action("ActivateAccount", "Account", new { email = playerModel.EmailId }, "http") + "'>Click here</a>"; string subject = "Confirm Email"; string body = "Thank you to join us, please " + lnkHref + " to activate your account and proceed further."; EmailHelper.SendEmail(playerModel.EmailId, body, subject); return(RedirectToAction("RegistrationSuccessful", new { emailAddress = playerModel.EmailId })); } return(View()); } catch (Exception ex) { return(ErrorView(ex)); } }
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)); } }
public IActionResult ResetPassword(ResetPasswordViewModel model) { if (ModelState.IsValid) { Player playerModel = iplayerBusiness.UpdatePassword(new Guid(model.ReturnToken), model.EmailId, EncHelper.Encryptdata(model.NewPassword)); ViewBag.Message = playerModel != null ? 1 : 2; } return(View()); }