Exemple #1
0
        protected void SignUpClick(object sender, EventArgs e)
        {
            FailureHolder.Visible = false;
            SuccessHolder.Visible = false;

            Validate();
            if (!IsValid)
            {
                RenderError("The provided data is not valid.", false);

                return;
            }

            var email  = Email.Text.Trim();
            var name   = UserName.Text.Trim();
            var secret = Secret.Text.Trim();

            try
            {
                DoSignUp(name, email, secret);
            }
            catch (Exception ex)
            {
                var error = "Failed to create user account, " +
                            $"UserName: \"{name}\", " +
                            $"Email: \"{email}\"";

                FridayLog.Error(SignUpRules.FeatureName, error, ex);

                RenderError($"Failed to create user account, contact your administrator with this reference: {Settings.InstanceName}-{DateTime.Now:yyMMddhhmmss}", true);
            }
        }
Exemple #2
0
        private void DoWork(object args)
        {
            try
            {
                var loginFilePath = HostingEnvironment.MapPath("/sitecore/login/default.aspx") ?? throw new ArgumentNullException();
                if (!File.Exists(loginFilePath))
                {
                    return;
                }

                var lines          = File.ReadAllLines(loginFilePath);
                var signupFilePath = HostingEnvironment.MapPath("/sitecore/signup/default.aspx");
                if (SignUpRules.Enabled)
                {
                    InjectLink(loginFilePath, lines);
                    DeployPage(signupFilePath);
                }
                else
                {
                    RemoveInjectedLink(loginFilePath, lines);
                    RemovePage(signupFilePath);
                }
            }
            catch (Exception ex)
            {
                FridayLog.Error(SignUpRules.FeatureName, "Failed to modify login page or bootstrap /sitecore/signup page", ex);
            }
        }
        internal void Process(HttpRequestArgs args)
        {
            if (Done)
            {
                return;
            }

            lock (SyncRoot)
            {
                if (Done)
                {
                    return;
                }

                new Thread(() =>
                {
                    try
                    {
                        Event.RaiseEvent(SitecoreStarted.EventName, new EventArgs());
                    }
                    catch (Exception ex)
                    {
                        FridayLog.Error(SitecoreStarted.FeatureName, $"Failed to process {SitecoreStarted.EventName} event", ex);
                    }
                }).Start();

                Done = true;
            }
        }
        internal void Process(HttpRequestArgs args)
        {
            if (Done)
            {
                return;
            }

            lock (SyncRoot)
            {
                if (Done)
                {
                    return;
                }

                Timer.Stop();
                FridayLog.Info(SitecoreStarted.FeatureName, $"Sitecore is up and serving requests. Elapsed: \"{Timer.Elapsed}\", First Request: \"{HttpContext.Current.Request.RawUrl}\"");

                new Thread(
                    () =>
                {
                    try
                    {
                        Event.RaiseEvent(SitecoreStarted.EventName, new EventArgs());
                    }
                    catch (Exception ex)
                    {
                        FridayLog.Error(SitecoreStarted.FeatureName, $"Failed to process \"{SitecoreStarted.EventName}\" event", ex);
                    }
                }).Start();

                Done = true;
            }
        }
Exemple #5
0
        internal static User CreateUserAccount(this MembershipProvider provider, string username, string email, bool isAdministrator, IReadOnlyList <string> roles, string feature)
        {
            var password = Membership.GeneratePassword(provider.MinRequiredPasswordLength, provider.MinRequiredNonAlphanumericCharacters);
            var user     = User.Create(username, password);

            try
            {
                var profile = user.Profile;
                profile.IsAdministrator = isAdministrator;
                profile.Email           = email;
                profile.Save();

                // update roles
                foreach (var role in roles)
                {
                    user.Roles.Add(Role.FromName(role));
                }

                var message = "Create user account, " +
                              $"UserName: \"{username}\", " +
                              $"IsAdministrator: {isAdministrator}, " +
                              $"Roles: \"{string.Join(", ", roles)}\", " +
                              $"Email: \"{email}\"";

                FridayLog.Audit(feature, message);

                return(user);
            }
            catch
            {
                try
                {
                    provider.DeleteUser(username, true);
                }
                catch (Exception ex)
                {
                    var error = "Failed to delete incomplete user account, " +
                                $"UserName: \"{username}\"";

                    FridayLog.Error(feature, error, ex);
                }

                throw;
            }
        }
Exemple #6
0
        private void DoWork(object args)
        {
            foreach (var account in AccountResetRules.Accounts)
            {
                var username = account.Name;

                try
                {
                    var user = MembershipProvider.GetUser(username, false);
                    if (user == null)
                    {
                        MembershipProvider.CreateUserAccount(username, "", true, new string[0], AccountResetRules.FeatureName);
                        user = MembershipProvider.GetUser(username, false)
                               ?? throw new InvalidOperationException($"Failed to find user after creating, UserName: {username}");
                    }

                    // first change password and only then it is safe to unlock
                    var password = MembershipProvider.ResetPassword(username, null);
                    if (user.IsLockedOut)
                    {
                        user.UnlockUser();
                    }

                    var desiredPassword = account.Password;
                    if (!string.IsNullOrEmpty(desiredPassword))
                    {
                        try
                        {
                            user.ChangePassword(password, desiredPassword);

                            FridayLog.Info(AccountResetRules.FeatureName, $"User account was reset, UserName: {username}, Password: {desiredPassword}, IsLockedOut: false");
                        }
                        catch (Exception ex)
                        {
                            FridayLog.Error(AccountResetRules.FeatureName, $"User account was reset, but failed to change password to desired one, UserName: {username}, CurrentPassword: {password}, DesiredPassword: {desiredPassword} IsLockedOut: false", ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    FridayLog.Error(AccountResetRules.FeatureName, $"Failed to reset user account, UserName: {username}", ex);
                }
            }
        }
Exemple #7
0
        private void DoWork(object args)
        {
            foreach (var account in AccountResetRules.Accounts)
            {
                var username = account.Name;

                try
                {
                    var user = MembershipProvider.GetUser(username, false);
                    if (user == null)
                    {
                        MembershipProvider.CreateUserAccount(username, "", true, new string[0], AccountResetRules.FeatureName);

                        var error = "Failed to find user after creating, " +
                                    $"UserName: {username}";

                        user = MembershipProvider.GetUser(username, false) ?? throw new InvalidOperationException(error);
                    }

                    // first change password and only then it is safe to unlock
                    var password = MembershipProvider.ResetPassword(username, null);
                    if (user.IsLockedOut)
                    {
                        user.UnlockUser();
                    }

                    var desiredPassword = account.Password;
                    if (!string.IsNullOrEmpty(desiredPassword))
                    {
                        try
                        {
                            Assert.IsTrue(user.ChangePassword(password, desiredPassword), "Membership provider rejected password change request.");
                        }
                        catch (Exception ex)
                        {
                            var error = "User account was reset, but failed to change password to desired one, " +
                                        $"UserName: \"{username}\", " +
                                        $"CurrentPassword: \"{password}\", " +
                                        $"DesiredPassword: \"{desiredPassword}\", " +
                                        "IsLockedOut: false";

                            FridayLog.Error(AccountResetRules.FeatureName, error, ex);

                            continue;
                        }
                    }

                    var message = "User account was reset, " +
                                  $"UserName: \"{username}\", " +
                                  $"Password: \"{(account.WritePasswordToLog ? desiredPassword ?? password : "******")}\", " +
                                  "IsLockedOut: false";

                    FridayLog.Info(AccountResetRules.FeatureName, message);

                    var recepients = account.EmailPasswordToRecepients;
                    if (recepients.Any())
                    {
                        Helper.SendMailMessageAsync(user, desiredPassword ?? password, recepients);
                    }
                }
                catch (Exception ex)
                {
                    var error = "Failed to reset user account, " +
                                $"UserName: \"{username}\"";

                    FridayLog.Error(AccountResetRules.FeatureName, error, ex);
                }
            }
        }