public IActionResult Login(UserLoginModel u) { bool status; TutorProfileModel tp = new TutorProfileModel(); UserDB udb = new UserDB(); StepsDB sdb = new StepsDB(); tp.TutorProfile = udb.UserLogin(u.Email, u.Password, GetConfiguration().GetConnectionString("DefaultConnection")); if (tp.TutorProfile != null) { HttpContext.Session.SetString("UserName", tp.TutorProfile.FirstName + "." + tp.TutorProfile.LastName); HttpContext.Session.SetInt32("UserId", (int)tp.TutorProfile.UserId); HttpContext.Session.SetInt32("TutorId", (int)tp.TutorProfile.Id); status = sdb.CheckCompletedSteps(tp.TutorProfile.UserId, 1, tp.TutorProfile.Id, GetConfiguration().GetConnectionString("DefaultConnection")); if (status == true) { return(RedirectToAction("Subjects", "TutorProfile")); } else { return(RedirectToAction("Questionnaire", "TutorProfile")); } } else { ViewData["Message"] = "User Login Details failed !!"; } return(View()); }
public IActionResult LoginView(LoginModel model) { string conStr = GetConfiguration().GetConnectionString(DEFAULT_CONNECTION); if (model == null && TempData["LoginModel"] != null) { string modelStr = TempData["LoginModel"].ToString(); model = JsonConvert.DeserializeObject <LoginModel>(modelStr); } User user = UserDB.Login(model.User.Type, model.User.Email, model.User.Password, model.User.TimezoneOffset, conStr); if (user != null) { if (model.Token != null) { model.Token.Approved = true; } else { model.Token = new AccessToken { Approved = false }; } user.Picture = null; //because picture is too long for the uri HttpContext.Response.Cookies.Append("user", JsonConvert.SerializeObject(user), cookieOptions); //new CookieOptions() { Path = "/", Domain = null, IsEssential = true }); if (user.Type == EntityType.Tutor) { Tutor tutor = (Tutor)user; TutorModel tutorModel = new TutorModel { User = tutor, Languages = AppContentDB.GetLanguages(conStr) }; string tutorStr = JsonConvert.SerializeObject(tutorModel); HttpContext.Response.Cookies.Append("tutor", tutorStr, cookieOptions); TempData["TutorModel"] = tutorStr; if (tutorModel.RedirectController != null && tutorModel.RedirectController.Length > 0) { string controller = tutorModel.RedirectController; tutorModel.RedirectController = null; if (tutorModel.RedirectAction != null && tutorModel.RedirectAction.Length > 0) { string action = tutorModel.RedirectAction; tutorModel.RedirectAction = null; return(RedirectToAction(action, controller)); //, tutorModel); } return(RedirectToAction(null, controller)); //, tutorModel); } RegistrationStep step = StepsDB.NextRegStep(user.UserId, 1, (byte)user.Type, model.Language, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION)); if (step != null) { return(RedirectToAction(step.UIName, "Tutor")); } } else if (user.Type == EntityType.Student) { //jinan Student student = (Student)user; HttpContext.Session.Set("StudentId", NumberUtil.ToBytes(student.Id)); student.RegStepsCompleted = StepsDB.CheckCompletedSteps(user.UserId, 1, (byte)user.Type, conStr); StudentModel studentModel = new StudentModel { User = student, Languages = AppContentDB.GetLanguages(conStr) }; string studentStr = JsonConvert.SerializeObject(studentModel); HttpContext.Response.Cookies.Append("student", studentStr, cookieOptions); TempData["StudentModel"] = studentStr; if (studentModel.RedirectController != null && studentModel.RedirectController.Length > 0) { string controller = studentModel.RedirectController; studentModel.RedirectController = null; if (studentModel.RedirectAction != null && studentModel.RedirectAction.Length > 0) { string action = studentModel.RedirectAction; studentModel.RedirectAction = null; return(RedirectToAction(action, controller)); //, studentModel); } return(RedirectToAction(null, controller)); //, studentModel); } if (student.RegStepsCompleted) { return(RedirectToAction("DisplayDashboard", "Student")); } } } else { ViewData["Message"] = "User Login failed !!"; Response.StatusCode = (int)HttpStatusCode.BadRequest; } return(RedirectToAction("Index", "Home")); }