コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(this.GetType());
            this.Page.ClientScript.RegisterClientScriptInclude(GetType(), "ajaxupload_script", VirtualPathUtility.ToAbsolute("~/js/ajaxupload.3.5.js"));
            Page.ClientScript.RegisterClientScriptInclude(typeof (string), "greetingsettingscontent_script", WebPath.GetPath("usercontrols/management/greetingsettings/js/greetingsettingscontent.js"));

            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "greetingsettings_style", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + WebSkin.GetUserSkin().GetAbsoluteWebPath("usercontrols/management/greetingsettings/css/<theme_folder>/greetingsettings.css") + "\">", false);
            _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);
        }
コード例 #2
0
        public object SaveGreetingSettings(string logoVP, string header)
        {
            try
            {
                SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

                _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);

                if (!String.IsNullOrEmpty(logoVP))
                {
                    var fileName = Path.GetFileName(logoVP);
                    var data = UserPhotoManager.GetTempPhotoData(fileName);
                    _tenantInfoSettings.SetCompanyLogo(fileName, data);

                    try
                    {
                        UserPhotoManager.RemoveTempPhoto(fileName);
                    }
                    catch
                    {
                    }
                }

                var currentTenant = CoreContext.TenantManager.GetCurrentTenant();
                currentTenant.Name = header;
                CoreContext.TenantManager.SaveTenant(currentTenant);

                SettingsManager.Instance.SaveSettings<TenantInfoSettings>(_tenantInfoSettings, TenantProvider.CurrentTenantID);

                return new {Status = 1, Message = Resources.Resource.SuccessfullySaveGreetingSettingsMessage};

            }
            catch (Exception e)
            {
                return new {Status = 0, Message = e.Message.HtmlEncode()};
            }
        }
コード例 #3
0
ファイル: confirm.aspx.cs プロジェクト: ridhouan/teamlab.v6.5
        protected void Page_Load(object sender, EventArgs e)
        {
            ((IStudioMaster)this.Master).DisabledSidePanel = true;
            UserInfo _user = null;

            this.Page.Title = HeaderStringHelper.GetPageTitle(Resources.Resource.AccountControlPageTitle, null, null);

            var type = typeof(ConfirmType).TryParseEnum<ConfirmType>(Request["type"] ?? "", ConfirmType.EmpInvite);
            ((StudioTemplate)this.Master).TopNavigationPanel.DisableProductNavigation = true;
            ((StudioTemplate)this.Master).TopNavigationPanel.DisableUserInfo = true;
            ((StudioTemplate)this.Master).TopNavigationPanel.DisableSearch = true;

            if (type == ConfirmType.Activation || type == ConfirmType.EmpInvite)
                ((StudioTemplate)this.Master).TopNavigationPanel.CustomTitle = Resources.Resource.JoinTitle;

            _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);

            var email = Request["email"] ?? "";
            var key = Request["key"] ?? "";
            var fap = Request["fap"] ?? "";


            var validInterval = SetupInfo.ValidEamilKeyInterval;
            var checkKeyResult = EmailValidationKeyProvider.ValidationResult.Invalid;

            var tenant = CoreContext.TenantManager.GetCurrentTenant();
            if (tenant.Status != TenantStatus.Active && type != ConfirmType.PortalContinue)
            {
                Response.Redirect(SetupInfo.NoTenantRedirectURL, true);
            }

            if (type == ConfirmType.DnsChange)
            {
                var dnsChangeKey = string.Join(string.Empty, new string[] { email.ToLower(), type.ToString().ToLower(), Request["dns"], Request["alias"] });
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(dnsChangeKey, key, validInterval);
            }
            else if (type == ConfirmType.PortalContinue)
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower(), key);
            }
            else if ((type == ConfirmType.EmpInvite || type == ConfirmType.Activation) && !String.IsNullOrEmpty(fap) && String.Equals(fap, "1"))
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower() + "allrights", key, validInterval);
            }
            else if (type == ConfirmType.PasswordChange)
            {
                //Check activation signature
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower(), key, validInterval);
            }
            else if (type == ConfirmType.PortalOwnerChange && !String.IsNullOrEmpty(Request["uid"]))
            {
                Guid uid = Guid.Empty;
                try
                {
                    uid = new Guid(Request["uid"]);
                }
                catch { }
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower() + uid.ToString(), key, validInterval);
            }
            else if (type == ConfirmType.ProfileRemove && !(String.IsNullOrEmpty(Request["email"]) || String.IsNullOrEmpty(Request["key"])))
            {
                _user = CoreContext.UserManager.GetUserByEmail(email);

                if (_user.ID.Equals(ASC.Core.Users.Constants.LostUser.ID)) return;

                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower(), key, validInterval);
            }
            else if (type == ConfirmType.EmpInvite && String.IsNullOrEmpty(email))
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower(), key, TimeSpan.FromDays(3));
            }
            else if (type == ConfirmType.PhoneActivation || type == ConfirmType.PhoneAuth)
            {
                UserTransferData obj;
                if (Context.Session["UserTransferData"] != null)
                {
                    obj = (Context.Session["UserTransferData"] as UserTransferData);
                    key = obj.ValidationKey;
                }
                else
                {
                    obj = new UserTransferData { Login = email };
                }
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey((obj.HashId ?? obj.Login) + type.ToString().ToLower(), key, TimeSpan.FromDays(3));
            }
            else if (type == ConfirmType.PhoneChange)
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower(), key, TimeSpan.FromDays(3));
            }
            else
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString().ToLower(), key, validInterval);
            }

            if (((!email.TestEmailRegex() && !(type == ConfirmType.PhoneActivation || type == ConfirmType.PhoneAuth)) || checkKeyResult != EmailValidationKeyProvider.ValidationResult.Ok) && type != ConfirmType.LinkInvite)
            {
                ShowError(Resources.Resource.ErrorConfirmURLError);
                return;
            }

            if (!email.TestEmailRegex() && !(type == ConfirmType.LinkInvite || type == ConfirmType.PhoneActivation || type == ConfirmType.PhoneAuth))
            {
                ShowError(Resources.Resource.ErrorNotCorrectEmail);
                return;
            }

            if (checkKeyResult == EmailValidationKeyProvider.ValidationResult.Invalid)
            {
                //If check failed
                ShowError(Resources.Resource.ErrorInvalidActivationLink);
                return;
            }
            if (checkKeyResult == EmailValidationKeyProvider.ValidationResult.Expired)
            {
                //If link expired
                ShowError(Resources.Resource.ErrorExpiredActivationLink);
                return;
            }

            switch (type)
            {
                //Invite
                case ConfirmType.EmpInvite:
                case ConfirmType.LinkInvite:
                case ConfirmType.Activation:
                    _confirmHolder2.Controls.Add(LoadControl(ConfirmInviteActivation.Location));
                    _contentWithControl.Visible = false;
                    break;

                case ConfirmType.EmailChange:
                case ConfirmType.PasswordChange:
                    _confirmHolder.Controls.Add(LoadControl(ConfirmActivation.Location));
                    break;

                case ConfirmType.EmailActivation:
                    ProcessEmailActivation(email);
                    break;

                case ConfirmType.PortalRemove:
                case ConfirmType.PortalSuspend:
                case ConfirmType.PortalContinue:
                case ConfirmType.DnsChange:
                    _confirmHolder.Controls.Add(LoadControl(ConfirmPortalActivity.Location));
                    break;

                case ConfirmType.PortalOwnerChange:
                    _confirmHolder.Controls.Add(LoadControl(ConfirmPortalOwner.Location));
                    break;

                case ConfirmType.ProfileRemove:
                    var control = (ProfileOperation)LoadControl(ProfileOperation.Location);
                    control.Key = key;
                    control.Email = email;
                    control.User = _user;
                    _confirmHolder.Controls.Add(control);
                    break;

                case ConfirmType.PhoneActivation:
                case ConfirmType.PhoneChange:
                    var authControl = (ConfirmMobileActivation)LoadControl(ConfirmMobileActivation.Location);
                    authControl.Activate = true;
                    _confirmHolder.Controls.Add(authControl);
                    break;

                case ConfirmType.PhoneAuth:
                    var authControl1 = (ConfirmMobileActivation)LoadControl(ConfirmMobileActivation.Location);
                    authControl1.Activate = false;
                    _confirmHolder.Controls.Add(authControl1);
                    break;
            }
        }
コード例 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.RegisterBodyScripts(ResolveUrl("~/usercontrols/management/confirminviteactivation/js/confirm_invite_activation.js"));

            Page.RegisterStyleControl(VirtualPathUtility.ToAbsolute("~/usercontrols/management/confirminviteactivation/css/confirm_invite_activation.less"));

            _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);

            var uid = Guid.Empty;
            try
            {
                uid = new Guid(Request["uid"]);
            }
            catch
            {
            }

            var email = GetEmailAddress();

            if (_type != ConfirmType.Activation && AccountLinkControl.IsNotEmpty)
            {
                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(ASC.Core.Users.Constants.LostUser.ID) || usr.ID.Equals(ASC.Core.Configuration.Constants.Guest.ID))
                    usr = CoreContext.UserManager.GetUsers(CoreContext.TenantManager.GetCurrentTenant().OwnerId);

                _userAvatar = usr.GetMediumPhotoURL();
                _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(ASC.Core.Users.Constants.LostUser.ID))
                {
                    ShowError(CustomNamingPeople.Substitute<Resource>("ErrorEmailAlreadyExists"));
                    return;
                }
            }

            else if (_type == ConfirmType.Activation)
            {
                if (user.IsActive)
                {
                    ShowError(Resource.ErrorConfirmURLError);
                    return;
                }

                if (user.ID.Equals(ASC.Core.Users.Constants.LostUser.ID) || user.Status == EmployeeStatus.Terminated)
                {
                    ShowError(string.Format(Resource.ErrorUserNotFoundByEmail, email));
                    return;
                }
            }

            if (!IsPostBack)
                return;

            var firstName = GetFirstName();
            var lastName = GetLastName();
            var pwd = (Request["pwdInput"] ?? "").Trim();
            var repwd = (Request["repwdInput"] ?? "").Trim();
            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;
                }

                var checkPassResult = CheckPassword(pwd, repwd);
                if (!String.IsNullOrEmpty(checkPassResult))
                {
                    _errorMessage = checkPassResult;
                    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, pwd, _employeeType, fromInviteLink);
                        userID = newUser.ID;
                    }

                    if (Request["__EVENTTARGET"] == "thirdPartyLogin")
                    {
                        if (!String.IsNullOrEmpty(CheckPassword(pwd, repwd)))
                            pwd = UserManagerWrapper.GeneratePassword();
                        var valueRequest = Request["__EVENTARGUMENT"];
                        thirdPartyProfile = new LoginProfile(valueRequest);
                        newUser = CreateNewUser(GetFirstName(thirdPartyProfile), GetLastName(thirdPartyProfile), GetEmailAddress(thirdPartyProfile), pwd, _employeeType, 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)
                {
                    user.ActivationStatus = EmployeeActivationStatus.Activated;
                    user.FirstName = firstName;
                    user.LastName = lastName;
                    CoreContext.UserManager.SaveUserInfo(user);
                    SecurityContext.SetUserPassword(user.ID, pwd);

                    userID = user.ID;

                    //notify
                    if (user.IsVisitor()) { 
                        StudioNotifyService.Instance.GuestInfoAddedAfterInvite(user, pwd);
                    }
                    else
                    {
                        StudioNotifyService.Instance.UserInfoAddedAfterInvite(user, pwd);
                    }
                }
            }
            catch (Exception exception)
            {
                _errorMessage = HttpUtility.HtmlEncode(exception.Message);
                return;
            }
            finally
            {
                SecurityContext.Logout();
            }

            try
            {
                var cookiesKey = SecurityContext.AuthenticateMe(userID.ToString(), pwd);
                CookiesManager.SetCookies(CookiesType.UserID, userID.ToString());
                CookiesManager.SetCookies(CookiesType.AuthKey, cookiesKey);
                StudioNotifyService.Instance.UserHasJoin();
            }
            catch (Exception exception)
            {
                (Page as confirm).ErrorMessage = HttpUtility.HtmlEncode(exception.Message);
                return;
            }

            user = CoreContext.UserManager.GetUsers(userID);

            UserHelpTourHelper.IsNewUser = true;
            Response.Redirect(user.IsVisitor() ? "~/" : "~/welcome.aspx");
        }
コード例 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(this.GetType());
            Page.RegisterBodyScripts(VirtualPathUtility.ToAbsolute("~/js/uploader/ajaxupload.js"));
            Page.RegisterBodyScripts(ResolveUrl("~/usercontrols/management/greetingsettings/js/greetingsettingscontent.js"));

            Page.RegisterStyleControl(VirtualPathUtility.ToAbsolute("~/usercontrols/management/greetingsettings/css/greetingsettings.less"));

            _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);

            RegisterScript();
        }
コード例 #6
0
        public object RestoreGreetingSettings()
        {
            try
            {
                SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings);

                _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);
                _tenantInfoSettings.RestoreDefault();
                SettingsManager.Instance.SaveSettings<TenantInfoSettings>(_tenantInfoSettings, TenantProvider.CurrentTenantID);

                AdminLog.PostAction("Settings: restored previous greeting settings");

                return new 
                           {
                               Status = 1,
                               Message = Resources.Resource.SuccessfullySaveGreetingSettingsMessage,
                               LogoPath = _tenantInfoSettings.GetAbsoluteCompanyLogoPath(),
                               CompanyName = CoreContext.TenantManager.GetCurrentTenant().Name,
                           };
            }
            catch (Exception e)
            {
                return new {Status = 0, Message = e.Message.HtmlEncode()};
            }
        }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = HeaderStringHelper.GetPageTitle(Resource.AccountControlPageTitle);

            Master.DisabledSidePanel = true;
            Master.TopStudioPanel.DisableProductNavigation = true;
            Master.TopStudioPanel.DisableUserInfo = true;
            Master.TopStudioPanel.DisableSearch = true;
            Master.TopStudioPanel.DisableSettings = true;
            Master.TopStudioPanel.DisableVideo = true;
            Master.TopStudioPanel.DisableTariff = true;

            _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);

            _email = Request["email"] ?? "";
            _type = typeof(ConfirmType).TryParseEnum(Request["type"] ?? "", ConfirmType.EmpInvite);

            var tenant = CoreContext.TenantManager.GetCurrentTenant();
            if (tenant.Status != TenantStatus.Active && _type != ConfirmType.PortalContinue)
            {
                Response.Redirect(SetupInfo.NoTenantRedirectURL, true);
            }

            if (_type == ConfirmType.PhoneActivation && SecurityContext.IsAuthenticated)
            {
                Master.TopStudioPanel.DisableUserInfo = false;
            }

            if (!CheckValidationKey())
            {
                return;
            }

            LoadControls();
        }
コード例 #8
0
 protected override void OnInit(EventArgs e)
 {
     Page.ClientScript.RegisterClientScriptInclude(typeof(string), "ajaxupload_script", WebPath.GetPath("js/ajaxupload.3.5.js"));
     TenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);
 }
コード例 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = HeaderStringHelper.GetPageTitle(Resource.AccountControlPageTitle);

            Master.DisabledSidePanel = true;
            Master.TopStudioPanel.DisableProductNavigation = true;
            Master.TopStudioPanel.DisableUserInfo = true;
            Master.TopStudioPanel.DisableSearch = true;
            Master.TopStudioPanel.DisableSettings = true;
            Master.TopStudioPanel.DisableVideo = true;

            _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);

            var email = Request["email"] ?? "";
            var key = Request["key"] ?? "";
            var emplType = Request["emplType"] ?? "";
            var type = typeof(ConfirmType).TryParseEnum(Request["type"] ?? "", ConfirmType.EmpInvite);

            var validInterval = SetupInfo.ValidEamilKeyInterval;
            var authInterval = TimeSpan.FromHours(1);
            EmailValidationKeyProvider.ValidationResult checkKeyResult;

            UserInfo user = null;
            var tenant = CoreContext.TenantManager.GetCurrentTenant();
            if (tenant.Status != TenantStatus.Active && type != ConfirmType.PortalContinue)
            {
                Response.Redirect(SetupInfo.NoTenantRedirectURL, true);
            }

            if (type == ConfirmType.DnsChange)
            {
                var dnsChangeKey = string.Join(string.Empty, new[] { email, type.ToString(), Request["dns"], Request["alias"] });
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(dnsChangeKey, key, validInterval);
            }
            else if (type == ConfirmType.PortalContinue)
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString(), key);
            }
            else if ((type == ConfirmType.EmpInvite || type == ConfirmType.Activation) && !String.IsNullOrEmpty(emplType))
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString() + emplType, key, validInterval);
            }
            else if (type == ConfirmType.PasswordChange)
            {
                //Check activation signature
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString(), key, validInterval);
            }
            else if (type == ConfirmType.PortalOwnerChange && !String.IsNullOrEmpty(Request["uid"]))
            {
                var uid = Guid.Empty;
                try
                {
                    uid = new Guid(Request["uid"]);
                }
                catch
                {
                }
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString() + uid.ToString(), key, validInterval);
            }
            else if (type == ConfirmType.ProfileRemove && !(String.IsNullOrEmpty(Request["email"]) || String.IsNullOrEmpty(Request["key"])))
            {
                user = CoreContext.UserManager.GetUserByEmail(email);

                if (user.ID.Equals(Constants.LostUser.ID))
                {
                    ShowError(Resource.ErrorUserNotFound);
                    return;
                }

                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString(), key, validInterval);
            }
            else if (type == ConfirmType.EmpInvite && String.IsNullOrEmpty(email))
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString(), key, TimeSpan.FromDays(3));
            }
            else if (type == ConfirmType.PhoneAuth || type == ConfirmType.PhoneActivation)
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString(), key, authInterval);
            }
            else if (type == ConfirmType.Auth)
            {
                if (SecurityContext.IsAuthenticated)
                    Response.Redirect(CommonLinkUtility.GetDefault());

                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString(), key, authInterval);
                if (checkKeyResult == EmailValidationKeyProvider.ValidationResult.Ok)
                {
                    user = CoreContext.UserManager.GetUserByEmail(email);
                    var authCookie = SecurityContext.AuthenticateMe(user.ID);
                    CookiesManager.SetCookies(CookiesType.AuthKey, authCookie);
                    Response.Redirect(CommonLinkUtility.GetDefault());
                    return;
                }
            }else
            {
                checkKeyResult = EmailValidationKeyProvider.ValidateEmailKey(email + type.ToString() + emplType, key, validInterval);
            }

            if (type == ConfirmType.PhoneActivation && SecurityContext.IsAuthenticated)
            {
                Master.TopStudioPanel.DisableUserInfo = false;
            }

            if ((!email.TestEmailRegex() || checkKeyResult != EmailValidationKeyProvider.ValidationResult.Ok) && type != ConfirmType.LinkInvite)
            {
                ShowError(Resource.ErrorConfirmURLError);
                return;
            }

            if (!email.TestEmailRegex() && type != ConfirmType.LinkInvite)
            {
                ShowError(Resource.ErrorNotCorrectEmail);
                return;
            }

            if (checkKeyResult == EmailValidationKeyProvider.ValidationResult.Invalid)
            {
                //If check failed
                ShowError(Resource.ErrorInvalidActivationLink);
                return;
            }
            if (checkKeyResult == EmailValidationKeyProvider.ValidationResult.Expired)
            {
                //If link expired
                ShowError(Resource.ErrorExpiredActivationLink);
                return;
            }

            switch (type)
            {
                    //Invite
                case ConfirmType.EmpInvite:
                case ConfirmType.LinkInvite:
                case ConfirmType.Activation:
                    _confirmHolder2.Controls.Add(LoadControl(ConfirmInviteActivation.Location));
                    _contentWithControl.Visible = false;
                    break;

                case ConfirmType.EmailChange:
                case ConfirmType.PasswordChange:
                    _confirmHolder.Controls.Add(LoadControl(ConfirmActivation.Location));
                    break;

                case ConfirmType.EmailActivation:
                    ProcessEmailActivation(email);
                    break;

                case ConfirmType.PortalRemove:
                case ConfirmType.PortalSuspend:
                case ConfirmType.PortalContinue:
                case ConfirmType.DnsChange:
                    _confirmHolder.Controls.Add(LoadControl(ConfirmPortalActivity.Location));
                    break;

                case ConfirmType.PortalOwnerChange:
                    _confirmHolder.Controls.Add(LoadControl(ConfirmPortalOwner.Location));
                    break;

                case ConfirmType.ProfileRemove:
                    var control = (ProfileOperation)LoadControl(ProfileOperation.Location);
                    control.Key = key;
                    control.Email = email;
                    control.User = user;
                    _confirmHolder.Controls.Add(control);
                    break;

                case ConfirmType.PhoneActivation:
                case ConfirmType.PhoneAuth:
                    var confirmMobileActivation = (ConfirmMobileActivation)LoadControl(ConfirmMobileActivation.Location);
                    confirmMobileActivation.Activation = type == ConfirmType.PhoneActivation;
                    confirmMobileActivation.User = CoreContext.UserManager.GetUserByEmail(email);
                    _confirmHolder.Controls.Add(confirmMobileActivation);
                    break;
            }
        }
コード例 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm_invite_activation_style", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + WebSkin.GetUserSkin().GetAbsoluteWebPath("usercontrols/management/confirminviteactivation/css/<theme_folder>/confirm_invite_activation.css") + "\">", false);
            Page.ClientScript.RegisterClientScriptInclude(typeof(string), "confirm_invite_activation_script", WebPath.GetPath("usercontrols/management/confirminviteactivation/js/confirm_invite_activation.js"));

            _tenantInfoSettings = SettingsManager.Instance.LoadSettings<TenantInfoSettings>(TenantProvider.CurrentTenantID);

            Guid uid = Guid.Empty;
            try
            {
                uid = new Guid(Request["uid"]);
            }
            catch { }

            var type = typeof(ConfirmType).TryParseEnum(Request["type"] ?? "", ConfirmType.EmpInvite);

            var email = GetEmailAddress();
            var key = Request["key"] ?? "";
            var fap = Request["fap"] ?? "";

            //if (!string.IsNullOrEmpty(_email))
            //{
            //var thrd = LoadControl(AccountLinkControl.Location) as AccountLinkControl;
            //thrd.InviteView = true;
            //thrd.ClientCallback = "loginJoinCallback";
            //thrdParty.Controls.Add(thrd);
            //}
            Page.Title = HeaderStringHelper.GetPageTitle(Resources.Resource.Authorization, null, null);

            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(ASC.Core.Users.Constants.LostUser.ID) || usr.ID.Equals(ASC.Core.Configuration.Constants.Guest.ID))
                    usr = CoreContext.UserManager.GetUsers(CoreContext.TenantManager.GetCurrentTenant().OwnerId);

                _userAvatar = usr.GetMediumPhotoURL();
                _userName = usr.DisplayUserName(true);
                _userPost = (usr.Title ?? "").HtmlEncode();
            }
            finally
            {
                SecurityContext.Logout();
            }

            if (type == ConfirmType.LinkInvite || type == ConfirmType.EmpInvite)
            {
                if (!user.ID.Equals(ASC.Core.Users.Constants.LostUser.ID))
                {
                    ShowError(CustomNamingPeople.Substitute<Resources.Resource>("ErrorEmailAlreadyExists"));
                    return;
                }
            }

            else if (type == ConfirmType.Activation)
            {
                if (user.IsActive)
                {
                    ShowError(Resources.Resource.ErrorConfirmURLError);
                    return;
                }

                if (user.ID.Equals(ASC.Core.Users.Constants.LostUser.ID))
                {
                    ShowError(string.Format(Resources.Resource.ErrorUserNotFoundByEmail, email));
                    return;
                }
            }

            if (!IsPostBack)
                return;

            var firstName = GetFirstName();
            var lastName = GetLastName();
            var pwd = (Request["pwdInput"] ?? "").Trim();
            var repwd = (Request["repwdInput"] ?? "").Trim();
            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(Resources.Resource.ErrorNotCorrectEmail));
                    return;
                }
            }

            if (Request["__EVENTTARGET"] == "confirmInvite")
            {
                if (String.IsNullOrEmpty(email))
                {
                    _errorMessage = Resources.Resource.ErrorEmptyUserEmail;
                    return;
                }

                if (!email.TestEmailRegex())
                {
                    _errorMessage = Resources.Resource.ErrorNotCorrectEmail;
                    return;
                }

                if (String.IsNullOrEmpty(firstName))
                {
                    _errorMessage = Resources.Resource.ErrorEmptyUserFirstName;
                    return;
                }

                if (String.IsNullOrEmpty(lastName))
                {
                    _errorMessage = Resources.Resource.ErrorEmptyUserLastName;
                    return;
                }

                var checkPassResult = CheckPassword(pwd, repwd);
                if (!String.IsNullOrEmpty(checkPassResult))
                {
                    _errorMessage = checkPassResult;
                    return;
                }
            }
            var userID = Guid.Empty;
            try
            {
                SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem);
                if (type == ConfirmType.EmpInvite || type == ConfirmType.LinkInvite)
                {
                    UserInfo newUser;
                    if (Request["__EVENTTARGET"] == "confirmInvite")
                    {
                        newUser = CreateNewUser(firstName, lastName, email, pwd);
                        userID = newUser.ID;
                    }

                    if (Request["__EVENTTARGET"] == "thirdPartyLogin")
                    {
                        if (!String.IsNullOrEmpty(CheckPassword(pwd, repwd)))
                            pwd = UserManagerWrapper.GeneratePassword();
                        var valueRequest = Request["__EVENTARGUMENT"];
                        thirdPartyProfile = new LoginProfile(valueRequest);
                        newUser = CreateNewUser(GetFirstName(thirdPartyProfile), GetLastName(thirdPartyProfile), GetEmailAddress(thirdPartyProfile), pwd);
                        userID = newUser.ID;

                        var linker = new AccountLinker(WebConfigurationManager.ConnectionStrings["webstudio"]);
                        linker.AddLink(userID.ToString(), thirdPartyProfile);
                    }

                    #region Department

                    try
                    {
                        var deptID = new Guid((Request["deptID"] ?? "").Trim());
                        CoreContext.UserManager.AddUserIntoGroup(userID, deptID);
                    }
                    catch
                    {
                    }

                    #endregion
                }
                else if (type == ConfirmType.Activation)
                {
                    user.ActivationStatus = EmployeeActivationStatus.Activated;
                    user.FirstName = firstName;
                    user.LastName = lastName;
                    CoreContext.UserManager.SaveUserInfo(user);
                    SecurityContext.SetUserPassword(user.ID, pwd);

                    userID = user.ID;

                    //notify
                    StudioNotifyService.Instance.UserInfoAddedAfterInvite(user, pwd);
                }

                if (String.Equals(fap, "1"))
                    CoreContext.UserManager.AddUserIntoGroup(userID, ASC.Core.Users.Constants.GroupAdmin.ID);

            }
            catch (Exception exception)
            {
                (Page as confirm).ErrorMessage = HttpUtility.HtmlEncode(exception.Message);
                return;
            }
            finally
            {
                SecurityContext.Logout();
            }

            try
            {
                var cookiesKey = SecurityContext.AuthenticateMe(userID.ToString(), pwd);
                CookiesManager.SetCookies(CookiesType.UserID, userID.ToString());
                CookiesManager.SetCookies(CookiesType.AuthKey, cookiesKey);
                StudioNotifyService.Instance.UserHasJoin();
            }
            catch (Exception exception)
            {
                (Page as confirm).ErrorMessage = HttpUtility.HtmlEncode(exception.Message);
                return;
            }

            UserOnlineManager.Instance.RegistryOnlineUser(SecurityContext.CurrentAccount.ID);
            WebItemManager.Instance.ItemGlobalHandlers.Login(SecurityContext.CurrentAccount.ID);
            var smsAuthSettings = SettingsManager.Instance.LoadSettings<StudioSmsNotificationSettings>(TenantProvider.CurrentTenantID);
            if (smsAuthSettings.Enable)
            {
                var uData = new UserTransferData();
                var usr = CoreContext.UserManager.GetUsers(userID);
                uData.Login = usr.Email;
                uData.UserId = userID;
                Session["UserTransferData"] = uData;
            }

            Response.Redirect("~/");
        }