public HttpResponseMessage Logout() { // Change user status to Offline var userId = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId(); var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); IConnectionRepository connectionRepository = new ConnectionRepository(new DataContext()); connectionRepository.RemoveUser(new Guid(userId), null); hub.Clients.All.onUserDisconnected(userId); HttpContext.Current.GetOwinContext().Authentication.SignOut(); return(Request.CreateResponse(HttpStatusCode.Accepted, true)); }
public ActionResult Edit(User user) { ViewBag.Departments = new SelectList(new DataContext().Departments, "Name", "Name"); ViewBag.Locations = new SelectList(new DataContext().Locations, "Name", "Name"); var username = HttpContext.GetOwinContext().Authentication.User.Identity.Name; var edituser = userRepository.GetUserByUsername(username); Guid guid = edituser.UserId; var hashhelper = new HashHelper(); user.UserId = guid; if (user == null || edituser == null || !CheckCurrentUser(guid)) { return(RedirectToAction("Index", "Profile")); } if (user.Password == null || user.Password.Equals("")) { user.Password = edituser.Password; } else { user.Password = hashhelper.Hash(user.Password); } userRepository.UpdateUser(user); userRepository.Save(); if (!user.Username.Equals(username)) { var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); IConnectionRepository connectionRepository = new ConnectionRepository(new DataContext()); connectionRepository.RemoveUser(guid, null); hub.Clients.All.onUserDisconnected(guid); HttpContext.GetOwinContext().Authentication.SignOut(); return(RedirectToAction("Index", "Home", new { successMessage = "Ihre Daten wurden erfolgreich geändert! Bitte loggen Sie sich erneut ein." })); } else { return(RedirectToAction("Show", "Profile", new { userId = guid.ToString() })); } }