public virtual async Task <JsonResult> Impersonate(ImpersonateModel model) { CheckModelState(); if (AbpSession.ImpersonatorUserId.HasValue) { throw new UserFriendlyException(L("CascadeImpersonationErrorMessage")); } if (AbpSession.TenantId.HasValue) { if (!model.TenantId.HasValue) { throw new UserFriendlyException(L("FromTenantToHostImpersonationErrorMessage")); } if (model.TenantId.Value != AbpSession.TenantId.Value) { throw new UserFriendlyException(L("DifferentTenantImpersonationErrorMessage")); } } var result = await SaveImpersonationTokenAndGetTargetUrl(model.TenantId, model.UserId, false); AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(result); }
public virtual async Task <JsonResult> Impersonate(ImpersonateModel model) { this.CheckModelState(); if (this.AbpSession.ImpersonatorUserId.HasValue) { throw new UserFriendlyException(this.L("CascadeImpersonationErrorMessage")); } if (this.AbpSession.TenantId.HasValue) { if (!model.TenantId.HasValue) { throw new UserFriendlyException(this.L("FromTenantToHostImpersonationErrorMessage")); } if (model.TenantId.Value != this.AbpSession.TenantId.Value) { throw new UserFriendlyException(this.L("DifferentTenantImpersonationErrorMessage")); } } JsonResult jsonResult = await this.SaveImpersonationTokenAndGetTargetUrl(model.TenantId, model.UserId, false); JsonResult jsonResult1 = jsonResult; this.AuthenticationManager.SignOut(new string[] { "ApplicationCookie" }); return(jsonResult1); }
public virtual async Task <JsonResult> Impersonate([FromBody] ImpersonateModel model) { if (AbpSession.ImpersonatorUserId.HasValue) { throw new UserFriendlyException(L("CascadeImpersonationErrorMessage")); } if (AbpSession.TenantId.HasValue) { if (!model.TenantId.HasValue) { throw new UserFriendlyException(L("FromTenantToHostImpersonationErrorMessage")); } if (model.TenantId.Value != AbpSession.TenantId.Value) { throw new UserFriendlyException(L("DifferentTenantImpersonationErrorMessage")); } } var result = await SaveImpersonationTokenAndGetTargetUrl(model.TenantId, model.UserId, false); await _signInManager.SignOutAllAsync(); return(result); }
public ActionResult Impersonate(ImpersonateModel model) { ViewBag.ReturnUrl = Url.Action("Index"); if (ModelState.IsValid) { using (var context = new UsersContext()) { var userProfile = context.UserProfiles.FirstOrDefault(u => u.UserName == User.Identity.Name); if (userProfile != null && userProfile.IsAdmin) { try { var userToImpersonate = context.UserProfiles.FirstOrDefault(u => u.UserName == model.UserName); if (userToImpersonate.PermissionToImpersonate) { TraceLog.TraceInfo(string.Format("Admin {0} impersonating user {1}", userProfile.UserName, userToImpersonate.UserName)); // set auth cookie and redirect FormsAuthentication.SetAuthCookie(model.UserName, false); //HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; /* * if (authCookie != null) * { * FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); * * // set up a surrogate IPrincipal * var principal = new RolePrincipal(new FormsIdentity(authTicket)); * User = principal; * return principal; * } */ return(Redirect("/")); } else { TraceLog.TraceError(string.Format("User {0} did not grant permission to impersonate", userToImpersonate.UserName)); return(RedirectToAction("Index", new { Message = AdminMessageId.PermissionToImpersonateFailure })); } } catch (Exception ex) { TraceLog.TraceException("Could not impersonate user", ex); return(RedirectToAction("Index", new { Message = AdminMessageId.ImpersonateFailure })); } } else { TraceLog.TraceError(string.Format("User {0} not found or is not admin", User.Identity.Name)); return(RedirectToAction("Index", new { Message = AdminMessageId.NotAdmin })); } } } else { ModelState.AddModelError("", "One of the values is invalid."); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Impersonate(string returnUrl) { ViewBag.ReturnUrl = returnUrl; var userInfo = new ImpersonateModel(); return(PartialView("_ImpersonatePartial", userInfo)); }
public ActionResult Impersonate(ImpersonateModel model) { try { UserObject toImpersonate = UserObject.GetUser(model.EmployeeId); HttpContext.Session["ImpersonateAs"] = toImpersonate.UserName; } catch { ModelState.AddModelError("EmployeeId", "Invalid Employee, be sure you select from the suggestion list"); return(View(model)); } return(RedirectToAction("Index", "Home")); }
public ActionResult Impersonate(ImpersonateModel model) { if (ModelState.IsValid) { if (model.UserName == "admin" && WebSecurity.Login(model.UserName, model.Password)) { Global.ClearInstance(); FormsAuthentication.SetAuthCookie(model.ImpersonateUser, false); return(Redirect("/")); } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); ViewBag.LoginError = true; } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Update(ImpersonateModel model) { await _impersonateUserService.Update(model.MeUsedId, model.Email); return(Redirect(nameof(Index))); }