/// <summary> /// Handles the Click event of the btnChange control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnChange_Click( object sender, EventArgs e ) { var userLoginService = new UserLoginService(); var userLogin = userLoginService.GetByUserName( tbUserName.Text ); if ( userLogin != null ) { if ( UserLoginService.IsPasswordValid( tbPassword.Text ) ) { if ( userLoginService.ChangePassword( userLogin, tbOldPassword.Text, tbPassword.Text ) ) { userLoginService.Save( userLogin, CurrentPersonId ); lSuccess.Text = GetAttributeValue( "SuccessCaption" ); pnlEntry.Visible = false; pnlSuccess.Visible = true; } else DisplayError( "InvalidPasswordCaption" ); } else { InvalidPassword(); } } else DisplayError( "InvalidUserNameCaption" ); }
/// <summary> /// Handles the SaveClick event of the modalDetails control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void mdDetails_SaveClick( object sender, EventArgs e ) { if ( _canEdit ) { UserLogin userLogin = null; var service = new UserLoginService(); int userLoginId = int.Parse( hfIdValue.Value ); if ( userLoginId != 0 ) { userLogin = service.Get( userLoginId ); } if ( userLogin == null ) { userLogin = new UserLogin(); service.Add( userLogin, CurrentPersonId ); } userLogin.UserName = tbUserName.Text; userLogin.IsConfirmed = cbIsConfirmed.Checked; userLogin.IsLockedOut = cbIsLockedOut.Checked; var entityType = EntityTypeCache.Read( compProvider.SelectedValue.AsGuid() ); if ( entityType != null ) { userLogin.EntityTypeId = entityType.Id; if ( !string.IsNullOrWhiteSpace( tbPassword.Text ) ) { var component = AuthenticationContainer.GetComponent( entityType.Name ); if ( component != null && component.ServiceType == AuthenticationServiceType.Internal ) { if ( tbPassword.Text == tbPasswordConfirm.Text ) { if ( UserLoginService.IsPasswordValid( tbPassword.Text ) ) { userLogin.Password = component.EncodePassword( userLogin, tbPassword.Text ); userLogin.LastPasswordChangedDateTime = DateTime.Now; } else { nbErrorMessage.Title = "Invalid Password"; nbErrorMessage.Text = UserLoginService.FriendlyPasswordRules(); nbErrorMessage.Visible = true; return; } } else { nbErrorMessage.Title = "Invalid Password"; nbErrorMessage.Text = "Password and Confirmation do not match."; nbErrorMessage.Visible = true; return; } } } } if ( !userLogin.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { service.Save( userLogin, CurrentPersonId ); } ); mdDetails.Hide(); BindGrid(); } }
/// <summary> /// Handles the Delete event of the gUserLogins control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gUserLogins_Delete( object sender, RowEventArgs e ) { if ( _canEdit ) { var service = new UserLoginService(); var userLogin = service.Get( (int)e.RowKeyValue ); if ( userLogin != null ) { string errorMessage; if ( !service.CanDelete( userLogin, out errorMessage ) ) { maGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } service.Delete( userLogin, CurrentPersonId ); service.Save( userLogin, CurrentPersonId ); } } BindGrid(); }
/// <summary> /// Job that executes routine Rock cleanup tasks /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; // delete accounts that have not been confirmed in X hours int userExpireHours = Int32.Parse( dataMap.GetString( "HoursKeepUnconfirmedAccounts" ) ); DateTime userAccountExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1,0,0 ) ); var userLoginService = new UserLoginService(); foreach (var user in userLoginService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDateTime < userAccountExpireDate).ToList() ) { userLoginService.Delete( user, null ); userLoginService.Save( user, null ); } // purge exception log int exceptionExpireDays = Int32.Parse( dataMap.GetString( "DaysKeepExceptions" ) ); DateTime exceptionExpireDate = DateTime.Now.Add( new TimeSpan( exceptionExpireDays * -1, 0, 0, 0 ) ); ExceptionLogService exceptionLogService = new ExceptionLogService(); foreach ( var exception in exceptionLogService.Queryable().Where( e => e.ExceptionDateTime < exceptionExpireDate ).ToList() ) { exceptionLogService.Delete( exception, null ); exceptionLogService.Save( exception, null ); } // purge audit log int auditExpireDays = Int32.Parse( dataMap.GetString( "AuditLogExpirationDays" ) ); DateTime auditExpireDate = DateTime.Now.Add( new TimeSpan( auditExpireDays * -1, 0, 0, 0 ) ); AuditService auditService = new AuditService(); foreach( var audit in auditService.Queryable().Where( a => a.DateTime < auditExpireDate ).ToList() ) { auditService.Delete( audit, null ); auditService.Save( audit, null ); } // clean the cached file directory //get the attributes string cacheDirectoryPath = dataMap.GetString( "BaseCacheDirectory" ); int cacheExpirationDays = int.Parse( dataMap.GetString( "DaysKeepCachedFiles" ) ); DateTime cacheExpirationDate = DateTime.Now.Add( new TimeSpan( cacheExpirationDays * -1, 0, 0, 0 ) ); //if job is being run by the IIS scheduler and path is not null if ( context.Scheduler.SchedulerName == "RockSchedulerIIS" && !String.IsNullOrEmpty( cacheDirectoryPath ) ) { //get the physical path of the cache directory cacheDirectoryPath = System.Web.Hosting.HostingEnvironment.MapPath( cacheDirectoryPath ); } //if directory is not blank and cache expiration date not in the future if ( !String.IsNullOrEmpty( cacheDirectoryPath ) && cacheExpirationDate <= DateTime.Now ) { //Clean cache directory CleanCacheDirectory( cacheDirectoryPath, cacheExpirationDate ); } // clean out any temporary binary files BinaryFileService binaryFileService = new BinaryFileService(); foreach( var binaryFile in binaryFileService.Queryable().Where( bf => bf.IsTemporary == true ).ToList() ) { if ( binaryFile.LastModifiedDateTime < DateTime.Now.AddDays(-1) ) { binaryFileService.Delete( binaryFile, null ); binaryFileService.Save( binaryFile, null ); } } }