public ActionResult ChangeUserPass(ChangeUserPassword user) { var email = User.Identity.Name; if (_kundeBLL.ChangeUserPass(user, email)) { return RedirectToAction("Index", "Manage"); } ModelState.AddModelError("", "Problem med bytte passord, forsøk igjen"); return View(user); }
public bool byttPassord(ChangeUserPassword ansatt,string anr) { return _repository.byttPassord(ansatt, anr); }
public bool ChangeUserPass(ChangeUserPassword user, string email) { return _repository.ChangeUserPass(user, email); }
public bool ChangeUserPass(ChangeUserPassword user, string email) { if (user.OldPassword == null || email == null) return false; return true; }
public void endrepassord_post_ok() { /*var mock = new Mock<ControllerContext>(); var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()), new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub())); controller.ControllerContext = mock.Object; controller.ViewData.ModelState.AddModelError("", "Feil"); var resultat = (ViewResult)controller.registrerAdmin(null, "Leder"); //act //assert Assert.IsTrue(resultat.ViewData.ModelState.Count == 1); Assert.IsTrue(resultat.ViewName == "");*/ var mock = new Mock<ControllerContext>(); mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true); mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("123"); var passord = new ChangeUserPassword() { Password = "******", OldPassword = "******", ConfirmPassword = "******", }; var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()), new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub())); controller.ControllerContext = mock.Object; var viewResult = (RedirectToRouteResult)controller.endrePassord(passord); Assert.AreEqual("Index", viewResult.RouteValues["Action"]); //<---view som blir vist hvis er requested-->) Assert.AreEqual("Admin", viewResult.RouteValues["Controller"]); }
public void endrepassord_post_notloggedin() { var mock = new Mock<ControllerContext>(); mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(false); mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns(""); var passord = new ChangeUserPassword(); var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()), new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub())); controller.ControllerContext = mock.Object; var viewResult = (ViewResult)controller.endrePassord(passord); Assert.IsTrue(viewResult.ViewName == ""); }
public bool ChangeUserPass(ChangeUserPassword user, string email) { try { if (email == null || email == "" || user.OldPassword == null || user.OldPassword == "" || user.Password == null || user.Password == "") return false; var UserDB = db.Users.FirstOrDefault(u => u.Email == email); if (UserDB != null) { if (isValid(email, user.OldPassword)) { if (!(user.OldPassword == user.Password)) { var crypto = new SimpleCrypto.PBKDF2(); var encryPass = crypto.Compute(user.Password); UserDB.Password = encryPass; UserDB.PasswordSalt = crypto.Salt; db.SaveChanges(); return true; } } } return false; } catch (System.Data.SqlClient.SqlException ex) { SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (InvalidOperationException ex) { SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (ArgumentException ex) { SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (NullReferenceException ex) { SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (SystemException ex) { SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } catch (Exception ex) { SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace + "" + Environment.NewLine + "Date :" + DateTime.Now.ToString()); SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine); } return false; }