private static bool TryByHashId(AccountLinkControl accountLinkControl, string hashId, out Guid userId) { userId = Guid.Empty; if (accountLinkControl == null || string.IsNullOrEmpty(hashId)) { return(false); } var accountsStrId = accountLinkControl.GetLinker().GetLinkedObjectsByHashId(hashId); userId = accountsStrId .Select(x => { try { return(new Guid(x)); } catch { return(Guid.Empty); } }) .Where(x => x != Guid.Empty) .FirstOrDefault(x => CoreContext.UserManager.UserExists(x)); return(true); }
private static bool TryByHashId(AccountLinkControl accountLinkControl, string hashId, out Guid userId) { userId = Guid.Empty; if (accountLinkControl == null || string.IsNullOrEmpty(hashId)) { return(false); } var linkedProfiles = accountLinkControl.GetLinker().GetLinkedObjectsByHashId(hashId); var tmp = Guid.Empty; if (linkedProfiles.Any(profileId => Guid.TryParse(profileId, out tmp) && CoreContext.UserManager.UserExists(tmp))) { userId = tmp; } return(true); }
protected void Page_Load(object sender, EventArgs e) { _login = ""; _password = ""; //Account link control AccountLinkControl accountLink = null; if (SetupInfo.ThirdPartyAuthEnabled) { accountLink = (AccountLinkControl)LoadControl(AccountLinkControl.Location); associateAccount.Visible = true; associateAccount.Text = Resources.Resource.LoginWithAccount; accountLink.ClientCallback = "authCallback"; accountLink.SettingsView = false; signInPlaceholder.Controls.Add(accountLink); } ((IStudioMaster)this.Master).DisabledSidePanel = true; //top panel if (this.Master is StudioTemplate) { ((StudioTemplate)this.Master).TopNavigationPanel.DisableProductNavigation = true; ((StudioTemplate)this.Master).TopNavigationPanel.DisableSearch = true; } _tenantInfoSettings = SettingsManager.Instance.LoadSettings <TenantInfoSettings>(TenantProvider.CurrentTenantID); this.Title = HeaderStringHelper.GetPageTitle(Resources.Resource.Authorization, null, null); pwdReminderHolder.Controls.Add(LoadControl(PwdTool.Location)); pwdReminderHolder.Controls.Add(LoadControl(InviteEmployeeControl.Location)); _communitations.Controls.Add(LoadControl(AuthCommunications.Location)); var msg = Request["m"]; if (!string.IsNullOrEmpty(msg)) { _loginMessage = "<div class='errorBox'>" + HttpUtility.HtmlEncode(msg) + "</div>"; } if (this.IsPostBack && !SecurityContext.IsAuthenticated) { var uData = new UserTransferData(); if (!String.IsNullOrEmpty(Request["login"])) { _login = Request["login"]; uData.Login = _login; } if (!String.IsNullOrEmpty(Request["pwd"])) { _password = Request["pwd"]; uData.Password = _password; } bool isDemo = false; if (!String.IsNullOrEmpty(Request["authtype"])) { isDemo = Request["authtype"] == "demo"; } string hashId = string.Empty; if (!string.IsNullOrEmpty(Request["__EVENTARGUMENT"]) && Request["__EVENTTARGET"] == "signInLogin" && accountLink != null) { //Login from open id hashId = Request["__EVENTARGUMENT"]; uData.HashId = hashId; } if (isDemo) { SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.Demo); } else { try { string cookiesKey = string.Empty; if (!string.IsNullOrEmpty(hashId)) { var accounts = accountLink.GetLinker().GetLinkedObjectsByHashId(hashId); foreach (var account in accounts.Select(x => { try { return(new Guid(x)); } catch { return(Guid.Empty); } })) { if (CoreContext.UserManager.UserExists(account) && account != Guid.Empty) { var coreAcc = CoreContext.UserManager.GetUsers(account); cookiesKey = SecurityContext.AuthenticateMe(coreAcc.Email, CoreContext.Authentication.GetUserPasswordHash(coreAcc.ID)); uData.UserId = coreAcc.ID; ProcessSmsValidation(uData); } } if (string.IsNullOrEmpty(cookiesKey)) { _loginMessage = "<div class=\"errorBox\">" + HttpUtility.HtmlEncode(Resources.Resource.LoginWithAccountNotFound) + "</div>"; return; } } else { cookiesKey = SecurityContext.AuthenticateMe(_login, _password); uData.UserId = SecurityContext.CurrentAccount.ID; ProcessSmsValidation(uData); } CookiesManager.SetCookies(CookiesType.AuthKey, cookiesKey); } catch (System.Security.SecurityException) { ProcessLogout(); _loginMessage = "<div class=\"errorBox\">" + HttpUtility.HtmlEncode(Resources.Resource.InvalidUsernameOrPassword) + "</div>"; return; } catch (Exception exception) { ProcessLogout(); _loginMessage = "<div class=\"errorBox\">" + HttpUtility.HtmlEncode(exception.Message) + "</div>"; return; } } UserOnlineManager.Instance.RegistryOnlineUser(SecurityContext.CurrentAccount.ID); WebItemManager.Instance.ItemGlobalHandlers.Login(SecurityContext.CurrentAccount.ID); string refererURL = (string)Session["refererURL"]; if (String.IsNullOrEmpty(refererURL)) { Response.Redirect("~/"); } else { Session["refererURL"] = null; Response.Redirect(refererURL); } return; } else if (SecurityContext.IsAuthenticated && base.IsLogout) { ProcessLogout(); Response.Redirect("~/auth.aspx"); } ProcessConfirmedEmailCondition(); }