public async Task <IActionResult> ReNewLoan([FromForm] LoanModel model) { if (ModelState.IsValid) { var result = await _loanRepo.ReNewLoan(model); if (result) { _ElasticEmailService = new ElasticEmailService(); string name = model.Surname + " " + model.GivenName; await _ElasticEmailService.Send(model.EmailAdress, "account created sussefully", name + " " + model.AccountNumber); //string emailSent = await _emailSending.Send(model.EmailAdress, "account created sussefully", name + " " + AccountNumber); //alert message TempData["Message"] = "Account number " + " " + model.AccountNumber + " " + " Successfully re-activated"; dynamic transRef = TempData["Message"]; Alert("success", transRef, NotificationType.success); return(RedirectToAction("Index", "Home")); } } else { TempData["Error"] = "bad"; } return(View(model)); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { //var open = "open"; if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) { // Don't reveal that the user does not exist or is not confirmed TempData["Message"] = "User Not exist."; } //if (model.Password.Trim().ToLower() == open) //{ //dosomething //var user = await UserManager.FindByNameAsync(model.Email); //var staff = _votMgr.GetVoters(model.Email); // if(staff == null) //{ // TempData["Message"] = "User Not exist."; //} //For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 //Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); _ElasticEmailService = new ElasticEmailService(); await _ElasticEmailService.Send(user.Email, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">Reset</a>"); //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("ForgotPasswordConfirmation", "Account")); //} //if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) //{ // // Don't reveal that the user does not exist or is not confirmed // return View("ForgotPasswordConfirmation"); //} } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = new ApplicationUser { Email = model.UserName, UserName = model.UserName }; string role; if (user.UserName == /*ConfigurationManager.AppSettings["adminusername"]*/ "*****@*****.**" && model.Password == /*ConfigurationManager.AppSettings["adminpassword"]*/ "admin123") { role = /*ConfigurationManager.AppSettings["Adminkey"]*/ "Admin"; } else if (user.UserName == /*ConfigurationManager.AppSettings["deptusername"]*/ "*****@*****.**" && model.Password == /*ConfigurationManager.AppSetting*//*s["deptpass"]*/ "deptleader") { role = /*ConfigurationManager.AppSettings["DeptLeaderRole"]*/ "DepartmentLeader"; } else { role = "User"; _ElasticEmailService = new ElasticEmailService(); await _ElasticEmailService.Send(user.Email, "registration was successfull", "Please reset yo <a href=\"" /*+ callbackUrl *//*+ *//*"\">Reset</a>"*/); } var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (!roleManager.RoleExists(role)) { var identityRole = new IdentityRole { Name = role }; roleManager.Create <IdentityRole, string>(identityRole); } bool checkrole = await userManager.IsInRoleAsync(user.Id, role); if (!checkrole && model.UserName == model.UserName) { result = await userManager.AddToRoleAsync(user.Id, role); } var identity = await userManager.CreateIdentityAsync(user, "ApplicationCookie"); Request.GetOwinContext().Authentication.SignIn(identity); return(RedirectToAction("Login", "Account")); } if (result.Errors.Any()) { foreach (var error in result.Errors) { ModelState.AddModelError("", error); } } return(View(model)); }