/// <summary> /// Sets the user context. /// </summary> /// <param name="model">The model.</param> /// <param name="identity">The identity.</param> private void SetUserContext(StartScreenViewModel model, MQ1Identity identity) { SetLocale(identity.Locale); // use new Owin auth // FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); ApplicationContext.User = HttpContext.User; var claims = new List<Claim> { new Claim(ClaimTypes.Name, model.UserName) }; var id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = model.RememberMe }, id); }
/// <summary>Shared by ActionResult Login and SamlConsumer.</summary> /// <param name="model">The model.</param> /// <param name="returnUrl">The return URL.</param> /// <param name="identity">The identity.</param> /// <returns></returns> private ActionResult LoginRedirect(StartScreenViewModel model, string returnUrl, MQ1Identity identity) { if (HttpContext != null) { model.RememberMe &= SystemOptionsEdit.GetSysOptionsInfo().AllowRememberMe; SetUserContext(model, identity); } return Redirect(Url.Action("Index", "Default")); }
/// <summary> /// Sets the principal. /// </summary> /// <param name="identity">The identity.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool SetPrincipal(MQ1Identity identity) { if (identity.IsAuthenticated) { var principal = new MQ1Principal(identity); ApplicationContext.User = principal; } return identity.IsAuthenticated; }
/// <summary>Shared by ActionResult Login and SamlConsumer.</summary> /// <param name="model">The model.</param> /// <param name="returnUrl">The return URL.</param> /// <param name="identity">The identity.</param> /// <returns></returns> private ActionResult LoginRedirect(StartScreenViewModel model, string returnUrl, MQ1Identity identity) { if (HttpContext != null) { model.RememberMe &= SystemOptionsEdit.GetSysOptionsInfo().AllowRememberMe; SetUserContext(model, identity); } int fileId; if (int.TryParse(model.DeepLink, out fileId)) { return Redirect("~/DocHandler.ashx?FileId=" + fileId); } if (!string.IsNullOrEmpty(model.InitParams)) { var queryString = HttpUtility.ParseQueryString(model.InitParams); if (queryString.HasKeys() && !string.IsNullOrEmpty(queryString["FileId"])) return Redirect("~/DocHandler.ashx" + model.InitParams); if (queryString.HasKeys() && !string.IsNullOrEmpty(queryString[Constants.FileProcessFileName])) return Redirect("~/DocHandler.ashx" + model.InitParams); } var url = returnUrl ?? Url.Action("Index", "Default"); if (!string.IsNullOrWhiteSpace(model.DeepLink)) { url += "#" + model.DeepLink; } GetLogger().Info("Redirect to " + url); return Redirect(url); }
/// <summary> /// Begins the change password. /// </summary> /// <param name="identity">The identity.</param> /// <param name="password">The password.</param> /// <param name="newPassword">The new password.</param> /// <param name="confirmPassword">The confirm password.</param> /// <param name="callback">The callback.</param> public static void BeginChangePassword(MQ1Identity identity, string password, string newPassword, string confirmPassword, EventHandler<DataPortalResult<ChangePasswordCommand>> callback) { MQ1Identity.ChangePassword(identity, password, newPassword, confirmPassword, callback); }