コード例 #1
0
        void Handle(Input.RestoreClick action)
        {
            this.DisableRestoreClick = 1;
            this.MessageCss          = "alert alert-danger";

            if (string.IsNullOrEmpty(this.Username))
            {
                this.Message = "Username is required!";
                return;
            }

            SystemUser user = SystemUser.GetSystemUser(this.Username);

            if (user == null)
            {
                this.Message = "Invalid username!";
                return;
            }

            Person       person = user.WhoIs as Person;
            EmailAddress email  = Utils.GetUserEmailAddress(user);

            if (person == null || email == null || string.IsNullOrEmpty(email.EMail))
            {
                this.Message = "Unable to restore password, no e-mail address found!";
                return;
            }

            string password = Utils.RandomString(5);
            string hash     = SystemUser.GeneratePasswordHash(user.Username, password, user.PasswordSalt);

            try
            {
                this.SendNewPassword(person.FullName, user.Username, password, email.Name);
                this.Message    = "Your new password has been sent to your email address.";
                this.MessageCss = "alert alert-success";
                Db.Transact(() => { user.Password = hash; });
            }
            catch (Exception ex)
            {
                this.Message    = "Mail server is currently unavailable.";
                this.MessageCss = "alert alert-danger";
                Starcounter.Logging.LogSource log = new Starcounter.Logging.LogSource(Application.Current.Name);
                log.LogException(ex);
            }
        }