public IActionResult Index() { if (string.IsNullOrEmpty(HttpContext.Session.GetString("userEmail"))) { TempData["msg"] = "Please login to proceed."; return(RedirectToAction("Index", "Login")); } else { if (string.IsNullOrEmpty(HttpContext.Session.GetString("roomId"))) { TempData["msg"] = "Invalid room id."; return(RedirectToAction("Index", "Main")); } else { var roomid = HttpContext.Session.GetString("roomId"); var users = _roomUserDB.getUsersInRoom(roomid); var userList = new List <User>(); foreach (string temp in users) { userList.Add(_userDB.getUser(temp)); } return(View("~/Views/MyRoom/MyRoom.cshtml", userList)); } } }
public IActionResult Login([Bind] User user) { try { if (ModelState.IsValid) { var result = _userDB.loginUser(user); if (result.error) { TempData["msg"] = result.message; return(View("~/Views/Login/Index.cshtml")); } else { var temp = _userDB.getUser(user); if (temp != null) { _userDB.updateUserSignIn(temp.user_email); HttpContext.Session.SetString("firstName", temp.user_first_name); HttpContext.Session.SetString("lastName", temp.user_last_name); HttpContext.Session.SetString("userEmail", temp.user_email); HttpContext.Session.SetString("userRole", temp.user_role); Activity activity = new Activity { user_email = temp.user_email, user_first_name = temp.user_first_name, user_last_name = temp.user_last_name, activity_type = "Sign in", activity_details = "", last_activity = DateTime.Now, }; _activityDB.logActivity(activity); TempData["msg"] = result.message; return(RedirectToAction("Index", "Main")); } else { TempData["msg"] = "Failed to retrieve user information."; return(View("~/Views/Login/Index.cshtml")); } } } } catch (Exception e) { TempData["msg"] = e.Message; } return(View("~/Views/Login/Index.cshtml")); }
public IActionResult GetUserInfo() { var result = _userDB.getUser(HttpContext.Session.GetString("userEmail")); return(Ok(result)); }