public ActionResult GetAcountInfo(user user, borrower borrower, string newpassword = null) { //Knyter samman user och borrower -objekten BorrowerWithUser borrowerWithUser = new BorrowerWithUser() { User = user, Borrower = borrower }; Auth _auth = new Auth((BorrowerWithUser)Session["User"]); if (_auth.HasUserPermission()) { if (ModelState.IsValid) { if (user.Password != null && PasswordService.VerifyPassword(user.Password, _auth.LoggedInUser.User.Password)) { if (UserService.EmailExists(user.Email) && _auth.LoggedInUser.User.Email != user.Email) { borrowerWithUser.PushAlert(AlertView.Build("Email existerar. Försök igen!", AlertType.Danger)); return(View(borrowerWithUser)); } if (!_auth.IsSameAs(borrowerWithUser, newpassword)) { if (newpassword == "") { UserService.Update(borrowerWithUser, user.Password); } else { if (!PasswordValidaton.IsValid(newpassword)) { borrowerWithUser.PushAlert(AlertView.Build(PasswordValidaton.ErrorMessage, AlertType.Danger)); return(View(borrowerWithUser)); } UserService.Update(borrowerWithUser, newpassword); } borrowerWithUser.PushAlert(AlertView.Build("Du har uppdaterat ditt konto.", AlertType.Success)); Session["User"] = BorrowerService.GetBorrowerWithUserByPersonId(user.PersonId); return(View(borrowerWithUser)); } else { borrowerWithUser.PushAlert(AlertView.Build("Inget har uppdaterats.", AlertType.Info)); return(View(borrowerWithUser)); } } borrowerWithUser.PushAlert(AlertView.Build("Du måste ange ditt eget lösenord.", AlertType.Danger)); return(View(borrowerWithUser)); } return(View(borrowerWithUser)); } return(Redirect("/Error/Code/403")); }
public ActionResult Borrower(BorrowerWithUser BorrowerWithUser) { if (new Auth((BorrowerWithUser)Session["User"]).HasAdminPermission()) { if (ModelState.IsValid && (BorrowerWithUser.Borrower.CategoryId == 1 || BorrowerWithUser.Borrower.CategoryId == 2 || BorrowerWithUser.Borrower.CategoryId == 3 || BorrowerWithUser.Borrower.CategoryId == 4)) { user tempU = AuthService.GetUserByPersonId(BorrowerWithUser.Borrower.PersonId); if (BorrowerWithUser.User != null && !(UserService.EmailExists(BorrowerWithUser.User.Email) && BorrowerWithUser.User.Email != tempU.Email)) { UserService.Update(BorrowerWithUser, null); } else { BorrowerService.UpdateBorrower(BorrowerWithUser.Borrower); } TempData["Alert"] = AlertView.Build("Du har uppdaterat låntagaren.", AlertType.Success); return(RedirectToAction("/Borrower/" + BorrowerWithUser.Borrower.PersonId)); } return(View(BorrowerService.GetBorrowerWithBorrows(BorrowerWithUser.Borrower.PersonId))); } return(Redirect("/Error/Code/403")); }
public static BorrowerWithUser GetBorrowerWithUserByPersonId(string PersonId) { BorrowerWithUser activeUser = new BorrowerWithUser(); activeUser.User = AuthService.GetUserByPersonId(PersonId); activeUser.Borrower = BorrowerRepository.GetBorrower(activeUser.User.PersonId); return(activeUser); }
public static bool BorrowerIsUser(BorrowerWithUser b, string personId) { if (b.User.PersonId == personId) { return(true); } return(false); }
public static void Update(BorrowerWithUser user, string password) { if (password != null) { user.User.Password = PasswordService.CreateHash(password); } else { user.User.Password = AuthService.GetUserByPersonId(user.User.PersonId).Password; } UserRepository.UpdateUser(user.User.PersonId, user.User); BorrowerService.UpdateBorrower(user.Borrower); }
public ActionResult Login(string email, string password) { if (AuthService.Login(email, password)) { BorrowerWithUser b = BorrowerService.GetBorrowerWithUserByEmail(email); Session["User"] = b; Session["Permissions"] = b.User.RoleId; return(Redirect("/")); } TempData["Alert"] = AlertView.Build("Fel email eller lösenord. Försök igen!", AlertType.Danger); return(View()); }
public bool IsSameAs(BorrowerWithUser b, string newpassword) { if ((this.LoggedInUser.Borrower.Address == b.Borrower.Address) && (this.LoggedInUser.Borrower.FirstName == b.Borrower.FirstName) && (this.LoggedInUser.Borrower.CategoryId == b.Borrower.CategoryId) && (this.LoggedInUser.Borrower.LastName == b.Borrower.LastName) && (this.LoggedInUser.Borrower.Telno == b.Borrower.Telno) && (newpassword == "") && (this.LoggedInUser.User.Email == b.User.Email) && (this.LoggedInUser.User.PersonId == b.User.PersonId) && (this.LoggedInUser.User.RoleId == b.User.RoleId)) { return(true); } else { return(false); } }
public Auth(BorrowerWithUser b) { _loggedInUser = b; }