protected void Page_Load(object sender, EventArgs e) { if (CoreContext.Configuration.CustomMode) { return; } Page .RegisterStyle("~/UserControls/Statistics/PortalAnalytics/css/portalanalytics.less") .RegisterBodyScripts("~/UserControls/Statistics/PortalAnalytics/js/portalanalytics.js"); if (TenantExtra.Opensource) { Enabled = true; SwitchedOn = WizardSettings.Load().Analytics; } else if (TenantExtra.Saas && SetupInfo.CustomScripts.Length != 0) { Enabled = true; SwitchedOn = TenantAnalyticsSettings.Load().Analytics; } }
public bool UpdatePortalAnalytics(bool enable) { SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); if (!(TenantExtra.Opensource || (TenantExtra.Saas && SetupInfo.CustomScripts.Length != 0)) || CoreContext.Configuration.CustomMode) { throw new SecurityException(); } if (TenantExtra.Opensource) { var wizardSettings = WizardSettings.Load(); wizardSettings.Analytics = enable; wizardSettings.Save(); } else if (TenantExtra.Saas) { var analyticsSettings = TenantAnalyticsSettings.Load(); analyticsSettings.Analytics = enable; analyticsSettings.Save(); } return(enable); }
protected void Page_Load(object sender, EventArgs e) { Page.RegisterBodyScripts("~/js/third-party/xregexp.js", "~/UserControls/Management/ConfirmInviteActivation/js/confirm_invite_activation.js") .RegisterStyle("~/UserControls/Management/ConfirmInviteActivation/css/confirm_invite_activation.less"); var uid = Guid.Empty; try { uid = new Guid(Request["uid"]); } catch { } var email = GetEmailAddress(); if (_type != ConfirmType.Activation && AccountLinkControl.IsNotEmpty && !CoreContext.Configuration.Personal) { var thrd = (AccountLinkControl)LoadControl(AccountLinkControl.Location); thrd.InviteView = true; thrd.ClientCallback = "loginJoinCallback"; thrdParty.Visible = true; thrdParty.Controls.Add(thrd); } Page.Title = HeaderStringHelper.GetPageTitle(Resource.Authorization); UserInfo user; try { SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); user = CoreContext.UserManager.GetUserByEmail(email); var usr = CoreContext.UserManager.GetUsers(uid); if (usr.ID.Equals(Constants.LostUser.ID) || usr.ID.Equals(ASC.Core.Configuration.Constants.Guest.ID)) { usr = CoreContext.UserManager.GetUsers(CoreContext.TenantManager.GetCurrentTenant().OwnerId); } var photoData = UserPhotoManager.GetUserPhotoData(usr.ID, UserPhotoManager.MediumFotoSize); _userAvatar = photoData == null?usr.GetMediumPhotoURL() : "data:image/png;base64," + Convert.ToBase64String(photoData); _userName = usr.DisplayUserName(true); _userPost = (usr.Title ?? "").HtmlEncode(); } finally { SecurityContext.Logout(); } if (_type == ConfirmType.LinkInvite || _type == ConfirmType.EmpInvite) { if (TenantStatisticsProvider.GetUsersCount() >= TenantExtra.GetTenantQuota().ActiveUsers&& _employeeType == EmployeeType.User) { ShowError(UserControlsCommonResource.TariffUserLimitReason); return; } if (!user.ID.Equals(Constants.LostUser.ID)) { ShowError(CustomNamingPeople.Substitute <Resource>("ErrorEmailAlreadyExists")); return; } } else if (_type == ConfirmType.Activation) { if (user.IsActive) { Response.Redirect(CommonLinkUtility.GetDefault()); return; } if (user.ID.Equals(Constants.LostUser.ID) || user.Status == EmployeeStatus.Terminated) { ShowError(string.Format(Resource.ErrorUserNotFoundByEmail, email)); return; } } var tenant = CoreContext.TenantManager.GetCurrentTenant(); if (tenant != null) { var settings = IPRestrictionsSettings.Load(); if (settings.Enable && !IPSecurity.IPSecurity.Verify(tenant)) { ShowError(Resource.ErrorAccessRestricted); return; } } if (!IsPostBack) { return; } var firstName = GetFirstName(); var lastName = GetLastName(); var passwordHash = (Request["passwordHash"] ?? "").Trim(); var analytics = (Request["analytics"] ?? "").Trim() == "True"; var mustChangePassword = false; LoginProfile thirdPartyProfile; //thirdPartyLogin confirmInvite if (Request["__EVENTTARGET"] == "thirdPartyLogin") { var valueRequest = Request["__EVENTARGUMENT"]; thirdPartyProfile = new LoginProfile(valueRequest); if (!string.IsNullOrEmpty(thirdPartyProfile.AuthorizationError)) { // ignore cancellation if (thirdPartyProfile.AuthorizationError != "Canceled at provider") { ShowError(HttpUtility.HtmlEncode(thirdPartyProfile.AuthorizationError)); } return; } if (string.IsNullOrEmpty(thirdPartyProfile.EMail)) { ShowError(HttpUtility.HtmlEncode(Resource.ErrorNotCorrectEmail)); return; } } if (Request["__EVENTTARGET"] == "confirmInvite") { if (String.IsNullOrEmpty(email)) { _errorMessage = Resource.ErrorEmptyUserEmail; return; } if (!email.TestEmailRegex()) { _errorMessage = Resource.ErrorNotCorrectEmail; return; } if (String.IsNullOrEmpty(firstName)) { _errorMessage = Resource.ErrorEmptyUserFirstName; return; } if (String.IsNullOrEmpty(lastName)) { _errorMessage = Resource.ErrorEmptyUserLastName; return; } if (String.IsNullOrEmpty(passwordHash)) { _errorMessage = Resource.ErrorPasswordEmpty; return; } } var userID = Guid.Empty; try { SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); if (_type == ConfirmType.EmpInvite || _type == ConfirmType.LinkInvite) { if (TenantStatisticsProvider.GetUsersCount() >= TenantExtra.GetTenantQuota().ActiveUsers&& _employeeType == EmployeeType.User) { ShowError(UserControlsCommonResource.TariffUserLimitReason); return; } UserInfo newUser; if (Request["__EVENTTARGET"] == "confirmInvite") { var fromInviteLink = _type == ConfirmType.LinkInvite; newUser = CreateNewUser(firstName, lastName, email, passwordHash, _employeeType, fromInviteLink); var messageAction = _employeeType == EmployeeType.User ? MessageAction.UserCreatedViaInvite : MessageAction.GuestCreatedViaInvite; MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, messageAction, MessageTarget.Create(newUser.ID), newUser.DisplayUserName(false)); userID = newUser.ID; var settings = TenantAnalyticsSettings.LoadForCurrentUser(); settings.Analytics = analytics; settings.SaveForCurrentUser(); } if (Request["__EVENTTARGET"] == "thirdPartyLogin") { if (String.IsNullOrEmpty(passwordHash)) { passwordHash = UserManagerWrapper.GeneratePassword(); mustChangePassword = true; } var valueRequest = Request["__EVENTARGUMENT"]; thirdPartyProfile = new LoginProfile(valueRequest); newUser = CreateNewUser(GetFirstName(thirdPartyProfile), GetLastName(thirdPartyProfile), GetEmailAddress(thirdPartyProfile), passwordHash, _employeeType, false); var messageAction = _employeeType == EmployeeType.User ? MessageAction.UserCreatedViaInvite : MessageAction.GuestCreatedViaInvite; MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, messageAction, MessageTarget.Create(newUser.ID), newUser.DisplayUserName(false)); userID = newUser.ID; if (!String.IsNullOrEmpty(thirdPartyProfile.Avatar)) { SaveContactImage(userID, thirdPartyProfile.Avatar); } var linker = new AccountLinker("webstudio"); linker.AddLink(userID.ToString(), thirdPartyProfile); } } else if (_type == ConfirmType.Activation) { if (!UserFormatter.IsValidUserName(firstName, lastName)) { throw new Exception(Resource.ErrorIncorrectUserName); } SecurityContext.SetUserPasswordHash(user.ID, passwordHash); user.ActivationStatus = EmployeeActivationStatus.Activated; user.FirstName = firstName; user.LastName = lastName; CoreContext.UserManager.SaveUserInfo(user); userID = user.ID; //notify if (user.IsVisitor()) { StudioNotifyService.Instance.GuestInfoAddedAfterInvite(user); MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, MessageAction.GuestActivated, MessageTarget.Create(user.ID), user.DisplayUserName(false)); } else { StudioNotifyService.Instance.UserInfoAddedAfterInvite(user); MessageService.Send(HttpContext.Current.Request, MessageInitiator.System, MessageAction.UserActivated, MessageTarget.Create(user.ID), user.DisplayUserName(false)); } } } catch (SecurityContext.PasswordException) { _errorMessage = HttpUtility.HtmlEncode(Resource.ErrorPasswordRechange); return; } catch (Exception exception) { _errorMessage = HttpUtility.HtmlEncode(exception.Message); return; } finally { SecurityContext.Logout(); } user = CoreContext.UserManager.GetUsers(userID); try { var cookiesKey = SecurityContext.AuthenticateMe(user.Email, passwordHash); CookiesManager.SetCookies(CookiesType.AuthKey, cookiesKey); MessageService.Send(HttpContext.Current.Request, MessageAction.LoginSuccess); StudioNotifyService.Instance.UserHasJoin(); if (mustChangePassword) { StudioNotifyService.Instance.UserPasswordChange(user); } } catch (Exception exception) { (Page as Confirm).ErrorMessage = HttpUtility.HtmlEncode(exception.Message); return; } UserHelpTourHelper.IsNewUser = true; if (CoreContext.Configuration.Personal) { PersonalSettings.IsNewUser = true; } Response.Redirect(CommonLinkUtility.GetDefault()); }
public static UserInfo GetUserByThirdParty(LoginProfile loginProfile) { try { if (!string.IsNullOrEmpty(loginProfile.AuthorizationError)) { // ignore cancellation if (loginProfile.AuthorizationError != "Canceled at provider") { throw new Exception(loginProfile.AuthorizationError); } return(Constants.LostUser); } var userInfo = Constants.LostUser; Guid userId; if (TryGetUserByHash(loginProfile.HashId, out userId)) { userInfo = CoreContext.UserManager.GetUsers(userId); } var isNew = false; if (CoreContext.Configuration.Personal) { if (CoreContext.UserManager.UserExists(userInfo.ID) && SetupInfo.IsSecretEmail(userInfo.Email)) { try { SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); CoreContext.UserManager.DeleteUser(userInfo.ID); userInfo = Constants.LostUser; } finally { SecurityContext.Logout(); } } if (!CoreContext.UserManager.UserExists(userInfo.ID)) { userInfo = JoinByThirdPartyAccount(loginProfile); isNew = true; } } if (isNew) { var spam = HttpContext.Current.Request["spam"]; if (spam != "on") { try { const string _databaseID = "com"; using (var db = DbManager.FromHttpContext(_databaseID)) { db.ExecuteNonQuery(new SqlInsert("template_unsubscribe", false) .InColumnValue("email", userInfo.Email.ToLowerInvariant()) .InColumnValue("reason", "personal") ); LogManager.GetLogger("ASC.Web").Debug(String.Format("Write to template_unsubscribe {0}", userInfo.Email.ToLowerInvariant())); } } catch (Exception ex) { LogManager.GetLogger("ASC.Web").Debug(String.Format("ERROR write to template_unsubscribe {0}, email:{1}", ex.Message, userInfo.Email.ToLowerInvariant())); } } var analytics = HttpContext.Current.Request["analytics"] == "on"; var settings = TenantAnalyticsSettings.LoadForCurrentUser(); settings.Analytics = analytics; settings.SaveForCurrentUser(); StudioNotifyService.Instance.UserHasJoin(); UserHelpTourHelper.IsNewUser = true; PersonalSettings.IsNewUser = true; } return(userInfo); } catch (Exception) { Auth.ProcessLogout(); throw; } }
protected void Page_Load(object sender, EventArgs e) { InitScripts(); HubUrl = ConfigurationManager.AppSettings["web.hub"] ?? string.Empty; if (!_enableWebChat.HasValue || _enableWebChat.Value) { EnabledWebChat = Convert.ToBoolean(ConfigurationManager.AppSettings["web.chat"] ?? "false") && WebItemManager.Instance.GetItems(WebZoneType.CustomProductList, ItemAvailableState.Normal). Any(id => id.ID == WebItemManager.TalkProductID) && !(Request.Browser != null && Request.Browser.Browser == "IE" && (Request.Browser.MajorVersion == 8 || Request.Browser.MajorVersion == 9 || Request.Browser.MajorVersion == 10)); } IsMobile = MobileDetector.IsMobile; if (!DisabledSidePanel && EnabledWebChat && !IsMobile) { SmallChatHolder.Controls.Add(LoadControl(UserControls.Common.SmallChat.SmallChat.Location)); } if (!DisabledSidePanel && !CoreContext.Configuration.Personal) { /** InvitePanel popup **/ InvitePanelHolder.Controls.Add(LoadControl(InvitePanel.Location)); } if ((!DisabledSidePanel || !DisabledTopStudioPanel) && !TopStudioPanel.DisableSettings && HubUrl != string.Empty && SecurityContext.IsAuthenticated) { AddBodyScripts(ResolveUrl, "~/js/third-party/socket.io.js", "~/js/asc/core/asc.socketio.js"); } if (!DisabledTopStudioPanel) { TopContent.Controls.Add(TopStudioPanel); } if (!EmailActivated && !CoreContext.Configuration.Personal && SecurityContext.IsAuthenticated && EmailActivationSettings.LoadForCurrentUser().Show) { activateEmailPanel.Controls.Add(LoadControl(ActivateEmailPanel.Location)); } if (AffiliateHelper.BannerAvailable || CoreContext.Configuration.Personal) { BannerHolder.Controls.Add(LoadControl(Banner.Location)); } if (ThirdPartyBanner.Display && !Request.DesktopApp()) { BannerHolder.Controls.Add(LoadControl(ThirdPartyBanner.Location)); } var curUser = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); if (!DisabledSidePanel) { TariffNotifyHolder.Controls.Add(LoadControl(TariffNotify.Location)); } if (curUser.IsVisitor() && !curUser.IsOutsider()) { var collaboratorPopupSettings = CollaboratorSettings.LoadForCurrentUser(); if (collaboratorPopupSettings.FirstVisit) { AddBodyScripts(ResolveUrl, "~/js/asc/core/collaborators.js"); } } #region third-party scripts if (TenantExtra.Saas) { if (SetupInfo.CustomScripts.Length != 0) { if (CoreContext.Configuration.Personal) { if (TenantAnalyticsSettings.LoadForCurrentUser().Analytics) { GoogleTagManagerPlaceHolder.Controls.Add(LoadControl("~/UserControls/Common/ThirdPartyScripts/GoogleTagManagerScript.ascx")); GoogleAnalyticsScriptPlaceHolder.Controls.Add(LoadControl("~/UserControls/Common/ThirdPartyScripts/GoogleAnalyticsScriptPersonal.ascx")); } } else { if (TenantAnalyticsSettings.Load().Analytics) { GoogleTagManagerPlaceHolder.Controls.Add(LoadControl("~/UserControls/Common/ThirdPartyScripts/GoogleTagManagerScript.ascx")); GoogleAnalyticsScriptPlaceHolder.Controls.Add(LoadControl("~/UserControls/Common/ThirdPartyScripts/GoogleAnalyticsScript.ascx")); } } } } else if (TenantExtra.Opensource && WizardSettings.Load().Analytics && SecurityContext.IsAuthenticated) { GoogleTagManagerPlaceHolder.Controls.Add(LoadControl("~/UserControls/Common/ThirdPartyScripts/GoogleTagManagerScript.ascx")); GoogleAnalyticsScriptPlaceHolder.Controls.Add(LoadControl("~/UserControls/Common/ThirdPartyScripts/GoogleAnalyticsScriptOpenSource.ascx")); } #endregion }