public IActionResult UsersList() { ViewBag.Success = TempData["Success"]; List <UserModel> usersList = adHelper.GetAllUsers(); // haetaan lista käyttäjistä HttpContext.Session.Set("usersListSession", usersList); //tallennetaan lista sessioon return(View(usersList)); }
public IActionResult ForgotPw(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var ad = adHelper.GetAllUsers(); var user = ad.Find(x => x.Email.ToLower() == model.Email.ToLower()); if (user == null) { return(RedirectToAction(nameof(ForgotPasswordConfirmation))); } else { MailMessage mail = new MailMessage { Subject = "mokkamoi!!", From = new MailAddress("*****@*****.**") }; ApplicationUser userA = new ApplicationUser(); userA.UserName = user.Username; Guid g = Guid.NewGuid(); string GuidString = Convert.ToBase64String(g.ToByteArray()); GuidString = GuidString.Replace("=", ""); GuidString = GuidString.Replace("+", ""); var callbackUrl = Url.ResetPasswordCallbackLink(user.Username, GuidString, Request.Scheme); try { PasswordCode result = (from p in _context.PasswordCode where p.Username == user.Username select p).SingleOrDefault(); if (result == null)//jos käyttäjä ei ole ennen tehnyt salasananpalautusta tehdään uusi passwordcode { result = new PasswordCode { Username = user.Username }; } result.Code = GuidString;// tallennetaan käyttäjälle salasanan palautus tiedot result.IsUsed = false; result.TimeStamp = DateTime.Now; _context.Update(result); _context.SaveChanges(); } catch (Exception) { } mail.To.Add(user.Email); mail.Body = $"Reset password link: {callbackUrl}"; mail.IsBodyHtml = true; adHelper.SendMail(mail, user.Email); } return(RedirectToAction(nameof(ForgotPasswordConfirmation))); } // If we got this far, something failed, redisplay form return(View()); }