public ActionResult LoginCheck(LoginViewModel logInfos) { try { if (ModelState.IsValid) { // Move comparaison, and searching of person in an other layer PersonBAL balPerson = new PersonBAL(); Person personConnecting = balPerson.GetPersonByLogin(logInfos.Login, db); // Move comparaison in an other laver if (personConnecting != null && personConnecting.Password == HashService.GenerateSHA256String(logInfos.Password)) { Session["User"] = personConnecting; ViewBag.User = Session["User"]; return(RedirectToAction(nameof(HomeController.Index), "Home")); } else { Session["User"] = null; TempData["LoginError"] = "Invalid login or password"; return(RedirectToAction(nameof(AccountController.Login), "Account")); } } } catch (Exception) { ModelState.AddModelError("Error", "Error"); } Session["User"] = null; TempData["LoginError"] = "Invalid login or password"; return(RedirectToAction(nameof(AccountController.Login), "Account")); }
public ActionResult Add(PersonRegisterViewModel newAccount) { try { if (ModelState.IsValid) { PersonBAL balPerson = new PersonBAL(); if (balPerson.IsLoginValid(newAccount.Login, db)) { if (newAccount.Roles == EnumRoles.Student) { StudentBAL balStudent = new StudentBAL(); balStudent.CreateStudentRegistering(newAccount, db); } else { InstructorBAL balInstructor = new InstructorBAL(); balInstructor.CreateInstructorRegistering(newAccount, db); } // Move searching of person in an other layer // getPersonByLogin(newAccount.Login) Session["User"] = balPerson.GetPersonByLogin(newAccount.Login, db); return(RedirectToAction(nameof(HomeController.Index), "Home")); } else { TempData["LoginError"] = "This login already exists"; return(RedirectToAction(nameof(AccountController.Register), "Account")); } } } catch (Exception) { ModelState.AddModelError("Error", "Error"); } return(RedirectToAction(nameof(HomeController.Index), "Home")); }